Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions llvm/lib/Analysis/LoopAccessAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2859,26 +2859,23 @@ 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
// point) easier analyzable. If OrigPtr is equal to Ptr we are analyzing the
// 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;

Expand All @@ -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)
auto StepVal = StepConst->getAPInt().trySExtValue();
if (!StepVal || StepVal != 1)
return nullptr;

int64_t StepVal = APStepVal.getSExtValue();
if (PtrAccessSize != StepVal)
return nullptr;
V = M->getOperand(1);
}
}
Expand All @@ -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;

Expand Down