Skip to content

Commit 038dc2c

Browse files
NewSigmaChuanqiXu9
andauthored
[CoroSplit] Always erase lifetime intrinsics for spilled allocas (#142551)
If the control flow between `lifetime.start` and `lifetime.end` is too complex, it is acceptable to give up the optimization opportunity and collect the alloca to the frame. However, storing to the frame will lengthen the lifetime of the alloca, and the sanitizer will complain. I propose we always erase lifetime intrinsics of spilled allocas. Fix #124612 --------- Co-authored-by: Chuanqi Xu <[email protected]>
1 parent 020ab69 commit 038dc2c

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,11 +1215,17 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
12151215
for (const auto &A : FrameData.Allocas) {
12161216
AllocaInst *Alloca = A.Alloca;
12171217
UsersToUpdate.clear();
1218-
for (User *U : Alloca->users()) {
1218+
for (User *U : make_early_inc_range(Alloca->users())) {
12191219
auto *I = cast<Instruction>(U);
1220-
if (DT.dominates(Shape.CoroBegin, I))
1220+
// It is meaningless to retain the lifetime intrinsics refer for the
1221+
// member of coroutine frames and the meaningless lifetime intrinsics
1222+
// are possible to block further optimizations.
1223+
if (I->isLifetimeStartOrEnd())
1224+
I->eraseFromParent();
1225+
else if (DT.dominates(Shape.CoroBegin, I))
12211226
UsersToUpdate.push_back(I);
12221227
}
1228+
12231229
if (UsersToUpdate.empty())
12241230
continue;
12251231
auto *G = GetFramePointer(Alloca);
@@ -1233,17 +1239,8 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
12331239
for (auto *DVR : DbgVariableRecords)
12341240
DVR->replaceVariableLocationOp(Alloca, G);
12351241

1236-
for (Instruction *I : UsersToUpdate) {
1237-
// It is meaningless to retain the lifetime intrinsics refer for the
1238-
// member of coroutine frames and the meaningless lifetime intrinsics
1239-
// are possible to block further optimizations.
1240-
if (I->isLifetimeStartOrEnd()) {
1241-
I->eraseFromParent();
1242-
continue;
1243-
}
1244-
1242+
for (Instruction *I : UsersToUpdate)
12451243
I->replaceUsesOfWith(Alloca, G);
1246-
}
12471244
}
12481245
Builder.SetInsertPoint(&*Shape.getInsertPtAfterFramePtr());
12491246
for (const auto &A : FrameData.Allocas) {

0 commit comments

Comments
 (0)