Skip to content

Commit 01db4ba

Browse files
committed
Fix coro lowering of single predecessor phis
Code assumes that uses of single predecessor phis are not live accross suspend points. Cleanup any single predecessor phis preceeding the code making this assumption. rdar://76020301
1 parent d4b9446 commit 01db4ba

File tree

2 files changed

+442
-0
lines changed

2 files changed

+442
-0
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,24 @@ static void rewritePHIsForCleanupPad(BasicBlock *CleanupPadBB,
14801480
}
14811481
}
14821482

1483+
static void cleanupSinglePredPHIs(Function &F) {
1484+
SmallVector<PHINode *, 32> Worklist;
1485+
for (auto &BB : F) {
1486+
for (auto &Phi : BB.phis()) {
1487+
if (Phi.getNumIncomingValues() == 1) {
1488+
Worklist.push_back(&Phi);
1489+
} else
1490+
break;
1491+
}
1492+
}
1493+
while (!Worklist.empty()) {
1494+
auto *Phi = Worklist.back();
1495+
Worklist.pop_back();
1496+
auto copy = Phi->getIncomingValue(0);
1497+
Phi->replaceAllUsesWith(copy);
1498+
}
1499+
}
1500+
14831501
static void rewritePHIs(BasicBlock &BB) {
14841502
// For every incoming edge we will create a block holding all
14851503
// incoming values in a single PHI nodes.
@@ -2269,6 +2287,10 @@ void coro::buildCoroutineFrame(Function &F, Shape &Shape) {
22692287
}
22702288
}
22712289

2290+
// Later code makes structural assumptions about single predecessors phis e.g
2291+
// that they are not live accross a suspend point.
2292+
cleanupSinglePredPHIs(F);
2293+
22722294
// Transforms multi-edge PHI Nodes, so that any value feeding into a PHI will
22732295
// never has its definition separated from the PHI by the suspend point.
22742296
rewritePHIs(F);

0 commit comments

Comments
 (0)