summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2021-08-06 00:51:15 +0300
committerGitHub <noreply@github.com>2021-08-05 14:51:15 -0700
commitcbe4b578a639ede260f33fc4ebcde17fcbf4ccc2 (patch)
treea5cca5cd60c69b8e228a853ff06ef159eca8adc5
parent243ac8942e1e0136b8d91242642d9bc825a9cfd9 (diff)
downloadbinaryen-cbe4b578a639ede260f33fc4ebcde17fcbf4ccc2.tar.gz
binaryen-cbe4b578a639ede260f33fc4ebcde17fcbf4ccc2.tar.bz2
binaryen-cbe4b578a639ede260f33fc4ebcde17fcbf4ccc2.zip
[OptimizeForJS] Fix use of localized variable in popcnt(x) == 1 rule (#4057)
Localizer may have added a new tee and a local, and we should apply the tee in the right place.
-rw-r--r--src/passes/OptimizeForJS.cpp4
-rw-r--r--test/lit/passes/optimize-for-js.wast29
2 files changed, 30 insertions, 3 deletions
diff --git a/src/passes/OptimizeForJS.cpp b/src/passes/OptimizeForJS.cpp
index b5ba84d90..589374c06 100644
--- a/src/passes/OptimizeForJS.cpp
+++ b/src/passes/OptimizeForJS.cpp
@@ -54,9 +54,7 @@ struct OptimizeForJSPass : public WalkerPass<PostWalker<OptimizeForJSPass>> {
replaceCurrent(builder.makeBinary(
AndInt32,
- builder.makeUnary(
- EqZInt32,
- builder.makeUnary(eqzOp, builder.makeLocalGet(temp.index, type))),
+ builder.makeUnary(EqZInt32, builder.makeUnary(eqzOp, temp.expr)),
builder.makeUnary(
eqzOp,
builder.makeBinary(
diff --git a/test/lit/passes/optimize-for-js.wast b/test/lit/passes/optimize-for-js.wast
index c123011fc..c771f77a7 100644
--- a/test/lit/passes/optimize-for-js.wast
+++ b/test/lit/passes/optimize-for-js.wast
@@ -27,6 +27,35 @@
(i32.const 1)
)
)
+ ;; CHECK: (func $is-power-of-2_expr_32 (param $x i64) (result i32)
+ ;; CHECK-NEXT: (local $1 i32)
+ ;; CHECK-NEXT: (i32.and
+ ;; CHECK-NEXT: (i32.eqz
+ ;; CHECK-NEXT: (i32.eqz
+ ;; CHECK-NEXT: (local.tee $1
+ ;; CHECK-NEXT: (i32.wrap_i64
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (i32.eqz
+ ;; CHECK-NEXT: (i32.and
+ ;; CHECK-NEXT: (local.get $1)
+ ;; CHECK-NEXT: (i32.sub
+ ;; CHECK-NEXT: (local.get $1)
+ ;; CHECK-NEXT: (i32.const 1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $is-power-of-2_expr_32 (param $x i64) (result i32)
+ (i32.eq
+ (i32.popcnt (i32.wrap_i64 (local.get $x)))
+ (i32.const 1)
+ )
+ )
;; CHECK: (func $is-power-of-2_64 (param $x i64) (result i32)
;; CHECK-NEXT: (i32.and
;; CHECK-NEXT: (i32.eqz