[llvm] [DA] Add initial support for monotonicity check (PR #162280)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 16 02:53:15 PDT 2025
================
@@ -177,13 +189,189 @@ void DependenceAnalysisWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequiredTransitive<LoopInfoWrapperPass>();
}
+namespace {
+
+/// The type of monotonicity of a SCEV. This property is defined with respect to
+/// the outermost loop that DA is analyzing.
+///
+/// This is designed to classify the behavior of AddRec expressions, and does
+/// not care about other SCEVs. For example, given the two loop-invariant values
+/// `A` and `B`, `A + B` is treated as Invariant even if the addition wraps.
----------------
Meinersbur wrote:
Using `Monotonic` is fine if the documentation/definition reflects what it is meant to be, even if it only implements it for AddRec atm. That would give a clear path how it cold to be extended.
> This property is defined with respect to the outermost loop that DA is analyzing.
Could be understood as FlagNSW of the outermost loop only, but I think you mean wrapping of any nested loop.
> This is designed to classify the behavior of AddRec expressions, and does not care about other SCEVs.
The current doxygen for `SCEVMonotonicityType` says it it only for AddRecs, and mixes monotonicity and wrapping (I think we consider monotonicity to imply no-wrapping, so if a wrapping AddRec is found it cannot be monotonic, but the other way around may not be true, e.g. with a non-affine SCEVAddRecExpr). Only caring about AddRecs seems arbitrary. Why? What is the property we want to ensure? Could you use a clearer definition?
> For example, given the two loop-invariant values `A` and `B`, `A + B` is treated as Invariant even if the addition wraps.
I think this is easier to explain with monotonicity, which is always relative to a variates, the loop induction variables in this case. `A` and `B` are just constants (so `A + B` also evaluates to just a constant, even if it is the result of an overflow, and could have been hoisted out of the loop), i.e. the function over which we defined monotonicity is $f_{A,B}(i)$, where $i$ is the variate.
https://github.com/llvm/llvm-project/pull/162280
More information about the llvm-commits
mailing list