Skip to content

[CoroSplit] Always erase lifetime intrinsics for spilled allocas #142551

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 4 commits into from
Jun 3, 2025
Merged
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
21 changes: 9 additions & 12 deletions llvm/lib/Transforms/Coroutines/CoroFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,11 +1215,17 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
for (const auto &A : FrameData.Allocas) {
AllocaInst *Alloca = A.Alloca;
UsersToUpdate.clear();
for (User *U : Alloca->users()) {
for (User *U : make_early_inc_range(Alloca->users())) {
auto *I = cast<Instruction>(U);
if (DT.dominates(Shape.CoroBegin, I))
// It is meaningless to retain the lifetime intrinsics refer for the
// member of coroutine frames and the meaningless lifetime intrinsics
// are possible to block further optimizations.
if (I->isLifetimeStartOrEnd())
I->eraseFromParent();
else if (DT.dominates(Shape.CoroBegin, I))
UsersToUpdate.push_back(I);
}

if (UsersToUpdate.empty())
continue;
auto *G = GetFramePointer(Alloca);
Expand All @@ -1233,17 +1239,8 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
for (auto *DVR : DbgVariableRecords)
DVR->replaceVariableLocationOp(Alloca, G);

for (Instruction *I : UsersToUpdate) {
// It is meaningless to retain the lifetime intrinsics refer for the
// member of coroutine frames and the meaningless lifetime intrinsics
// are possible to block further optimizations.
if (I->isLifetimeStartOrEnd()) {
I->eraseFromParent();
continue;
}

for (Instruction *I : UsersToUpdate)
I->replaceUsesOfWith(Alloca, G);
}
}
Builder.SetInsertPoint(&*Shape.getInsertPtAfterFramePtr());
for (const auto &A : FrameData.Allocas) {
Expand Down
Loading