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/unit.fromasm.imprecise | |
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/unit.fromasm.imprecise')
-rw-r--r-- | test/unit.fromasm.imprecise | 74 |
1 files changed, 35 insertions, 39 deletions
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index b5da4cfe4..a56482591 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -233,20 +233,20 @@ ) (func $smallCompare (; 18 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) (if - (i32.lt_s - (get_local $0) - (get_local $1) - ) - (set_local $0 - (i32.add - (get_local $0) - (i32.const 1) - ) - ) - ) - (if (i32.lt_u - (get_local $0) + (tee_local $0 + (select + (i32.add + (get_local $0) + (i32.const 1) + ) + (get_local $0) + (i32.lt_s + (get_local $0) + (get_local $1) + ) + ) + ) (get_local $1) ) (set_local $0 @@ -426,24 +426,20 @@ (func $zeroInit (; 25 ;) (; has Stack IR ;) (param $0 i32) (local $1 i32) (if - (call $lb - (i32.const 0) - ) - (if - (call $lb - (i32.const 1) - ) - (set_local $1 + (i32.eq + (if (result i32) + (call $lb + (i32.const 0) + ) + (if (result i32) + (call $lb + (i32.const 1) + ) + (i32.const 3) + (get_local $1) + ) (i32.const 3) ) - ) - (set_local $1 - (i32.const 3) - ) - ) - (if - (i32.eq - (get_local $1) (i32.const 3) ) (drop @@ -999,16 +995,16 @@ ) (if (i32.eq - (get_local $0) - (i32.const 300) - ) - (set_local $1 - (i32.const 2) - ) - ) - (if - (i32.eq - (get_local $1) + (tee_local $1 + (select + (i32.const 2) + (get_local $1) + (i32.eq + (get_local $0) + (i32.const 300) + ) + ) + ) (i32.const 2) ) (call $relooperJumpThreading_irreducible |