Skip to content

Commit 485166f

Browse files
committed
fix handling of an if in a tee without an else, in coalesce-locals
1 parent cf6c4cf commit 485166f

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/passes/CoalesceLocals.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ struct CoalesceLocals : public WalkerPass<CFGWalker<CoalesceLocals, Visitor<Coal
196196
if (auto* get = set->value->dynCast<GetLocal>()) return get;
197197
if (auto* iff = set->value->dynCast<If>()) {
198198
if (auto* get = iff->ifTrue->dynCast<GetLocal>()) return get;
199-
if (auto* get = iff->ifFalse->dynCast<GetLocal>()) return get;
199+
if (iff->ifFalse) {
200+
if (auto* get = iff->ifFalse->dynCast<GetLocal>()) return get;
201+
}
200202
}
201203
return nullptr;
202204
}

test/passes/coalesce-locals.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,4 +1112,14 @@
11121112
)
11131113
(i32.const 1)
11141114
)
1115+
(func $unused-tee-with-child-if-no-else (type $4) (param $0 i32)
1116+
(loop $label$0
1117+
(drop
1118+
(if
1119+
(br $label$0)
1120+
(nop)
1121+
)
1122+
)
1123+
)
1124+
)
11151125
)

test/passes/coalesce-locals.wast

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,4 +1085,16 @@
10851085
)
10861086
(i32.const 1)
10871087
)
1088+
(func $unused-tee-with-child-if-no-else (param $0 i32)
1089+
(loop $label$0
1090+
(drop
1091+
(tee_local $0
1092+
(if
1093+
(br $label$0)
1094+
(nop)
1095+
)
1096+
)
1097+
)
1098+
)
1099+
)
10881100
)

0 commit comments

Comments
 (0)