diff --git a/src/mir/Lowering.cpp b/src/mir/Lowering.cpp index 8589be99..4bcb494d 100644 --- a/src/mir/Lowering.cpp +++ b/src/mir/Lowering.cpp @@ -451,9 +451,8 @@ namespace mir int lhs = EmitIntValue(bin->GetLhs(), function, value_vregs, scalar_slots, array_slots, block); - int rhs = EmitIntValue(bin->GetRhs(), function, value_vregs, - scalar_slots, array_slots, block); + // Mul by constant power-of-2 → shift left,避免先发射 rhs 再发现不需要的死 MovImm if (opcode == Opcode::MulRR) { auto *rhs_const = dynamic_cast(bin->GetRhs()); @@ -463,11 +462,7 @@ namespace mir if (val > 0 && (val & (val - 1)) == 0) { int shift = 0; - while (val > 1) - { - val >>= 1; - ++shift; - } + while (val > 1) { val >>= 1; ++shift; } block.Append(Opcode::ShlRR, {Operand::VReg(dst, VRegClass::Int), Operand::VReg(lhs, VRegClass::Int), @@ -478,6 +473,9 @@ namespace mir } } + int rhs = EmitIntValue(bin->GetRhs(), function, value_vregs, + scalar_slots, array_slots, block); + if (opcode == Opcode::DivRR) { auto *rhs_const = dynamic_cast(bin->GetRhs());