Skip to content

Commit fe61868

Browse files
committed
quickly avoid all unreachable branching in ifs
1 parent e88e1f1 commit fe61868

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

src/passes/RemoveUnusedBrs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
173173
auto* iff = (*currp)->dynCast<If>();
174174

175175
if (iff) {
176+
if (iff->condition->type == unreachable) {
177+
// avoid all the branching, we never reach it anyhow
178+
*currp = iff->condition;
179+
return;
180+
}
176181
self->pushTask(doVisitIf, currp);
177182
if (iff->ifFalse) {
178183
// we need to join up if-else control flow, and clear after the condition

test/passes/remove-unused-brs.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,12 +1062,13 @@
10621062
)
10631063
(func $unreachable-if-that-could-be-a-br_if (type $7) (result i64)
10641064
(loop $label$3
1065-
(if
1066-
(unreachable)
1067-
(f64.const 1)
1068-
(br $label$3)
1069-
)
1065+
(unreachable)
10701066
(i64.const 1)
10711067
)
10721068
)
1069+
(func $nop-br-might-update-type (type $1)
1070+
(block $label$39
1071+
(unreachable)
1072+
)
1073+
)
10731074
)

test/passes/remove-unused-brs.wast

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,5 +953,18 @@
953953
(i64.const 1)
954954
)
955955
)
956+
(func $nop-br-might-update-type
957+
(block $label$39
958+
(if
959+
(unreachable)
960+
(if (result i32)
961+
(i32.const 1)
962+
(br $label$39) ;; if we nop this, then the parent type must change
963+
(i32.const 0)
964+
)
965+
(i32.const 0)
966+
)
967+
)
968+
)
956969
)
957970

0 commit comments

Comments
 (0)