summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/OptimizeInstructions.cpp4
-rw-r--r--test/passes/optimize-instructions.txt11
-rw-r--r--test/passes/optimize-instructions.wast11
3 files changed, 22 insertions, 4 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 2930fe9c9..43a8faa32 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -195,7 +195,7 @@ Index getMaxBits(Expression* curr, LocalInfoProvider* localInfoProvider) {
case ShrUInt32: {
if (auto* shift = binary->right->dynCast<Const>()) {
auto maxBits = getMaxBits(binary->left, localInfoProvider);
- auto shifts = std::min(Index(shift->value.geti32()), maxBits); // can ignore more shifts than zero us out
+ auto shifts = std::min(Index(shift->value.geti32() & 31), maxBits); // can ignore more shifts than zero us out
return std::max(Index(0), maxBits - shifts);
}
return 32;
@@ -204,7 +204,7 @@ Index getMaxBits(Expression* curr, LocalInfoProvider* localInfoProvider) {
if (auto* shift = binary->right->dynCast<Const>()) {
auto maxBits = getMaxBits(binary->left, localInfoProvider);
if (maxBits == 32) return 32;
- auto shifts = std::min(Index(shift->value.geti32()), maxBits); // can ignore more shifts than zero us out
+ auto shifts = std::min(Index(shift->value.geti32() & 31), maxBits); // can ignore more shifts than zero us out
return std::max(Index(0), maxBits - shifts);
}
return 32;
diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt
index 301a6cfc0..68359d9fb 100644
--- a/test/passes/optimize-instructions.txt
+++ b/test/passes/optimize-instructions.txt
@@ -805,7 +805,7 @@
(i32.const -1)
(i32.const 2147483647)
)
- (i32.const 32)
+ (i32.const 31)
)
)
(drop
@@ -2006,4 +2006,13 @@
(i32.const 1)
)
)
+ (func $neg-shifts-and-255 (type $2) (result i32)
+ (i32.and
+ (i32.shr_u
+ (i32.const -99)
+ (i32.const -32)
+ )
+ (i32.const 255)
+ )
+ )
)
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index cf8275412..5300b8da8 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -842,7 +842,7 @@
(i32.const -1)
(i32.const 2147483647)
)
- (i32.const 32)
+ (i32.const 31) ;; adjusted after we fixed shift computation to just look at lower 5 bits
)
(i32.const 24)
)
@@ -2433,4 +2433,13 @@
(i32.const 1)
)
)
+ (func $neg-shifts-and-255 (result i32)
+ (i32.and
+ (i32.shr_u
+ (i32.const -99)
+ (i32.const -32) ;; this shift does nothing
+ )
+ (i32.const 255)
+ )
+ )
)