diff options
author | Alon Zakai (kripken) <alonzakai@gmail.com> | 2018-12-01 18:28:52 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2018-12-04 10:14:29 -0800 |
commit | e6048c1dabde9e511d25c8bd6d2da68461807f74 (patch) | |
tree | 08f5d4d4fbf5586f602bcab90a72aa288ec72ad1 /test/passes/simplify-locals.wast | |
parent | 774768375dbe8cdee91b797f1e8deec586085fb4 (diff) | |
download | binaryen-e6048c1dabde9e511d25c8bd6d2da68461807f74.tar.gz binaryen-e6048c1dabde9e511d25c8bd6d2da68461807f74.tar.bz2 binaryen-e6048c1dabde9e511d25c8bd6d2da68461807f74.zip |
Speculate in simplify-locals that it is worth turning an if into
an if-else.
If an if sets a local,
(if
(..condition..)
(set_local $x (..value..))
)
we can turn it into
(set_local $x
(if
(..condition..)
(..value..)
(get_local $x)
)
)
This increases code size and adds a branch in the if, but allows
the set to be optimized into a tee or optimized out entirely. In
the worst case, other optimizations can break up an if with a copy
in one of its arms later.
Includes a determinism fix for EquivalentSets, which this patch
triggered.
Diffstat (limited to 'test/passes/simplify-locals.wast')
-rw-r--r-- | test/passes/simplify-locals.wast | 203 |
1 files changed, 203 insertions, 0 deletions
diff --git a/test/passes/simplify-locals.wast b/test/passes/simplify-locals.wast index 60531717c..5396e6a5b 100644 --- a/test/passes/simplify-locals.wast +++ b/test/passes/simplify-locals.wast @@ -12,6 +12,8 @@ (import $_i64Subtract "env" "i64sub" (param i32 i32 i32 i32) (result i32)) (import $___udivmoddi4 "env" "moddi" (param i32 i32 i32 i32 i32) (result i32)) (import $lp "env" "lp" (param i32 i32) (result i32)) + (import "fuzzing-support" "log-f32" (func $fimport$0 (param f32))) + (global $global$0 (mut i32) (i32.const 10)) (func $contrast ;; check for tee and structure sinking (local $x i32) (local $y i32) @@ -882,6 +884,207 @@ ) ) ) + (func $if-one-side (result i32) + (local $x i32) + (if + (i32.const 1) + (set_local $x + (i32.const 2) + ) + ) + (get_local $x) + ) + (func $if-one-side-undo (result i32) + (local $x i32) + (local $y i32) + (set_local $y + (i32.const 0) + ) + (if + (i32.const 1) + (set_local $x + (i32.const 2) + ) + ) + (get_local $y) + ) + (func $if-one-side-multi (param $0 i32) (result i32) + (if + (i32.lt_s + (get_local $0) + (i32.const -1073741824) + ) + (set_local $0 + (i32.const -1073741824) + ) + (if + (i32.gt_s + (get_local $0) + (i32.const 1073741823) + ) + (set_local $0 + (i32.const 1073741823) + ) + ) + ) + (get_local $0) + ) + (func $if-one-side-undo-but-its-a-tee (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $x i32) + (local $y i32) + (local $z i32) + ;; break these splittable ifs up + (set_local $x + (if (result i32) + (i32.const -1) + (i32.const -2) + (get_local $x) + ) + ) + ;; oops, this one is a tee + (drop + (call $if-one-side-undo-but-its-a-tee + (tee_local $x + (if (result i32) + (i32.const -3) + (i32.const -4) + (get_local $x) + ) + ) + ) + ) + ;; sinkable + (set_local $y + (if (result i32) + (i32.const -5) + (i32.const -6) + (get_local $y) + ) + ) + (drop (i32.eqz (get_local $y))) + ;; tee-able at best + (set_local $z + (if (result i32) + (i32.const -7) + (i32.const -8) + (get_local $z) + ) + ) + (drop + (i32.add + (get_local $z) + (get_local $z) + ) + ) + (if + (block $label$1 (result i32) + (if + (i32.const 1) + (set_local $4 + (i32.const 2) + ) + ) + (if + (get_local $4) + (set_local $4 + (i32.const 0) + ) + ) + (get_local $4) + ) + (unreachable) + ) + (i32.const 0) + ) + (func $splittable-ifs-multicycle (param $20 i32) (result i32) + (set_local $20 + (if (result i32) + (i32.const 1) + (if (result i32) + (i32.const 2) + (if (result i32) + (i32.const 3) + (i32.const 4) + (get_local $20) + ) + (get_local $20) + ) + (get_local $20) + ) + ) + (get_local $20) + ) + (func $update-getCounter (param $0 i32) (param $1 f64) (param $2 f64) (param $3 f32) (param $4 i32) (result f64) + (set_global $global$0 + (i32.sub + (get_global $global$0) + (i32.const 1) + ) + ) + (set_global $global$0 + (i32.sub + (get_global $global$0) + (i32.const 1) + ) + ) + (loop $label$1 (result f64) + (set_global $global$0 + (i32.sub + (get_global $global$0) + (i32.const 1) + ) + ) + (set_global $global$0 + (i32.sub + (get_global $global$0) + (i32.const 1) + ) + ) + (call $fimport$0 + (tee_local $3 + (if (result f32) + (i32.eqz + (get_local $0) + ) + (f32.const 4623408228068004207103214e13) + (get_local $3) + ) + ) + ) + (set_global $global$0 + (i32.sub + (get_global $global$0) + (i32.const 1) + ) + ) + (if (result f64) + (get_global $global$0) + (block + (set_global $global$0 + (i32.sub + (get_global $global$0) + (i32.const 1) + ) + ) + (set_local $0 + (i32.const -65) + ) + (set_global $global$0 + (i32.sub + (get_global $global$0) + (i32.const 1) + ) + ) + (br $label$1) + ) + (f64.const -70) + ) + ) + ) ) (module (memory (shared 256 256)) |