Skip to content

Commit 93dcb15

Browse files
committed
ignore untaken branches in determining block type
1 parent cfe0fa1 commit 93dcb15

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/wasm/wasm.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,20 @@ struct TypeSeeker : public PostWalker<TypeSeeker> {
109109
Name targetName;
110110
std::vector<WasmType> types;
111111

112+
112113
TypeSeeker(Expression* target, Name targetName) : target(target), targetName(targetName) {
113114
Expression* temp = target;
114115
walk(temp);
115116
}
116117

117118
void visitBreak(Break* curr) {
118-
if (curr->name == targetName) {
119+
if (curr->name == targetName && BranchUtils::isBranchTaken(curr)) {
119120
types.push_back(curr->value ? curr->value->type : none);
120121
}
121122
}
122123

123124
void visitSwitch(Switch* curr) {
125+
if (!BranchUtils::isBranchTaken(curr)) return;
124126
for (auto name : curr->targets) {
125127
if (name == targetName) types.push_back(curr->value ? curr->value->type : none);
126128
}

test/passes/remove-unused-brs.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,4 +1035,17 @@
10351035
)
10361036
)
10371037
)
1038+
(func $untaken-br-with-concrete-last-element (type $2) (result i32)
1039+
(block $label$8 (result i32)
1040+
(block $label$11 (result i32)
1041+
(block $label$14
1042+
(br_if $label$8
1043+
(br $label$11
1044+
(i32.const 103)
1045+
)
1046+
)
1047+
)
1048+
)
1049+
)
1050+
)
10381051
)

test/passes/remove-unused-brs.wast

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,5 +919,18 @@
919919
)
920920
)
921921
)
922+
(func $untaken-br-with-concrete-last-element (result i32)
923+
(block $label$8 (result i32)
924+
(block $label$11 (result i32)
925+
(block $label$14
926+
(br_if $label$14
927+
(br $label$11
928+
(i32.const 103)
929+
)
930+
)
931+
)
932+
)
933+
)
934+
)
922935
)
923936

0 commit comments

Comments
 (0)