[llvm] [SCEV] Return a SCEVUse from getAddExpr and propagate use flags. (PR #220007)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 7 07:55:18 PDT 2026


================
@@ -2564,6 +2545,15 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
   if (Folded)
     return Folded;
 
+  // Conservatively drop use-specific flags if operands changed after constant
+  // folding, i.e. we are building a different expression than the initial one,
+  // for which the use-specific flags hold.
+  // TODO: In some cases, this is overly conservative.
----------------
nikic wrote:

I don't think this is necessary? We define that:

> NUW and NSW must hold for all subsets and orders of Add/Mul operands.

constantFoldAndGroupOps() can reorder operands, constant fold a subset of operands and remove identity operands. In all of those cases, the nowrap flags can be preserved (under SCEV semantics -- it wouldn't be valid for IR semantics where nowrap flags apply pairwise in a specific order).

https://github.com/llvm/llvm-project/pull/220007


More information about the llvm-commits mailing list