summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai (kripken) <alonzakai@gmail.com>2017-07-11 18:55:13 -0700
committerAlon Zakai (kripken) <alonzakai@gmail.com>2017-07-13 11:54:03 -0700
commit26b2f331a210bf6de22816e2564516a9f59178d0 (patch)
tree010fea245aea7b09f86c398d1e47cc0d55aa4f2f
parent485166f4a184543fda936b8c458f0f4b74c0368f (diff)
downloadbinaryen-26b2f331a210bf6de22816e2564516a9f59178d0.tar.gz
binaryen-26b2f331a210bf6de22816e2564516a9f59178d0.tar.bz2
binaryen-26b2f331a210bf6de22816e2564516a9f59178d0.zip
handle an unreachable condition properly in vacuum if simplification
-rw-r--r--src/passes/Vacuum.cpp6
-rw-r--r--test/passes/vacuum.txt14
-rw-r--r--test/passes/vacuum.wast18
3 files changed, 38 insertions, 0 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp
index 40f4a6e59..0178a794d 100644
--- a/src/passes/Vacuum.cpp
+++ b/src/passes/Vacuum.cpp
@@ -232,6 +232,12 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum>> {
replaceCurrent(child);
return;
}
+ // if the condition is unreachable, just return it
+ if (curr->condition->type == unreachable) {
+ replaceCurrent(curr->condition);
+ return;
+ }
+ // from here on, we can assume the condition executed
if (curr->ifFalse) {
if (curr->ifFalse->is<Nop>()) {
curr->ifFalse = nullptr;
diff --git a/test/passes/vacuum.txt b/test/passes/vacuum.txt
index e07357296..7cee4edf1 100644
--- a/test/passes/vacuum.txt
+++ b/test/passes/vacuum.txt
@@ -273,4 +273,18 @@
)
)
)
+ (func $unreachable-if-with-nop-arm-that-leaves-a-concrete-value-if-nop-is-removed (type $0)
+ (block $label$0
+ (loop $label$1
+ (br_if $label$0
+ (i32.load8_s
+ (i32.const 1634541608)
+ )
+ (loop $label$9
+ (br $label$9)
+ )
+ )
+ )
+ )
+ )
)
diff --git a/test/passes/vacuum.wast b/test/passes/vacuum.wast
index 77ffabd60..1885da09b 100644
--- a/test/passes/vacuum.wast
+++ b/test/passes/vacuum.wast
@@ -593,4 +593,22 @@
)
)
)
+ (func $unreachable-if-with-nop-arm-that-leaves-a-concrete-value-if-nop-is-removed
+ (block $label$0
+ (loop $label$1
+ (if
+ (br_if $label$0
+ (i32.load8_s
+ (i32.const 1634541608)
+ )
+ (loop $label$9
+ (br $label$9)
+ )
+ )
+ (nop)
+ (i32.const 1920103026)
+ )
+ )
+ )
+ )
)