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

Pawan Nirpal via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 03:00:57 PDT 2026


https://github.com/pawan-nirpal-031 created https://github.com/llvm/llvm-project/pull/228015

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.

>From 1eafb8084e18128638541a9715dfea023baf22c9 Mon Sep 17 00:00:00 2001
From: Pawan Nirpal <pnirpal at qti.qualcomm.com>
Date: Thu, 1 Oct 2026 02:58:09 -0700
Subject: [PATCH] [SCEV] - Set PositiveStride when adding stride > 0 predicate

---
 llvm/lib/Analysis/ScalarEvolution.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index cbadeaf7b347d..809f94457b6b7 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()));



More information about the llvm-commits mailing list