[llvm] [SCEV] Propagate a recurrence's nuw flag to its exit value. (PR #217378)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 01:37:22 PDT 2026
================
@@ -970,6 +970,27 @@ static const SCEV *BinomialCoefficient(const SCEV *It, unsigned K,
SE.getTruncateOrZeroExtend(DivResult, ResultTy));
}
+/// Attach \p UseFlags to \p Res as use-specific flags, but only if \p Res
+/// really is the two-operand \p ExprT over \p LHS and \p RHS - in either order,
+/// as operands get sorted by complexity.
+///
+/// Flags established for that operation say nothing about any other expression:
+/// a folded-away operand, a flattened nested expression or a distributed
+/// constant all give a different computation. They must not be attached to it,
+/// because an n-ary expression's no-wrap flags have to hold for all subsets and
+/// orders of its operands, and SCEVExpander relies on that when it stamps them
+/// on every partial sum or product it builds.
+template <typename ExprT>
+static SCEVUse withUseFlagsIfNotFolded(const SCEV *Res, SCEVUse LHS,
----------------
fhahn wrote:
Yep this is just meant to be temporary, to avoid pulling in too many other changes. 6840ae04353b98b231b38af5e42e830a277e933e should have all changes needed to remove it as follow-up
I could also pull it in here, if preferred
https://github.com/llvm/llvm-project/pull/217378
More information about the llvm-commits
mailing list