summaryrefslogtreecommitdiff
path: root/test/passes/optimize-instructions_all-features.wast
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2020-09-30 05:36:17 +0300
committerGitHub <noreply@github.com>2020-09-29 19:36:17 -0700
commit7e99538386e047bddc41ad50b9762b7d4b9611b8 (patch)
treebd0d875a773e255c6e35be3806de71ec47250180 /test/passes/optimize-instructions_all-features.wast
parent67a96ae60085366b59d64bc997c9e6525c247e27 (diff)
downloadbinaryen-7e99538386e047bddc41ad50b9762b7d4b9611b8.tar.gz
binaryen-7e99538386e047bddc41ad50b9762b7d4b9611b8.tar.bz2
binaryen-7e99538386e047bddc41ad50b9762b7d4b9611b8.zip
Simplify signed remainders compared with zero (#3153)
Specifically when the divisor is a power of two. `eqz((signed)x % C_pot)` -> `eqz(x & (C_pot - 1))` `(signed)x % C_pot != 0` -> `x & (C_pot - 1) != 0`
Diffstat (limited to 'test/passes/optimize-instructions_all-features.wast')
-rw-r--r--test/passes/optimize-instructions_all-features.wast67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/passes/optimize-instructions_all-features.wast b/test/passes/optimize-instructions_all-features.wast
index 8c2cefb53..1afa3e5b5 100644
--- a/test/passes/optimize-instructions_all-features.wast
+++ b/test/passes/optimize-instructions_all-features.wast
@@ -3104,6 +3104,73 @@
(i64.const 1)
))
)
+ (func $srem-by-pot-eq-ne-zero (param $x i32) (param $y i64)
+ ;; eqz((signed)x % 4)
+ (drop (i32.eqz
+ (i32.rem_s
+ (local.get $x)
+ (i32.const 4)
+ )
+ ))
+ (drop (i64.eqz
+ (i64.rem_s
+ (local.get $y)
+ (i64.const 4)
+ )
+ ))
+ ;; (signed)x % 4 == 0
+ (drop (i32.eq
+ (i32.rem_s
+ (local.get $x)
+ (i32.const 4)
+ )
+ (i32.const 0)
+ ))
+ (drop (i64.eq
+ (i64.rem_s
+ (local.get $y)
+ (i64.const 2)
+ )
+ (i64.const 0)
+ ))
+ ;; ;; (signed)x % 2 != 0
+ (drop (i32.ne
+ (i32.rem_s
+ (local.get $x)
+ (i32.const 2)
+ )
+ (i32.const 0)
+ ))
+ (drop (i64.ne
+ (i64.rem_s
+ (local.get $y)
+ (i64.const 2)
+ )
+ (i64.const 0)
+ ))
+ ;; ;;
+ (drop (i32.eq
+ (i32.rem_s
+ (local.get $x)
+ (i32.const 3) ;; skip
+ )
+ (i32.const 0)
+ ))
+ (drop (i32.eq
+ (i32.rem_s
+ (local.get $x)
+ (i32.const -4) ;; skip
+ )
+ (i32.const 0)
+ ))
+ (drop (i64.eq
+ (i64.rem_s
+ (local.get $y)
+ (i64.const 3) ;; skip
+ )
+ (i64.const 0)
+ ))
+ )
(func $orZero (param $0 i32) (result i32)
(i32.or
(local.get $0)