[llvm] [LoopUnroll] Remove unused lifetime marker pairs (PR #106858)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 31 08:57:48 PDT 2024
https://github.com/dtcxzyw created https://github.com/llvm/llvm-project/pull/106858
None
>From f12d7f3efd2bd699880425e094cf07b414228c5e Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Sat, 31 Aug 2024 23:57:14 +0800
Subject: [PATCH] [LoopUnroll] Remove unused lifetime marker pairs
---
llvm/lib/Transforms/Utils/LoopUnroll.cpp | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
index a0406111ecbf3b..9e601215db55fa 100644
--- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -375,7 +375,11 @@ void llvm::simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI,
// At this point, the code is well formed. Perform constprop, instsimplify,
// and dce.
const DataLayout &DL = L->getHeader()->getDataLayout();
+ Function *F = L->getHeader()->getParent();
SmallVector<WeakTrackingVH, 16> DeadInsts;
+ bool DoNotOptimizeLifetimeMarkers = F->hasFnAttribute(Attribute::SanitizeAddress) ||
+ F->hasFnAttribute(Attribute::SanitizeMemory) ||
+ F->hasFnAttribute(Attribute::SanitizeHWAddress);
for (BasicBlock *BB : L->getBlocks()) {
// Remove repeated debug instructions after loop unrolling.
if (BB->getParent()->getSubprogram())
@@ -387,6 +391,20 @@ void llvm::simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI,
Inst.replaceAllUsesWith(V);
if (isInstructionTriviallyDead(&Inst))
DeadInsts.emplace_back(&Inst);
+ if (!DoNotOptimizeLifetimeMarkers)
+ if (auto *II = dyn_cast<IntrinsicInst>(&Inst)) {
+ if (II->getIntrinsicID() == Intrinsic::lifetime_start) {
+ if (auto *PrevII = dyn_cast_or_null<IntrinsicInst>(II->getPrevNode()))
+ if (PrevII->getIntrinsicID() == Intrinsic::lifetime_end) {
+ if (PrevII->getArgOperand(0) == II->getArgOperand(0) &&
+ PrevII->getArgOperand(1) == II->getArgOperand(1)) {
+ PrevII->eraseFromParent();
+ II->eraseFromParent();
+ continue;
+ }
+ }
+ }
+ }
// Fold ((add X, C1), C2) to (add X, C1+C2). This is very common in
// unrolled loops, and handling this early allows following code to
More information about the llvm-commits
mailing list