summaryrefslogtreecommitdiff
path: root/test/passes/optimize-instructions_all-features.wast
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2020-09-18 02:39:39 +0300
committerGitHub <noreply@github.com>2020-09-17 16:39:39 -0700
commit2548f04c198594a21e4144261e8cfea5de56308a (patch)
treecd3172a039e10917d34adf456093869aebddff01 /test/passes/optimize-instructions_all-features.wast
parent2d47c0b8ae7b72e710b982abce83429c50c6de30 (diff)
downloadbinaryen-2548f04c198594a21e4144261e8cfea5de56308a.tar.gz
binaryen-2548f04c198594a21e4144261e8cfea5de56308a.tar.bz2
binaryen-2548f04c198594a21e4144261e8cfea5de56308a.zip
Optimize binary operations with 1-bit on lhs and 1 const on rhs (#2948)
`expr | 1` --> `1` `expr & 1` --> `expr` `expr == 1` --> `expr` `expr != 1` --> `!expr` where `maxBits(expr) == 1` i.e `expr` is boolean
Diffstat (limited to 'test/passes/optimize-instructions_all-features.wast')
-rw-r--r--test/passes/optimize-instructions_all-features.wast69
1 files changed, 67 insertions, 2 deletions
diff --git a/test/passes/optimize-instructions_all-features.wast b/test/passes/optimize-instructions_all-features.wast
index 7dc8cffbf..1b03782e9 100644
--- a/test/passes/optimize-instructions_all-features.wast
+++ b/test/passes/optimize-instructions_all-features.wast
@@ -3960,17 +3960,82 @@
)
)
)
- (func $optimize-boolean (param $x i32)
+ (func $optimize-boolean (param $x i32) (param $y i64)
+ ;; bool(-x) -> bool(x)
(drop
(select
(i32.const 1)
(i32.const 2)
- (i32.sub ;; bool(-x) -> bool(x)
+ (i32.sub
(i32.const 0)
(local.get $x)
)
)
)
+ ;; i32(bool(expr)) == 1 -> bool(expr)
+ (drop (i32.eq
+ (i32.and
+ (local.get $x)
+ (i32.const 1)
+ )
+ (i32.const 1)
+ ))
+ ;; i32(bool(expr)) != 1 -> !bool(expr)
+ (drop (i32.ne
+ (i32.and
+ (local.get $x)
+ (i32.const 1)
+ )
+ (i32.const 1)
+ ))
+ ;; i64(bool(expr)) == 1 -> i64(bool(expr))
+ (drop (i64.eq
+ (i64.and
+ (local.get $y)
+ (i64.const 1)
+ )
+ (i64.const 1)
+ ))
+ ;; i64(bool(expr)) != 1 -> !i64(bool(expr))
+ (drop (i64.ne
+ (i64.and
+ (local.get $y)
+ (i64.const 1)
+ )
+ (i64.const 1)
+ ))
+ ;; i32(bool(expr)) & 1 -> bool(expr)
+ (drop (i32.and
+ (i32.and
+ (local.get $x)
+ (i32.const 1)
+ )
+ (i32.const 1)
+ ))
+ ;; i32(bool(expr)) | 1 -> 1
+ (drop (i32.or
+ (i32.and
+ (local.get $x)
+ (i32.const 1)
+ )
+ (i32.const 1)
+ ))
+ ;; i64(bool(expr)) & 1 -> i64(bool(expr))
+ (drop (i64.and
+ (i64.and
+ (local.get $y)
+ (i64.const 1)
+ )
+ (i64.const 1)
+ ))
+ ;; i64(bool(expr)) | 1 -> 1
+ (drop (i64.or
+ (i64.and
+ (local.get $y)
+ (i64.const 1)
+ )
+ (i64.const 1)
+ ))
)
(func $getFallthrough ;; unit tests for Properties::getFallthrough
(local $x0 i32)