[llvm] [ScalarEvolution] howManyLessThans infer stride isPositive from guard (PR #214014)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 06:33:21 PDT 2026
================
@@ -13465,6 +13465,14 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
const SCEV *Stride = IV->getStepRecurrence(*this);
bool PositiveStride = isKnownPositive(Stride);
+ // A dominating guard may prove the stride positive.
+ if (!PositiveStride) {
+ const SCEV *GuardedStride = applyLoopGuards(Stride, L);
+ if (isKnownPositive(GuardedStride)) {
+ Stride = GuardedStride;
----------------
fhahn wrote:
Yep, I think for trip counts, we currently only apply guards to expressions we then use for reasoning/min/max computations, but not the final product, as it can make the expression unnecessarily complex.
Would be good to have a test for this. https://github.com/dtcxzyw/llvm-opt-benchmark-nightly/pull/1095 might be a good source for such a test
https://github.com/llvm/llvm-project/pull/214014
More information about the llvm-commits
mailing list