Skip to content

Commit cc193a4

Browse files
committed
don't turn untaken br_ifs into ifs in remove-unused-brs
1 parent 077c531 commit cc193a4

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/passes/RemoveUnusedBrs.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
481481
// format. We need to flip the condition, which at worst adds 1.
482482
if (curr->name.is()) {
483483
auto* br = list[0]->dynCast<Break>();
484-
if (br && br->condition && br->name == curr->name) {
484+
// we seek a regular br_if; if the type is unreachable that means it is not
485+
// actually taken, so ignore
486+
if (br && br->condition && br->name == curr->name && br->type != unreachable) {
485487
assert(!br->value); // can't, it would be dropped or last in the block
486488
if (BranchUtils::BranchSeeker::countNamed(curr, curr->name) == 1) {
487489
// no other breaks to that name, so we can do this

test/passes/remove-unused-brs.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,4 +1048,15 @@
10481048
)
10491049
)
10501050
)
1051+
(func $untaken-br_if-then-if (type $1)
1052+
(block $label$0
1053+
(br_if $label$0
1054+
(unreachable)
1055+
)
1056+
(if
1057+
(i32.const 0)
1058+
(nop)
1059+
)
1060+
)
1061+
)
10511062
)

test/passes/remove-unused-brs.wast

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,5 +932,16 @@
932932
)
933933
)
934934
)
935+
(func $untaken-br_if-then-if
936+
(block $label$0
937+
(br_if $label$0
938+
(unreachable)
939+
)
940+
(if
941+
(i32.const 0)
942+
(nop)
943+
)
944+
)
945+
)
935946
)
936947

0 commit comments

Comments
 (0)