diff options
author | Max Graey <maxgraey@gmail.com> | 2020-11-11 01:56:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 15:56:14 -0800 |
commit | bb124f995527f650d98bdac30b00b125b76fab9c (patch) | |
tree | 05c63599a575cf40b1aff5ed5c4da7211324bb28 /test | |
parent | 236296d8563e0f90c3b57f32f1f8f63bac414b89 (diff) | |
download | binaryen-bb124f995527f650d98bdac30b00b125b76fab9c.tar.gz binaryen-bb124f995527f650d98bdac30b00b125b76fab9c.tar.bz2 binaryen-bb124f995527f650d98bdac30b00b125b76fab9c.zip |
Optimize i32(x) % C_pot in boolean context (#3307)
bool(i32(x) % C_pot) -> bool(i32(x) & (C_pot - 1))
bool(i32(x) % min_s) -> bool(i32(x) & max_s)
For all other situations we already do this for (i32|i64).rem_s
Diffstat (limited to 'test')
-rw-r--r-- | test/passes/optimize-instructions_all-features.txt | 20 | ||||
-rw-r--r-- | test/passes/optimize-instructions_all-features.wast | 18 |
2 files changed, 38 insertions, 0 deletions
diff --git a/test/passes/optimize-instructions_all-features.txt b/test/passes/optimize-instructions_all-features.txt index a5cc470fb..88b053835 100644 --- a/test/passes/optimize-instructions_all-features.txt +++ b/test/passes/optimize-instructions_all-features.txt @@ -4005,6 +4005,26 @@ (i32.const 0) ) ) + (drop + (if (result i32) + (i32.and + (local.get $x) + (i32.const 3) + ) + (i32.const 1) + (i32.const 0) + ) + ) + (drop + (if (result i32) + (i32.and + (local.get $x) + (i32.const 2147483647) + ) + (i32.const 1) + (i32.const 0) + ) + ) ) (func $optimize-bitwise-oprations (param $x i32) (param $y i32) (param $z i64) (param $w i64) (drop diff --git a/test/passes/optimize-instructions_all-features.wast b/test/passes/optimize-instructions_all-features.wast index b28536519..5804c1b2a 100644 --- a/test/passes/optimize-instructions_all-features.wast +++ b/test/passes/optimize-instructions_all-features.wast @@ -4517,6 +4517,24 @@ ) (i32.const 0) )) + ;; (signed)x % 4 ? 1 : 0 + (drop (if (result i32) + (i32.rem_s + (local.get $x) + (i32.const 4) + ) + (i32.const 1) + (i32.const 0) + )) + ;; (signed)x % min_s ? 1 : 0 + (drop (if (result i32) + (i32.rem_s + (local.get $x) + (i32.const 0x80000000) + ) + (i32.const 1) + (i32.const 0) + )) ) (func $optimize-bitwise-oprations (param $x i32) (param $y i32) (param $z i64) (param $w i64) ;; ~(1 << x) -> rotl(-2, x) |