Skip to content

Commit 7444ccd

Browse files
authored
LAA: improve code in getStrideFromPointer (NFC) (#124780)
Strip dead code, inline a constant, and modernize style.
1 parent e822dff commit 7444ccd

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,26 +2859,23 @@ static Value *stripGetElementPtr(Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
28592859
/// strides "a[i*stride]". Returns the symbolic stride, or null otherwise.
28602860
static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
28612861
auto *PtrTy = dyn_cast<PointerType>(Ptr->getType());
2862-
if (!PtrTy || PtrTy->isAggregateType())
2862+
if (!PtrTy)
28632863
return nullptr;
28642864

28652865
// Try to remove a gep instruction to make the pointer (actually index at this
28662866
// point) easier analyzable. If OrigPtr is equal to Ptr we are analyzing the
28672867
// pointer, otherwise, we are analyzing the index.
28682868
Value *OrigPtr = Ptr;
28692869

2870-
// The size of the pointer access.
2871-
int64_t PtrAccessSize = 1;
2872-
28732870
Ptr = stripGetElementPtr(Ptr, SE, Lp);
28742871
const SCEV *V = SE->getSCEV(Ptr);
28752872

28762873
if (Ptr != OrigPtr)
28772874
// Strip off casts.
2878-
while (const SCEVIntegralCastExpr *C = dyn_cast<SCEVIntegralCastExpr>(V))
2875+
while (auto *C = dyn_cast<SCEVIntegralCastExpr>(V))
28792876
V = C->getOperand();
28802877

2881-
const SCEVAddRecExpr *S = dyn_cast<SCEVAddRecExpr>(V);
2878+
auto *S = dyn_cast<SCEVAddRecExpr>(V);
28822879
if (!S)
28832880
return nullptr;
28842881

@@ -2888,25 +2885,20 @@ static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *L
28882885
return nullptr;
28892886

28902887
V = S->getStepRecurrence(*SE);
2891-
if (!V)
2892-
return nullptr;
28932888

28942889
// Strip off the size of access multiplication if we are still analyzing the
28952890
// pointer.
28962891
if (OrigPtr == Ptr) {
2897-
if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(V)) {
2898-
if (M->getOperand(0)->getSCEVType() != scConstant)
2892+
if (auto *M = dyn_cast<SCEVMulExpr>(V)) {
2893+
auto *StepConst = dyn_cast<SCEVConstant>(M->getOperand(0));
2894+
if (!StepConst)
28992895
return nullptr;
29002896

2901-
const APInt &APStepVal = cast<SCEVConstant>(M->getOperand(0))->getAPInt();
2902-
2903-
// Huge step value - give up.
2904-
if (APStepVal.getBitWidth() > 64)
2897+
auto StepVal = StepConst->getAPInt().trySExtValue();
2898+
// Bail out on a non-unit pointer access size.
2899+
if (!StepVal || StepVal != 1)
29052900
return nullptr;
29062901

2907-
int64_t StepVal = APStepVal.getSExtValue();
2908-
if (PtrAccessSize != StepVal)
2909-
return nullptr;
29102902
V = M->getOperand(1);
29112903
}
29122904
}
@@ -2920,7 +2912,7 @@ static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *L
29202912
if (isa<SCEVUnknown>(V))
29212913
return V;
29222914

2923-
if (const auto *C = dyn_cast<SCEVIntegralCastExpr>(V))
2915+
if (auto *C = dyn_cast<SCEVIntegralCastExpr>(V))
29242916
if (isa<SCEVUnknown>(C->getOperand()))
29252917
return V;
29262918

0 commit comments

Comments
 (0)