Skip to content

Fix coro lowering of single predecessor phis #2774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions llvm/lib/Transforms/Coroutines/CoroFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,24 @@ static void rewritePHIsForCleanupPad(BasicBlock *CleanupPadBB,
}
}

static void cleanupSinglePredPHIs(Function &F) {
SmallVector<PHINode *, 32> Worklist;
for (auto &BB : F) {
for (auto &Phi : BB.phis()) {
if (Phi.getNumIncomingValues() == 1) {
Worklist.push_back(&Phi);
} else
break;
}
}
while (!Worklist.empty()) {
auto *Phi = Worklist.back();
Worklist.pop_back();
auto copy = Phi->getIncomingValue(0);
Phi->replaceAllUsesWith(copy);
}
}

static void rewritePHIs(BasicBlock &BB) {
// For every incoming edge we will create a block holding all
// incoming values in a single PHI nodes.
Expand Down Expand Up @@ -2269,6 +2287,10 @@ void coro::buildCoroutineFrame(Function &F, Shape &Shape) {
}
}

// Later code makes structural assumptions about single predecessors phis e.g
// that they are not live accross a suspend point.
cleanupSinglePredPHIs(F);

// Transforms multi-edge PHI Nodes, so that any value feeding into a PHI will
// never has its definition separated from the PHI by the suspend point.
rewritePHIs(F);
Expand Down
Loading