[llvm] [LAA] Collect no-wrap predicates separately in getPtrStride/isNoWrap. (PR #203787)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 14 14:15:36 PDT 2026


================
@@ -1021,16 +1021,19 @@ getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
 }
 
 /// Check whether \p AR is a non-wrapping AddRec. If \p Ptr is not nullptr, use
-/// informating from the IR pointer value to determine no-wrap.
-static bool isNoWrap(PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR,
-                     Value *Ptr, Type *AccessTy, const Loop *L, bool Assume,
-                     const DominatorTree &DT,
-                     std::optional<int64_t> Stride = std::nullopt) {
+/// information from the IR pointer value to determine no-wrap. If \p Predicates
+/// is not nullptr add no-wrap assumptions if needed.
+static bool
+isNoWrap(PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR, Value *Ptr,
+         Type *AccessTy, const Loop *L, const DominatorTree &DT,
+         std::optional<int64_t> Stride = std::nullopt,
+         SmallVectorImpl<const SCEVPredicate *> *Predicates = nullptr) {
   // FIXME: This should probably only return true for NUW.
   if (any(AR->getNoWrapFlags(SCEV::NoWrapMask)))
     return true;
 
-  if (Ptr && PSE.hasNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW))
+  if (Ptr && isa<SCEVAddRecExpr>(PSE.getSCEV(Ptr)) &&
----------------
artagnon wrote:

Can we move the SCEVAddRecExpr check into hasNoOverflow? It calls a cast anyway:

```cpp
const auto *AR = cast<SCEVAddRecExpr>(Expr);
```

https://github.com/llvm/llvm-project/pull/203787


More information about the llvm-commits mailing list