From 00c489f0be2c0e13374a92db6b0b83a9e097e78a Mon Sep 17 00:00:00 2001 From: lzkk <956449176@qq.com> Date: Thu, 28 May 2026 13:41:16 +0800 Subject: [PATCH] =?UTF-8?q?perf(mir):=20=E6=B6=88=E9=99=A4=20Mul=20?= =?UTF-8?q?=E5=B9=82=E6=AC=A1=E6=96=B9=E4=BC=98=E5=8C=96=E4=BA=A7=E7=94=9F?= =?UTF-8?q?=E7=9A=84=E6=AD=BB=20MovImm=E2=80=94=E2=80=94=E5=85=88=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=90=8E=E5=8F=91=E5=B0=84=20rhs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit x*2^n 优化为 lsl 时,先检测常量是否幂次方再决定是否发射 rhs, 避免先发射 MovImm 再被 ShlRR 覆盖的死代码。 crypto 1458→1449,crc 303→297。 --- src/mir/Lowering.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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());