[llvm] [SCEV] - Set PositiveStride when adding stride > 0 predicate. (PR #228015)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 03:01:45 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Pawan Nirpal (pawan-nirpal-031)

<details>
<summary>Changes</summary>

Follows : https://github.com/llvm/llvm-project/pull/222261

When howManyLessThans adds a Compare predicate: stride sgt 0 for
loops that cannot be proven finite, the PositiveStride flag was not
being set. Even though the stride is guaranteed positive under the predicate.

---
Full diff: https://github.com/llvm/llvm-project/pull/228015.diff


1 Files Affected:

- (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+1) 


``````````diff
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index cbadeaf7b347dbd..809f94457b6b777 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -13541,6 +13541,7 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
       const SCEVPredicate *P =
           getComparePredicate(ICmpInst::ICMP_SGT, Stride, Zero);
       Predicates.push_back(P);
+      PositiveStride = true;
       // When the predicate holds (Stride > 0), umax(Stride, 1) == Stride,
       // so the result is unchanged. To prevent div by zero.
       Stride = getUMaxExpr(Stride, getOne(Stride->getType()));

``````````

</details>


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


More information about the llvm-commits mailing list