Skip to content

release/20.x: [CoroSplit] Always erase lifetime intrinsics for spilled allocas (#142551) #147448

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

Open
wants to merge 1 commit into
base: release/20.x
Choose a base branch
from
Open
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 @@ -1213,11 +1213,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.
Comment on lines +1218 to +1220
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have trouble parsing this comment. It says it's "meaningless to retain the lifetime intrinsics" and that they may block further optimization, but isn't the point of #124612 that spilling allocas to the coro frame changes the lifetime of the allocas, so that the old lifetime intrinsics are incorrect, and should therefore be removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the point is, the lifetime intrinsics are for allocas. And when we move them into the frame, the original lifetime intrinsics are naturally meaningless. To me, I feel it is meaningless to talk about whether or not the undefined intrinsics are correct or not.

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 @@ -1231,17 +1237,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