diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-08-23 14:38:29 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-07 09:55:06 -0700 |
commit | e125ae76b29b84563892263663e66ff072852c99 (patch) | |
tree | 8139743a155624d80359b18eb4cf88e2685dd504 | |
parent | 8384ada03f9ffc5d09d2a39e1dfa49cd1e1c8686 (diff) | |
download | binaryen-e125ae76b29b84563892263663e66ff072852c99.tar.gz binaryen-e125ae76b29b84563892263663e66ff072852c99.tar.bz2 binaryen-e125ae76b29b84563892263663e66ff072852c99.zip |
don't simplify locals out of loops if they contain branching, as it may invalidate the branch
-rw-r--r-- | src/ast_utils.h | 3 | ||||
-rw-r--r-- | test/passes/simplify-locals.txt | 29 | ||||
-rw-r--r-- | test/passes/simplify-locals.wast | 20 |
3 files changed, 52 insertions, 0 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h index b81413d78..0bb0a821e 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -130,6 +130,9 @@ struct EffectAnalyzer : public PostWalker<EffectAnalyzer, Visitor<EffectAnalyzer bool checkPost(Expression* curr) { visit(curr); + if (curr->is<Loop>()) { + branches = true; + } return hasAnything(); } diff --git a/test/passes/simplify-locals.txt b/test/passes/simplify-locals.txt index 60e07f3fb..ee4418953 100644 --- a/test/passes/simplify-locals.txt +++ b/test/passes/simplify-locals.txt @@ -7,6 +7,7 @@ (type $4 (func (param i32))) (type $5 (func (param i32) (result i32))) (type $6 (func (param i32 i32 i32 i32 i32 i32))) + (type $7 (func (param i32 i32))) (import $waka "env" "waka") (import $waka_int "env" "waka_int" (result i32)) (import $_i64Subtract "env" "i64sub" (param i32 i32 i32 i32) (result i32)) @@ -673,4 +674,32 @@ (get_local $i1) ) ) + (func $no-out-of-label (type $7) (param $x i32) (param $y i32) + (loop $moar + (set_local $x + (block $block0 + (br_if $moar + (get_local $x) + ) + (i32.const 0) + ) + ) + ) + (drop + (get_local $x) + ) + (block $moar + (set_local $y + (block $block1 + (br_if $moar + (get_local $y) + ) + (i32.const 0) + ) + ) + ) + (drop + (get_local $y) + ) + ) ) diff --git a/test/passes/simplify-locals.wast b/test/passes/simplify-locals.wast index d74ebe054..2b5b84a5f 100644 --- a/test/passes/simplify-locals.wast +++ b/test/passes/simplify-locals.wast @@ -731,4 +731,24 @@ (get_local $i1) ) ) + (func $no-out-of-label (param $x i32) (param $y i32) + (loop $moar + (set_local $x + (block + (br_if $moar (get_local $x)) + (i32.const 0) + ) + ) + ) + (drop (get_local $x)) + (block $moar + (set_local $y + (block + (br_if $moar (get_local $y)) + (i32.const 0) + ) + ) + ) + (drop (get_local $y)) + ) ) |