summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/RemoveUnusedBrs.cpp4
-rw-r--r--test/passes/remove-unused-brs.txt11
-rw-r--r--test/passes/remove-unused-brs.wast11
3 files changed, 25 insertions, 1 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index 9fed3e4a5..8994c7fe2 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -481,7 +481,9 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
// format. We need to flip the condition, which at worst adds 1.
if (curr->name.is()) {
auto* br = list[0]->dynCast<Break>();
- if (br && br->condition && br->name == curr->name) {
+ // we seek a regular br_if; if the type is unreachable that means it is not
+ // actually taken, so ignore
+ if (br && br->condition && br->name == curr->name && br->type != unreachable) {
assert(!br->value); // can't, it would be dropped or last in the block
if (BranchUtils::BranchSeeker::countNamed(curr, curr->name) == 1) {
// no other breaks to that name, so we can do this
diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt
index 355f8a531..fe0c59fca 100644
--- a/test/passes/remove-unused-brs.txt
+++ b/test/passes/remove-unused-brs.txt
@@ -1048,4 +1048,15 @@
)
)
)
+ (func $untaken-br_if-then-if (type $1)
+ (block $label$0
+ (br_if $label$0
+ (unreachable)
+ )
+ (if
+ (i32.const 0)
+ (nop)
+ )
+ )
+ )
)
diff --git a/test/passes/remove-unused-brs.wast b/test/passes/remove-unused-brs.wast
index e7c221fa4..996b05264 100644
--- a/test/passes/remove-unused-brs.wast
+++ b/test/passes/remove-unused-brs.wast
@@ -932,5 +932,16 @@
)
)
)
+ (func $untaken-br_if-then-if
+ (block $label$0
+ (br_if $label$0
+ (unreachable)
+ )
+ (if
+ (i32.const 0)
+ (nop)
+ )
+ )
+ )
)