summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/OptimizeInstructions.cpp5
-rw-r--r--test/passes/optimize-instructions_all-features.txt8
-rw-r--r--test/passes/optimize-instructions_all-features.wast10
3 files changed, 20 insertions, 3 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index d77db8093..b0d12eb95 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -1275,7 +1275,6 @@ private:
if ((matches(curr, binary(Abstract::Eq, any(&left), ival(0))))) {
return builder.makeUnary(EqZInt64, left);
}
-
// Operations on one
// (signed)x % 1 ==> 0
if (matches(curr, binary(Abstract::RemS, pure(&left), ival(1)))) {
@@ -1298,7 +1297,9 @@ private:
return left;
}
// i64(bool(x)) == 1 ==> i32(bool(x))
- if (matches(curr, binary(EqInt64, any(&left), i64(1))) &&
+ // i64(bool(x)) != 0 ==> i32(bool(x))
+ if ((matches(curr, binary(EqInt64, any(&left), i64(1))) ||
+ matches(curr, binary(NeInt64, any(&left), i64(0)))) &&
Bits::getMaxBits(left, this) == 1) {
return builder.makeUnary(WrapInt64, left);
}
diff --git a/test/passes/optimize-instructions_all-features.txt b/test/passes/optimize-instructions_all-features.txt
index 82b0af68a..e3ad30a0b 100644
--- a/test/passes/optimize-instructions_all-features.txt
+++ b/test/passes/optimize-instructions_all-features.txt
@@ -3434,6 +3434,14 @@
)
(drop
(i32.wrap_i64
+ (i64.shr_u
+ (local.get $y)
+ (i64.const 63)
+ )
+ )
+ )
+ (drop
+ (i32.wrap_i64
(i64.and
(local.get $y)
(i64.const 1)
diff --git a/test/passes/optimize-instructions_all-features.wast b/test/passes/optimize-instructions_all-features.wast
index a89a16c1b..8c2cefb53 100644
--- a/test/passes/optimize-instructions_all-features.wast
+++ b/test/passes/optimize-instructions_all-features.wast
@@ -3988,7 +3988,15 @@
)
(i32.const 1)
))
- ;; i64(bool(expr)) == 1 -> i64(bool(expr))
+ ;; i64(bool(expr)) != 0 -> i32(bool(expr))
+ (drop (i64.ne
+ (i64.shr_u
+ (local.get $y)
+ (i64.const 63)
+ )
+ (i64.const 0)
+ ))
+ ;; i64(bool(expr)) == 1 -> i32(bool(expr))
(drop (i64.eq
(i64.and
(local.get $y)