[llvm] LAA: improve code in getStrideFromPointer (NFC) (PR #124780)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 28 08:22:54 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Ramkumar Ramachandra (artagnon)
<details>
<summary>Changes</summary>
Strip dead code, inline a constant, and modernize style.
---
Full diff: https://github.com/llvm/llvm-project/pull/124780.diff
1 Files Affected:
- (modified) llvm/lib/Analysis/LoopAccessAnalysis.cpp (+9-18)
``````````diff
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 697b40403902cc..aa3f108e24cb99 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,19 @@ 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)
+ if (auto StepVal = StepConst->getAPInt().trySExtValue();
+ !StepVal || StepVal != 1)
return nullptr;
- int64_t StepVal = APStepVal.getSExtValue();
- if (PtrAccessSize != StepVal)
- return nullptr;
V = M->getOperand(1);
}
}
@@ -2920,7 +2911,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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/124780
More information about the llvm-commits
mailing list