[llvm] [NFC][LICM] Hoist `isPotentiallyPromotable` to reusable function (PR #222684)
Zach Goldthorpe via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 11 07:07:34 PDT 2026
https://github.com/zGoldthorpe updated https://github.com/llvm/llvm-project/pull/222684
>From 77df249f79fcdf229fc1d01469fe73e4227f58f0 Mon Sep 17 00:00:00 2001
From: Zach Goldthorpe <Zach.Goldthorpe at amd.com>
Date: Wed, 9 Sep 2026 09:38:52 -0500
Subject: [PATCH] [NFC][LICM] Hoist `isPotentiallyPromotable` to reusable
function
---
llvm/lib/Transforms/Scalar/LICM.cpp | 36 +++++++++++++++--------------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 8a5210e75d41a..112524fe992ed 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -2328,6 +2328,24 @@ static void foreachMemoryAccess(MemorySSA *MSSA, Loop *L,
Fn(MUD->getMemoryInst());
}
+/// Returns whether \p I is a memory access that may be a candidate for
+/// promotion out of the loop \p L.
+static bool isPotentiallyPromotable(const Instruction *I, const Loop *L) {
+ if (const auto *SI = dyn_cast<StoreInst>(I)) {
+ const Value *PtrOp = SI->getPointerOperand();
+ if (isStrongerThanMonotonic(SI->getOrdering()))
+ return false;
+ return !isa<ConstantData>(PtrOp) && L->isLoopInvariant(PtrOp);
+ }
+ if (const auto *LI = dyn_cast<LoadInst>(I)) {
+ const Value *PtrOp = LI->getPointerOperand();
+ if (isStrongerThanMonotonic(LI->getOrdering()))
+ return false;
+ return !isa<ConstantData>(PtrOp) && L->isLoopInvariant(PtrOp);
+ }
+ return false;
+}
+
// The bool indicates whether there might be reads outside the set, in which
// case only loads may be promoted.
static SmallVector<PointersAndHasReadsOutsideSet, 0>
@@ -2337,26 +2355,10 @@ collectPromotionCandidates(MemorySSA *MSSA, AliasAnalysis *AA,
BatchAAResults BatchAA(*AA);
AliasSetTracker AST(BatchAA);
- auto IsPotentiallyPromotable = [L](const Instruction *I) {
- if (const auto *SI = dyn_cast<StoreInst>(I)) {
- const Value *PtrOp = SI->getPointerOperand();
- if (isStrongerThanMonotonic(SI->getOrdering()))
- return false;
- return !isa<ConstantData>(PtrOp) && L->isLoopInvariant(PtrOp);
- }
- if (const auto *LI = dyn_cast<LoadInst>(I)) {
- const Value *PtrOp = LI->getPointerOperand();
- if (isStrongerThanMonotonic(LI->getOrdering()))
- return false;
- return !isa<ConstantData>(PtrOp) && L->isLoopInvariant(PtrOp);
- }
- return false;
- };
-
// Populate AST with potentially promotable accesses.
SmallPtrSet<Value *, 16> AttemptingPromotion;
foreachMemoryAccess(MSSA, L, [&](Instruction *I) {
- if (IsPotentiallyPromotable(I)) {
+ if (isPotentiallyPromotable(I, L)) {
AttemptingPromotion.insert(I);
if (StoreInst *SI = dyn_cast<StoreInst>(I);
SI && !SafetyInfo->isGuaranteedToExecute(*SI, DT)) {
More information about the llvm-commits
mailing list