[llvm] [LAA] Bound non-affine monotonic pointer expressions for runtime checks. (PR #210626)

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 14:49:31 PDT 2026


================
@@ -328,6 +328,64 @@ static bool evaluatePtrAddRecAtMaxBTCWillNotWrap(
   return SE.isKnownPredicate(CmpInst::ICMP_ULE, MaxOffset, DerefBytesSCEV);
 }
 
+/// Return true if \p S is known to be monotonically non-decreasing
+/// (in the unsigned sense, without unsigned wrap) across iterations of \p L.
+static bool isKnownNonDecreasingInLoop(const SCEV *S, const Loop *L,
+                                       ScalarEvolution &SE) {
+  if (SE.isLoopInvariant(S, L))
+    return true;
+
+  switch (S->getSCEVType()) {
+  case scUDivExpr: {
+    // Non-decreasing in the numerator when the divisor is loop-invariant.
+    const auto *UDiv = cast<SCEVUDivExpr>(S);
+    return SE.isLoopInvariant(UDiv->getRHS(), L) &&
+           isKnownNonDecreasingInLoop(UDiv->getLHS(), L, SE);
----------------
anemet wrote:

What happens if the loop-invariant is negative, doesn't that flip the direction?

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


More information about the llvm-commits mailing list