Skip to content

Commit 13f1e8e

Browse files
NewSigmaChuanqiXu9
authored andcommitted
[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]> (cherry picked from commit 038dc2c)
1 parent 0de59a2 commit 13f1e8e

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
@@ -1213,11 +1213,17 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
12131213
for (const auto &A : FrameData.Allocas) {
12141214
AllocaInst *Alloca = A.Alloca;
12151215
UsersToUpdate.clear();
1216-
for (User *U : Alloca->users()) {
1216+
for (User *U : make_early_inc_range(Alloca->users())) {
12171217
auto *I = cast<Instruction>(U);
1218-
if (DT.dominates(Shape.CoroBegin, I))
1218+
// It is meaningless to retain the lifetime intrinsics refer for the
1219+
// member of coroutine frames and the meaningless lifetime intrinsics
1220+
// are possible to block further optimizations.
1221+
if (I->isLifetimeStartOrEnd())
1222+
I->eraseFromParent();
1223+
else if (DT.dominates(Shape.CoroBegin, I))
12191224
UsersToUpdate.push_back(I);
12201225
}
1226+
12211227
if (UsersToUpdate.empty())
12221228
continue;
12231229
auto *G = GetFramePointer(Alloca);
@@ -1231,17 +1237,8 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
12311237
for (auto *DVR : DbgVariableRecords)
12321238
DVR->replaceVariableLocationOp(Alloca, G);
12331239

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

0 commit comments

Comments
 (0)