Skip to content

Commit 6159fb4

Browse files
committed
fix handling of unreachable br values in merge-blocks
1 parent e5ebae7 commit 6159fb4

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/passes/MergeBlocks.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ struct BreakValueDropper : public ControlFlowWalker<BreakValueDropper> {
122122
if (curr->value && curr->name == origin) {
123123
Builder builder(*getModule());
124124
auto* value = curr->value;
125+
if (value->type == unreachable) {
126+
// the break isn't even reached
127+
replaceCurrent(value);
128+
return;
129+
}
125130
curr->value = nullptr;
126131
curr->finalize();
127132
replaceCurrent(builder.makeSequence(builder.makeDrop(value), curr));
@@ -130,7 +135,8 @@ struct BreakValueDropper : public ControlFlowWalker<BreakValueDropper> {
130135

131136
void visitDrop(Drop* curr) {
132137
// if we dropped a br_if whose value we removed, then we are now dropping a (block (drop value) (br_if)) with type none, which does not need a drop
133-
if (curr->value->type == none) {
138+
// likewise, unreachable does not need to be dropped, so we just leave drops of concrete values
139+
if (!isConcreteWasmType(curr->value->type)) {
134140
replaceCurrent(curr->value);
135141
}
136142
}

test/passes/merge-blocks.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(module
22
(type $0 (func))
33
(type $1 (func (param i32)))
4+
(type $2 (func (result i32)))
45
(memory $0 0)
56
(func $drop-block (type $0)
67
(block $block
@@ -75,4 +76,15 @@
7576
)
7677
)
7778
)
79+
(func $drop-unreachable-br_if (type $2) (result i32)
80+
(block $label$0 (result i32)
81+
(block $label$2
82+
(drop
83+
(br $label$0
84+
(i32.const 538976371)
85+
)
86+
)
87+
)
88+
)
89+
)
7890
)

test/passes/merge-blocks.wast

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,21 @@
5353
)
5454
)
5555
)
56+
(func $drop-unreachable-br_if (result i32)
57+
(block $label$0 (result i32)
58+
(drop
59+
(block $label$2
60+
(drop
61+
(br_if $label$2
62+
(br $label$0
63+
(i32.const 538976371)
64+
)
65+
(i32.const 1918987552)
66+
)
67+
)
68+
)
69+
)
70+
)
71+
)
5672
)
5773

0 commit comments

Comments
 (0)