[llvm] [SCEV] Infer NUW on AR in getUDivExpr (PR #217133)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 02:53:56 PDT 2026


================
@@ -3536,11 +3538,9 @@ const SCEV *ScalarEvolution::getUDivExpr(SCEVUse LHS, SCEVUse RHS) {
           // {X,+,N}/C --> {X/C,+,N/C} if safe and N/C can be folded.
           const APInt &StepInt = Step->getAPInt();
           const APInt &DivInt = RHSC->getAPInt();
-          if (!StepInt.urem(DivInt) &&
-              getZeroExtendExpr(AR, ExtTy) ==
-              getAddRecExpr(getZeroExtendExpr(AR->getStart(), ExtTy),
-                            getZeroExtendExpr(Step, ExtTy),
-                            AR->getLoop(), SCEV::FlagAnyWrap)) {
+          bool HasNUW = hasFlags(proveNoUnsignedWrapViaInduction(AR),
+                                 SCEVNoWrapFlags::FlagNUW);
----------------
nikic wrote:

Looking at the zext implementation, it also has a bunch of other logic for inferring flags, like this: https://github.com/llvm/llvm-project/blob/d92ae181af1ae978b7a036a064897d654fc027b7/llvm/lib/Analysis/ScalarEvolution.cpp#L1672-L1727

Is that not relevant?

It would generally be great if we could get rid of that code and infer on construction to the degree possible.

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


More information about the llvm-commits mailing list