[llvm] [SCEV] Add non-poison/non-zero checks on denominators (PR #117152)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 21 05:06:11 PST 2024
================
@@ -3422,9 +3422,14 @@ const SCEV *ScalarEvolution::getUDivExpr(const SCEV *LHS,
if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP))
return S;
+ // If the denominator is zero, the udiv will trap.
+ auto IsValidDenominator = [&] {
+ return isGuaranteedNotToBePoison(RHS) && isKnownNonZero(RHS);
----------------
fhahn wrote:
Share logic with the existing code in `getSequentialMinMaxExpr`
```
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 && (!isKnownNonZero(UDiv->getOperand(1)) ||
!isGuaranteedNotToBePoison(UDiv->getOperand(1)));
});
```
https://github.com/llvm/llvm-project/pull/117152
More information about the llvm-commits
mailing list