diff options
author | Ramkumar Ramachandra <ramkumar.ramachandra@codasip.com> | 2025-01-31 20:06:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-31 20:06:25 +0000 |
commit | 7444ccdd26ae5f7de828f50820a80b6b4014c9fa (patch) | |
tree | 991a9771f377be61f421c629adabc10e8c4f6669 /llvm/lib/Analysis/LoopAccessAnalysis.cpp | |
parent | e822dff0e9285707ad964ba831cb861d2f6f1714 (diff) | |
download | llvm-7444ccdd26ae5f7de828f50820a80b6b4014c9fa.zip llvm-7444ccdd26ae5f7de828f50820a80b6b4014c9fa.tar.gz llvm-7444ccdd26ae5f7de828f50820a80b6b4014c9fa.tar.bz2 |
LAA: improve code in getStrideFromPointer (NFC) (#124780)
Strip dead code, inline a constant, and modernize style.
Diffstat (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/LoopAccessAnalysis.cpp | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index 697b404..ac8a35f 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; |