Skip to content

Commit 26b2f33

Browse files
committed
handle an unreachable condition properly in vacuum if simplification
1 parent 485166f commit 26b2f33

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/passes/Vacuum.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum>> {
232232
replaceCurrent(child);
233233
return;
234234
}
235+
// if the condition is unreachable, just return it
236+
if (curr->condition->type == unreachable) {
237+
replaceCurrent(curr->condition);
238+
return;
239+
}
240+
// from here on, we can assume the condition executed
235241
if (curr->ifFalse) {
236242
if (curr->ifFalse->is<Nop>()) {
237243
curr->ifFalse = nullptr;

test/passes/vacuum.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,18 @@
273273
)
274274
)
275275
)
276+
(func $unreachable-if-with-nop-arm-that-leaves-a-concrete-value-if-nop-is-removed (type $0)
277+
(block $label$0
278+
(loop $label$1
279+
(br_if $label$0
280+
(i32.load8_s
281+
(i32.const 1634541608)
282+
)
283+
(loop $label$9
284+
(br $label$9)
285+
)
286+
)
287+
)
288+
)
289+
)
276290
)

test/passes/vacuum.wast

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,4 +593,22 @@
593593
)
594594
)
595595
)
596+
(func $unreachable-if-with-nop-arm-that-leaves-a-concrete-value-if-nop-is-removed
597+
(block $label$0
598+
(loop $label$1
599+
(if
600+
(br_if $label$0
601+
(i32.load8_s
602+
(i32.const 1634541608)
603+
)
604+
(loop $label$9
605+
(br $label$9)
606+
)
607+
)
608+
(nop)
609+
(i32.const 1920103026)
610+
)
611+
)
612+
)
613+
)
596614
)

0 commit comments

Comments
 (0)