[llvm] 7444ccd - LAA: improve code in getStrideFromPointer (NFC) (#124780)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 31 12:06:28 PST 2025
Author: Ramkumar Ramachandra
Date: 2025-01-31T20:06:25Z
New Revision: 7444ccdd26ae5f7de828f50820a80b6b4014c9fa
URL: https://github.com/llvm/llvm-project/commit/7444ccdd26ae5f7de828f50820a80b6b4014c9fa
DIFF: https://github.com/llvm/llvm-project/commit/7444ccdd26ae5f7de828f50820a80b6b4014c9fa.diff
LOG: LAA: improve code in getStrideFromPointer (NFC) (#124780)
Strip dead code, inline a constant, and modernize style.
Added:
Modified:
llvm/lib/Analysis/LoopAccessAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 697b40403902cc..ac8a35fbc54fb1 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2859,7 +2859,7 @@ static Value *stripGetElementPtr(Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
/// strides "a[i*stride]". Returns the symbolic stride, or null otherwise.
static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
auto *PtrTy = dyn_cast<PointerType>(Ptr->getType());
- if (!PtrTy || PtrTy->isAggregateType())
+ if (!PtrTy)
return nullptr;
// Try to remove a gep instruction to make the pointer (actually index at this
@@ -2867,18 +2867,15 @@ static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *L
// pointer, otherwise, we are analyzing the index.
Value *OrigPtr = Ptr;
- // The size of the pointer access.
- int64_t PtrAccessSize = 1;
-
Ptr = stripGetElementPtr(Ptr, SE, Lp);
const SCEV *V = SE->getSCEV(Ptr);
if (Ptr != OrigPtr)
// Strip off casts.
- while (const SCEVIntegralCastExpr *C = dyn_cast<SCEVIntegralCastExpr>(V))
+ while (auto *C = dyn_cast<SCEVIntegralCastExpr>(V))
V = C->getOperand();
- const SCEVAddRecExpr *S = dyn_cast<SCEVAddRecExpr>(V);
+ auto *S = dyn_cast<SCEVAddRecExpr>(V);
if (!S)
return nullptr;
@@ -2888,25 +2885,20 @@ static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *L
return nullptr;
V = S->getStepRecurrence(*SE);
- if (!V)
- return nullptr;
// Strip off the size of access multiplication if we are still analyzing the
// pointer.
if (OrigPtr == Ptr) {
- if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(V)) {
- if (M->getOperand(0)->getSCEVType() != scConstant)
+ if (auto *M = dyn_cast<SCEVMulExpr>(V)) {
+ auto *StepConst = dyn_cast<SCEVConstant>(M->getOperand(0));
+ if (!StepConst)
return nullptr;
- const APInt &APStepVal = cast<SCEVConstant>(M->getOperand(0))->getAPInt();
-
- // Huge step value - give up.
- if (APStepVal.getBitWidth() > 64)
+ auto StepVal = StepConst->getAPInt().trySExtValue();
+ // Bail out on a non-unit pointer access size.
+ if (!StepVal || StepVal != 1)
return nullptr;
- int64_t StepVal = APStepVal.getSExtValue();
- if (PtrAccessSize != StepVal)
- return nullptr;
V = M->getOperand(1);
}
}
@@ -2920,7 +2912,7 @@ static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *L
if (isa<SCEVUnknown>(V))
return V;
- if (const auto *C = dyn_cast<SCEVIntegralCastExpr>(V))
+ if (auto *C = dyn_cast<SCEVIntegralCastExpr>(V))
if (isa<SCEVUnknown>(C->getOperand()))
return V;
More information about the llvm-commits
mailing list