Skip to content

Commit

Permalink
ssa: fix regression
Browse files Browse the repository at this point in the history
  • Loading branch information
flyinghead committed Dec 8, 2024
1 parent fff03f6 commit 15617c1
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions core/hw/sh4/dyna/ssa.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,33 +285,37 @@ class SSAOptimizer
{
// Replace shld/shad with shl/shr/sar
u32 r2 = op.rs2.imm_value();
if ((r2 & 0x1F) == 0)
if (r2 != 0) // r2 == 0 is nop, handled in SimplifyExpressionPass()
{
if (op.op == shop_shld)
// rd = 0
ReplaceByMov32(op, 0);
if ((r2 & 0x1F) == 0)
{
if (op.op == shop_shld) {
// rd = 0
ReplaceByMov32(op, 0);
}
else
{
// rd = r1 >> 31
op.op = shop_sar;
op.rs2._imm = 31;
stats.constant_ops_replaced++;
}
}
else if ((r2 & 0x80000000) == 0)
{
// rd = r1 << (r2 & 0x1F)
op.op = shop_shl;
op.rs2._imm = r2 & 0x1F;
stats.constant_ops_replaced++;
}
else
{
// rd = r1 >> 31;
op.op = shop_sar;
op.rs2._imm = 31;
// rd = r1 >> ((~r2 & 0x1F) + 1)
op.op = op.op == shop_shad ? shop_sar : shop_shr;
op.rs2._imm = (~r2 & 0x1F) + 1;
stats.constant_ops_replaced++;
}
}
else if ((r2 & 0x80000000) == 0)
{
// rd = r1 << (r2 & 0x1F)
op.op = shop_shl;
op.rs2._imm = r2 & 0x1F;
stats.constant_ops_replaced++;
}
else
{
// rd = r1 >> ((~r2 & 0x1F) + 1)
op.op = op.op == shop_shad ? shop_sar : shop_shr;
op.rs2._imm = (~r2 & 0x1F) + 1;
stats.constant_ops_replaced++;
}
}
}
}
Expand Down

0 comments on commit 15617c1

Please sign in to comment.