[llvm] [SCEV] Merge udiv exact logic into general udiv logic (PR #195840)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed May 6 01:21:51 PDT 2026


================
@@ -3654,6 +3654,21 @@ const SCEV *ScalarEvolution::getUDivExpr(SCEVUse LHS, SCEVUse RHS) {
               return getMulExpr(Operands);
             }
           }
+
+          // Even if it's not divisible, try to remove a common factor.
+          if (const auto *LHSC = dyn_cast<SCEVConstant>(M->getOperand(0))) {
+            APInt Factor = APIntOps::GreatestCommonDivisor(LHSC->getAPInt(),
+                                                           RHSC->getAPInt());
----------------
nikic wrote:

I switched this to directly call GreatestCommonDivisor() instead of the gcd() helper, because that one seems to be targeted at a signed GCD (it takes absolute values).

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


More information about the llvm-commits mailing list