-
Notifications
You must be signed in to change notification settings - Fork 14.3k
LAA: improve code in getStrideFromPointer (NFC) #124780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Strip dead code, inline a constant, and modernize style.
@llvm/pr-subscribers-llvm-analysis Author: Ramkumar Ramachandra (artagnon) ChangesStrip dead code, inline a constant, and modernize style. Full diff: https://github.com/llvm/llvm-project/pull/124780.diff 1 Files Affected:
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;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for dealing with all the comments and explaining the logic. I think I'm satisfied now that the patch is NFC.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/13895 Here is the relevant piece of the build log for the reference
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the latest changes!
Strip dead code, inline a constant, and modernize style.