https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/147448
Backport 038dc2c63b2db744be6afeea74b18be4938149e9 Requested by: @ChuanqiXu9 >From 13f1e8e095bfbe59ce537a911e6fe95d940961ba Mon Sep 17 00:00:00 2001 From: Weibo He <newsi...@163.com> Date: Tue, 3 Jun 2025 18:52:41 +0800 Subject: [PATCH] [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 <yedeng...@linux.alibaba.com> (cherry picked from commit 038dc2c63b2db744be6afeea74b18be4938149e9) --- llvm/lib/Transforms/Coroutines/CoroFrame.cpp | 21 +++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp index 68edabb083be3..35832b594e9a3 100644 --- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -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. + if (I->isLifetimeStartOrEnd()) + I->eraseFromParent(); + else if (DT.dominates(Shape.CoroBegin, I)) UsersToUpdate.push_back(I); } + if (UsersToUpdate.empty()) continue; auto *G = GetFramePointer(Alloca); @@ -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) { _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits