summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeInstructions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r--src/passes/OptimizeInstructions.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index c4a5b2ed4..c4ce8c239 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -476,6 +476,22 @@ struct OptimizeInstructions
break;
}
}
+ // i32(x) << 24 >> 24 ==> i32.extend8_s(x)
+ // i32(x) << 16 >> 16 ==> i32.extend16_s(x)
+ if (matches(curr,
+ binary(ShrSInt32,
+ binary(ShlInt32, any(&x), i32(&c1)),
+ i32(&c2))) &&
+ Bits::getEffectiveShifts(c1) == Bits::getEffectiveShifts(c2)) {
+ switch (32 - Bits::getEffectiveShifts(c1)) {
+ case 8:
+ return replaceCurrent(builder.makeUnary(ExtendS8Int32, x));
+ case 16:
+ return replaceCurrent(builder.makeUnary(ExtendS16Int32, x));
+ default:
+ break;
+ }
+ }
}
}
{