diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-08-23 11:39:58 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-07 09:55:06 -0700 |
commit | 14fe75e4d6e670d2e7f3e171d3d96c340b574eab (patch) | |
tree | 26e4122a719e557c48a5d7d7f4de52bdc86054af | |
parent | 1d3f3dda67c24c148dce13734c21cdab487ddc87 (diff) | |
download | binaryen-14fe75e4d6e670d2e7f3e171d3d96c340b574eab.tar.gz binaryen-14fe75e4d6e670d2e7f3e171d3d96c340b574eab.tar.bz2 binaryen-14fe75e4d6e670d2e7f3e171d3d96c340b574eab.zip |
when replacing an if with its condition (when it has no body), we must drop it
-rw-r--r-- | src/passes/Vacuum.cpp | 2 | ||||
-rw-r--r-- | test/unit.asm.js | 11 | ||||
-rw-r--r-- | test/unit.fromasm | 12 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise | 12 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise.no-opts | 21 | ||||
-rw-r--r-- | test/unit.fromasm.no-opts | 21 |
6 files changed, 78 insertions, 1 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 150593713..89ef7359e 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -190,7 +190,7 @@ struct Vacuum : public WalkerPass<ExpressionStackWalker<Vacuum, Visitor<Vacuum>> // no else if (curr->ifTrue->is<Nop>()) { // no nothing - replaceCurrent(curr->condition); + replaceCurrent(Builder(*getModule()).makeDrop(curr->condition)); } } } diff --git a/test/unit.asm.js b/test/unit.asm.js index b4c10b1d2..8f0812e29 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -308,6 +308,17 @@ function asm(global, env, buffer) { } while(0); } + function ifChainEmpty(label) { + label = label | 0; + if ((label|0) == 4) { + return 0; + } + else if ((label|0) == 7) { + // unreachable; + } + return 0; + } + function z() { } function w() { diff --git a/test/unit.fromasm b/test/unit.fromasm index cecbeef22..bc5281ed5 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -558,4 +558,16 @@ ) ) ) + (func $ifChainEmpty (param $0 i32) (result i32) + (if + (i32.eq + (get_local $0) + (i32.const 4) + ) + (return + (i32.const 0) + ) + ) + (i32.const 0) + ) ) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index ba1af7916..945d6cc8e 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -540,4 +540,16 @@ ) ) ) + (func $ifChainEmpty (param $0 i32) (result i32) + (if + (i32.eq + (get_local $0) + (i32.const 4) + ) + (return + (i32.const 0) + ) + ) + (i32.const 0) + ) ) diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index 0c02680da..f06912d08 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -932,6 +932,27 @@ (nop) ) ) + (func $ifChainEmpty (param $label i32) (result i32) + (if + (i32.eq + (get_local $label) + (i32.const 4) + ) + (return + (i32.const 0) + ) + (if + (i32.eq + (get_local $label) + (i32.const 7) + ) + (nop) + ) + ) + (return + (i32.const 0) + ) + ) (func $z (nop) ) diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index fbbc6e7ff..222e0fa65 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -938,6 +938,27 @@ (nop) ) ) + (func $ifChainEmpty (param $label i32) (result i32) + (if + (i32.eq + (get_local $label) + (i32.const 4) + ) + (return + (i32.const 0) + ) + (if + (i32.eq + (get_local $label) + (i32.const 7) + ) + (nop) + ) + ) + (return + (i32.const 0) + ) + ) (func $z (nop) ) |