[llvm] [DA] Check monotonicity for subscripts (PR #154527)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 25 05:02:06 PDT 2025
================
@@ -3308,6 +3308,322 @@ void DependenceInfo::updateDirection(Dependence::DVEntry &Level,
llvm_unreachable("constraint has unexpected kind");
}
+namespace {
+
+enum class MonotonicityType {
+ MaySignedWrap, ///< The expression contains arithmetic operations that may
+ ///< cause signed wrap.
+ Constant, ///< The expression is constant. If a SCEV is classified as
+ ///< Constant, it also implies that it doesn't contain any
+ ///< arithmetic operations that may cause signed wrap.
+ Monotonic, ///< The expression is monotonically increasing or decreasing. This
+ ///< is exclusive of Constant. That is, we say an SCEV is Monotonic
+ ///< iff it contains at least one AddRec where its step reccurence
+ ///< value is non-zero.
----------------
Meinersbur wrote:
I think the description should mention it is relative to a specific loop. If it does not contain an SCEVAddRec, it could still contain a SCEVUnkown that is non-invariant in that loop.
It becomes interesting if you have a SCEVAddRec of a nested loop in there. How do you think those should be handled? E.g. the specific loop is counting up but the nested loop is counting down.
```
for (int i = n; i >= 0; --i) {
int j = 0;
for (; j < m; ++j)
A[i + j] = ...;
B[i + j] = ...;
}
```
Is the SCEV for `A[i + j]` monotonic? I think it for `B[i + j]` because at that point `j==m` is invariant, so the min is `0 + m` and the max is `n + m`.
https://github.com/llvm/llvm-project/pull/154527
More information about the llvm-commits
mailing list