summaryrefslogtreecommitdiff
path: root/test/passes/simplify-locals.wast
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-04-22 15:29:16 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-04-24 16:01:16 -0700
commit1fa7f7fef75d2cb795f04b2737efb46a280c9cdc (patch)
tree68cd9ed9b3ab284eb3a7431d80f1975eb70da5c2 /test/passes/simplify-locals.wast
parent308a2e24f8690a76d3ada08f4c5cfb70c6cccbb5 (diff)
downloadbinaryen-1fa7f7fef75d2cb795f04b2737efb46a280c9cdc.tar.gz
binaryen-1fa7f7fef75d2cb795f04b2737efb46a280c9cdc.tar.bz2
binaryen-1fa7f7fef75d2cb795f04b2737efb46a280c9cdc.zip
optimize block and if returns, by merging set_locals that flow out of them
Diffstat (limited to 'test/passes/simplify-locals.wast')
-rw-r--r--test/passes/simplify-locals.wast64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/passes/simplify-locals.wast b/test/passes/simplify-locals.wast
index 1b71c46b5..5f1db4bdb 100644
--- a/test/passes/simplify-locals.wast
+++ b/test/passes/simplify-locals.wast
@@ -387,5 +387,69 @@
)
)
)
+ (func $block-returns
+ (local $x i32)
+ (block $out
+ (block $waka
+ (set_local $x (i32.const 12))
+ (br_if $waka
+ (i32.const 1)
+ )
+ (set_local $x (i32.const 34))
+ )
+ (br_if $out ;; barrier
+ (i32.const 1)
+ )
+ (get_local $x) ;; a use, so setlocals are not all killed
+ (block $waka2
+ (if
+ (i32.const 1)
+ (set_local $x (i32.const 13))
+ (set_local $x (i32.const 24))
+ )
+ (if
+ (i32.const 1)
+ (block
+ (set_local $x (i32.const 14))
+ )
+ (block
+ (set_local $x (i32.const 25))
+ )
+ )
+ )
+ (br_if $out ;; barrier
+ (i32.const 1)
+ )
+ (block $sink-out-of-me-i-have-but-one-exit
+ (set_local $x (i32.const 99))
+ )
+ (get_local $x)
+ )
+ )
+ (func $multiple (param $s i32) (param $r i32) (param $f i32) (param $p i32) (param $t i32) (param $m i32)
+ (set_local $s
+ (get_local $m)
+ )
+ (set_local $r
+ (i32.add
+ (get_local $f)
+ (get_local $p)
+ )
+ )
+ (set_local $t ;; t is equal to p's original value; p must not be set to before t gets that value
+ (get_local $p)
+ )
+ (set_local $p
+ (i32.load
+ (i32.const r)
+ )
+ )
+ (i32.store
+ (get_local $r)
+ (get_local $t)
+ )
+ (get_local $s)
+ (get_local $t)
+ )
)