summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai (kripken) <alonzakai@gmail.com>2017-07-31 08:05:26 -0700
committerAlon Zakai (kripken) <alonzakai@gmail.com>2017-07-31 08:05:26 -0700
commit4aa3463a6b98e41070d03ddbe60e689537b02b59 (patch)
treebb102c8a09e0e5a9bd4d1076dde25c4250598365
parentb69f8a6bfc7963e0c56b10a69603e5dd36de58c3 (diff)
downloadbinaryen-4aa3463a6b98e41070d03ddbe60e689537b02b59.tar.gz
binaryen-4aa3463a6b98e41070d03ddbe60e689537b02b59.tar.bz2
binaryen-4aa3463a6b98e41070d03ddbe60e689537b02b59.zip
handle squared shifts of an unreachable
-rw-r--r--src/passes/OptimizeInstructions.cpp4
-rw-r--r--test/passes/optimize-instructions.txt6
-rw-r--r--test/passes/optimize-instructions.wast9
3 files changed, 17 insertions, 2 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 60222c3cd..6179833b8 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -539,9 +539,9 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
// shifts only use an effective amount from the constant, so adding must
// be done carefully
auto total = Bits::getEffectiveShifts(leftRight) + Bits::getEffectiveShifts(right);
- if (total == Bits::getEffectiveShifts(total, left->type)) {
+ if (total == Bits::getEffectiveShifts(total, right->type)) {
// no overflow, we can do this
- leftRight->value = LiteralUtils::makeLiteralFromInt32(total, left->type);
+ leftRight->value = LiteralUtils::makeLiteralFromInt32(total, right->type);
return left;
} // TODO: handle overflows
}
diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt
index e376d97d9..a399a9096 100644
--- a/test/passes/optimize-instructions.txt
+++ b/test/passes/optimize-instructions.txt
@@ -2055,4 +2055,10 @@
(i64.const 9)
)
)
+ (func $shifts-square-unreachable (type $3) (param $x i32) (result i32)
+ (i32.shr_u
+ (unreachable)
+ (i32.const 9)
+ )
+ )
)
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index 7e07e8aee..8362453e9 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -2487,4 +2487,13 @@
(i64.const 4098) ;; 2 bits effectively
)
)
+ (func $shifts-square-unreachable (param $x i32) (result i32)
+ (i32.shr_u
+ (i32.shr_u
+ (unreachable)
+ (i32.const 1031) ;; 7 bits effectively
+ )
+ (i32.const 4098) ;; 2 bits effectively
+ )
+ )
)