[llvm] [LAA] Perform checks for no-wrap separately from getPtrStride. (PR #126971)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 12 13:44:25 PST 2025
================
@@ -1458,74 +1544,13 @@ llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
return std::nullopt;
}
- // The access function must stride over the innermost loop.
- if (Lp != AR->getLoop()) {
- LLVM_DEBUG(dbgs() << "LAA: Bad stride - Not striding over innermost loop "
- << *Ptr << " SCEV: " << *AR << "\n");
- return std::nullopt;
- }
-
- // Check the step is constant.
- const SCEV *Step = AR->getStepRecurrence(*PSE.getSE());
-
- // Calculate the pointer stride and check if it is constant.
- const SCEVConstant *C = dyn_cast<SCEVConstant>(Step);
- if (!C) {
- LLVM_DEBUG(dbgs() << "LAA: Bad stride - Not a constant strided " << *Ptr
- << " SCEV: " << *AR << "\n");
- return std::nullopt;
- }
-
- const auto &DL = Lp->getHeader()->getDataLayout();
- TypeSize AllocSize = DL.getTypeAllocSize(AccessTy);
- int64_t Size = AllocSize.getFixedValue();
- const APInt &APStepVal = C->getAPInt();
-
- // Huge step value - give up.
- if (APStepVal.getBitWidth() > 64)
- return std::nullopt;
-
- int64_t StepVal = APStepVal.getSExtValue();
-
- // Strided access.
- int64_t Stride = StepVal / Size;
- int64_t Rem = StepVal % Size;
- if (Rem)
- return std::nullopt;
-
- if (!ShouldCheckWrap)
- return Stride;
-
- // The address calculation must not wrap. Otherwise, a dependence could be
- // inverted.
- if (isNoWrapAddRec(Ptr, AR, PSE, Lp))
- return Stride;
-
- // An nusw getelementptr that is an AddRec cannot wrap. If it would wrap,
- // the distance between the previously accessed location and the wrapped
- // location will be larger than half the pointer index type space. In that
- // case, the GEP would be poison and any memory access dependent on it would
- // be immediate UB when executed.
- if (auto *GEP = dyn_cast<GetElementPtrInst>(Ptr);
- GEP && GEP->hasNoUnsignedSignedWrap())
+ auto Stride = getStrideFromAddRec(AR, Lp, AccessTy, Ptr, PSE);
----------------
artagnon wrote:
s/auto/actual type/ since it's not clear?
https://github.com/llvm/llvm-project/pull/126971
More information about the llvm-commits
mailing list