[llvm] [LV] Rewrite UDiv A, B -> UDiv A, UMax(B, 1) in trip counts if needed. (PR #92177)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 28 13:30:20 PDT 2024
================
@@ -4304,12 +4304,22 @@ ScalarEvolution::getSequentialMinMaxExpr(SCEVTypes Kind,
}
for (unsigned i = 1, e = Ops.size(); i != e; ++i) {
+ bool MayBeUB = SCEVExprContains(Ops[i], [this](const SCEV *S) {
+ auto *UDiv = dyn_cast<SCEVUDivExpr>(S);
+ // The UDiv may be UB if the divisor is poison or zero. Unless the divisor
+ // is a non-zero constant, we have to assume the UDiv may be UB.
+ return UDiv && (!isa<SCEVConstant>(UDiv->getOperand(1)) ||
+ !isKnownNonZero(UDiv->getOperand(1)));
+ });
+
+ if (MayBeUB)
+ continue;
----------------
fhahn wrote:
Added thanks!
https://github.com/llvm/llvm-project/pull/92177
More information about the llvm-commits
mailing list