summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-08-25 11:33:12 -0700
committerAlon Zakai <alonzakai@gmail.com>2017-08-25 16:04:36 -0700
commitddfa483430c35ce81f05a6497cc68536b594c2b3 (patch)
treecd01ab61d1bb180a052e3af59acbfeeb89604af3
parentfe618683f2c8762f8817c7a573095a21751b2ed2 (diff)
downloadbinaryen-ddfa483430c35ce81f05a6497cc68536b594c2b3.tar.gz
binaryen-ddfa483430c35ce81f05a6497cc68536b594c2b3.tar.bz2
binaryen-ddfa483430c35ce81f05a6497cc68536b594c2b3.zip
avoid trying to optimize ifs with unreachable conditions in remove-unused-brs, as they are dead code anyhow, and it is pointless to work hard to handle the type changes
-rw-r--r--src/passes/RemoveUnusedBrs.cpp7
-rw-r--r--test/passes/remove-unused-brs.txt16
2 files changed, 19 insertions, 4 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index d2b7c944f..a3ef15639 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -82,6 +82,10 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
self->valueCanFlow = true; // start optimistic
} else if (curr->is<If>()) {
auto* iff = curr->cast<If>();
+ if (iff->condition->type == unreachable) {
+ // avoid trying to optimize this, we never reach it anyhow
+ return;
+ }
if (iff->ifFalse) {
assert(self->ifStack.size() > 0);
for (auto* flow : self->ifStack.back()) {
@@ -174,8 +178,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
if (iff) {
if (iff->condition->type == unreachable) {
- // avoid all the branching, we never reach it anyhow
- *currp = iff->condition;
+ // avoid trying to optimize this, we never reach it anyhow
return;
}
self->pushTask(doVisitIf, currp);
diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt
index 599459c57..c4c2710d3 100644
--- a/test/passes/remove-unused-brs.txt
+++ b/test/passes/remove-unused-brs.txt
@@ -1062,13 +1062,25 @@
)
(func $unreachable-if-that-could-be-a-br_if (type $7) (result i64)
(loop $label$3
- (unreachable)
+ (if
+ (unreachable)
+ (f64.const 1)
+ (br $label$3)
+ )
(i64.const 1)
)
)
(func $nop-br-might-update-type (type $1)
(block $label$39
- (unreachable)
+ (if
+ (unreachable)
+ (if (result i32)
+ (i32.const 1)
+ (br $label$39)
+ (i32.const 0)
+ )
+ (i32.const 0)
+ )
)
)
)