summaryrefslogtreecommitdiff
path: root/test/passes/optimize-instructions.wast
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2018-08-27 11:41:48 -0700
committerGitHub <noreply@github.com>2018-08-27 11:41:48 -0700
commit65112ceec0cb92ec853f3391263d51a12b15bad0 (patch)
treed8b54a465365a2fb4c15c5c859ad5e80447c8a7b /test/passes/optimize-instructions.wast
parentf215193ec12a45fdd893ea8a8cec1353aa3b529e (diff)
downloadbinaryen-65112ceec0cb92ec853f3391263d51a12b15bad0.tar.gz
binaryen-65112ceec0cb92ec853f3391263d51a12b15bad0.tar.bz2
binaryen-65112ceec0cb92ec853f3391263d51a12b15bad0.zip
Improve getFallthrough (#1643)
That method looks through tee_locals and other operations that receive a value and let it flow through them, like a block's final value, etc. It just handled a few such operations, with this PR all of them should be handled. Also refactor it out of the OptimizeInstructions pass as I think it may be useful for propagating returned constants.
Diffstat (limited to 'test/passes/optimize-instructions.wast')
-rw-r--r--test/passes/optimize-instructions.wast47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index b65432715..aa979c62a 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -3479,6 +3479,53 @@
)
)
)
+ (func $getFallthrough ;; unit tests for Properties::getFallthrough
+ (local $x0 i32)
+ (local $x1 i32)
+ (local $x2 i32)
+ (local $x3 i32)
+ (local $x4 i32)
+ (local $x5 i32)
+ (local $x6 i32)
+ (local $x7 i32)
+ ;; the trivial case
+ (set_local $x0 (i32.const 1))
+ (drop (i32.and (get_local $x0) (i32.const 7)))
+ ;; tees
+ (set_local $x1 (tee_local $x2 (i32.const 1)))
+ (drop (i32.and (get_local $x1) (i32.const 7)))
+ ;; loop
+ (set_local $x3 (loop (result i32) (i32.const 1)))
+ (drop (i32.and (get_local $x3) (i32.const 7)))
+ ;; if - two sides, can't
+ (set_local $x4 (if (result i32) (i32.const 1) (i32.const 2) (i32.const 3)))
+ (drop (i32.and (get_local $x4) (i32.const 7)))
+ ;; if - one side, can
+ (set_local $x5 (if (result i32) (i32.const 1) (unreachable) (i32.const 3)))
+ (drop (i32.and (get_local $x5) (i32.const 7)))
+ ;; if - one side, can
+ (set_local $x6 (if (result i32) (i32.const 1) (i32.const 3) (unreachable)))
+ (drop (i32.and (get_local $x6) (i32.const 7)))
+ ;; br_if with value
+ (drop
+ (block $out (result i32)
+ (set_local $x7 (br_if $out (i32.const 1) (i32.const 1)))
+ (drop (i32.and (get_local $x7) (i32.const 7)))
+ (unreachable)
+ )
+ )
+ )
+ (func $tee-with-unreachable-value (result f64)
+ (local $var$0 i32)
+ (block $label$1 (result f64)
+ (tee_local $var$0
+ (br_if $label$1 ;; the f64 does not actually flow through this, it's unreachable (and the type is wrong - but unchecked)
+ (f64.const 1)
+ (unreachable)
+ )
+ )
+ )
+ )
)
(module
(import "env" "memory" (memory $0 (shared 256 256)))