Skip to content

Commit 9a42d09

Browse files
Merge pull request #2774 from apple/rdar_76020301
Fix coro lowering of single predecessor phis
2 parents d4b9446 + 01db4ba commit 9a42d09

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)