[llvm] [LAA] strip dead code, simplify logic (NFC) (PR #92119)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Tue May 14 06:57:14 PDT 2024
https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/92119
733b8b2 ([LAA] Simplify identification of speculatable strides [nfc]) refactored getStrideFromPointer() to compute directly on SCEVs, and return an SCEV expression instead of a Value. However, it left behind a call to getUniqueCastUse(), which is completely unnecessary. Remove this dead code, and simplify the surrounding program logic.
>From 6da7d4c01c2f11683eaf662c507186d641d04ea5 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <r at artagnon.com>
Date: Tue, 14 May 2024 13:19:34 +0100
Subject: [PATCH] [LAA] strip dead code, simplify logic (NFC)
733b8b2 ([LAA] Simplify identification of speculatable strides [nfc])
refactored getStrideFromPointer() to compute directly on SCEVs, and
return an SCEV expression instead of a Value. However, it left behind a
call to getUniqueCastUse(), which is completely unnecessary. Remove this
dead code, and simplify the surrounding program logic.
---
llvm/lib/Analysis/LoopAccessAnalysis.cpp | 36 +++++-------------------
1 file changed, 7 insertions(+), 29 deletions(-)
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index d071e53324408..2574da76e747b 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2656,7 +2656,7 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
SymbolicStrides, UncomputablePtr, false);
if (!CanDoRTIfNeeded) {
auto *I = dyn_cast_or_null<Instruction>(UncomputablePtr);
- recordAnalysis("CantIdentifyArrayBounds", I)
+ recordAnalysis("CantIdentifyArrayBounds", I)
<< "cannot identify array bounds";
LLVM_DEBUG(dbgs() << "LAA: We can't vectorize because we can't find "
<< "the array bounds.\n");
@@ -2873,21 +2873,6 @@ static Value *stripGetElementPtr(Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
return GEP->getOperand(InductionOperand);
}
-/// If a value has only one user that is a CastInst, return it.
-static Value *getUniqueCastUse(Value *Ptr, Loop *Lp, Type *Ty) {
- Value *UniqueCast = nullptr;
- for (User *U : Ptr->users()) {
- CastInst *CI = dyn_cast<CastInst>(U);
- if (CI && CI->getType() == Ty) {
- if (!UniqueCast)
- UniqueCast = CI;
- else
- return nullptr;
- }
- }
- return UniqueCast;
-}
-
/// Get the stride of a pointer access in a loop. Looks for symbolic
/// strides "a[i*stride]". Returns the symbolic stride, or null otherwise.
static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
@@ -2950,21 +2935,14 @@ static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *L
return nullptr;
// Look for the loop invariant symbolic value.
- const SCEVUnknown *U = dyn_cast<SCEVUnknown>(V);
- if (!U) {
- const auto *C = dyn_cast<SCEVIntegralCastExpr>(V);
- if (!C)
- return nullptr;
- U = dyn_cast<SCEVUnknown>(C->getOperand());
- if (!U)
- return nullptr;
+ if (isa<SCEVUnknown>(V))
+ return V;
- // Match legacy behavior - this is not needed for correctness
- if (!getUniqueCastUse(U->getValue(), Lp, V->getType()))
- return nullptr;
- }
+ if (const auto *C = dyn_cast<SCEVIntegralCastExpr>(V))
+ if (isa<SCEVUnknown>(C->getOperand()))
+ return V;
- return V;
+ return nullptr;
}
void LoopAccessInfo::collectStridedAccess(Value *MemAccess) {
More information about the llvm-commits
mailing list