[llvm] [SCEV] Introduce UDiv::mayTriggerUB (PR #217064)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 01:55:39 PDT 2026


================
@@ -1667,20 +1667,11 @@ Value *SCEVExpander::expand(SCEVUse S) {
 
   // We can move insertion point only if there is no div or rem operations
   // otherwise we are risky to move it over the check for zero denominator.
-  auto SafeToHoist = [](const SCEV *S) {
-    return !SCEVExprContains(S, [](const SCEV *S) {
-              if (const auto *D = dyn_cast<SCEVUDivExpr>(S)) {
-                if (const auto *SC = dyn_cast<SCEVConstant>(D->getRHS()))
-                  // Division by non-zero constants can be hoisted.
-                  return SC->getValue()->isZero();
-                // All other divisions should not be moved as they may be
-                // divisions by zero and should be kept within the
-                // conditions of the surrounding loops that guard their
-                // execution (see PR35406).
-                return true;
-              }
-              return false;
-            });
+  auto SafeToHoist = [this](const SCEV *S) {
+    return !SCEVExprContains(S, [this](const SCEV *S) {
+      const auto *D = dyn_cast<SCEVUDivExpr>(S);
+      return D && D->mayTriggerUB(SE);
----------------
nikic wrote:

This doesn't account for the poison case? We generally also have to prove both non-zero and non-poison for division.

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


More information about the llvm-commits mailing list