perf(mir): 消除 Mul 幂次方优化产生的死 MovImm——先检测后发射 rhs

x*2^n 优化为 lsl 时,先检测常量是否幂次方再决定是否发射 rhs,
避免先发射 MovImm 再被 ShlRR 覆盖的死代码。
crypto 1458→1449,crc 303→297。
lzk
lzkk 2 days ago
parent 4179f40264
commit 00c489f0be

@ -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<const ir::ConstantInt *>(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<const ir::ConstantInt *>(bin->GetRhs());

Loading…
Cancel
Save