summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/RemoveUnusedBrs.cpp5
-rw-r--r--test/passes/remove-unused-brs.txt11
-rw-r--r--test/passes/remove-unused-brs.wast13
3 files changed, 24 insertions, 5 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index f0db1eee6..d2b7c944f 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -173,6 +173,11 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
auto* iff = (*currp)->dynCast<If>();
if (iff) {
+ if (iff->condition->type == unreachable) {
+ // avoid all the branching, we never reach it anyhow
+ *currp = iff->condition;
+ return;
+ }
self->pushTask(doVisitIf, currp);
if (iff->ifFalse) {
// we need to join up if-else control flow, and clear after the condition
diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt
index 5cc900abd..599459c57 100644
--- a/test/passes/remove-unused-brs.txt
+++ b/test/passes/remove-unused-brs.txt
@@ -1062,12 +1062,13 @@
)
(func $unreachable-if-that-could-be-a-br_if (type $7) (result i64)
(loop $label$3
- (if
- (unreachable)
- (f64.const 1)
- (br $label$3)
- )
+ (unreachable)
(i64.const 1)
)
)
+ (func $nop-br-might-update-type (type $1)
+ (block $label$39
+ (unreachable)
+ )
+ )
)
diff --git a/test/passes/remove-unused-brs.wast b/test/passes/remove-unused-brs.wast
index ecf70b758..32c4ece6a 100644
--- a/test/passes/remove-unused-brs.wast
+++ b/test/passes/remove-unused-brs.wast
@@ -953,5 +953,18 @@
(i64.const 1)
)
)
+ (func $nop-br-might-update-type
+ (block $label$39
+ (if
+ (unreachable)
+ (if (result i32)
+ (i32.const 1)
+ (br $label$39) ;; if we nop this, then the parent type must change
+ (i32.const 0)
+ )
+ (i32.const 0)
+ )
+ )
+ )
)