[llvm] [polly] [SCEV] Introduce SDiv expressions (PR #216862)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 25 01:46:04 PDT 2026
================
@@ -729,20 +730,29 @@ Value *SCEVExpander::visitUDivExpr(SCEVUseT<const SCEVUDivExpr *> S) {
const SCEV *RHSExpr = S->getRHS();
Value *RHS = expand(RHSExpr);
if (SafeUDivMode) {
- bool GuaranteedNotPoison =
- ScalarEvolution::isGuaranteedNotToBePoison(RHSExpr);
- if (!GuaranteedNotPoison)
+ if (!ScalarEvolution::isGuaranteedNotToBePoison(RHSExpr))
RHS = Builder.CreateFreeze(RHS);
// We need an umax if either RHSExpr is not known to be zero, or if it is
// not guaranteed to be non-poison. In the later case, the frozen poison may
// be 0.
- if (!SE.isKnownNonZero(RHSExpr) || !GuaranteedNotPoison)
+ if (S->mayTriggerUB(SE))
RHS = Builder.CreateIntrinsic(RHS->getType(), Intrinsic::umax,
{RHS, ConstantInt::get(RHS->getType(), 1)});
}
return InsertBinop(Instruction::UDiv, LHS, RHS, SCEV::FlagAnyWrap,
- /*IsSafeToHoist*/ SE.isKnownNonZero(S->getRHS()));
+ /*IsSafeToHoist=*/!S->mayTriggerUB(SE));
+}
+
+Value *SCEVExpander::visitSDivExpr(SCEVUseT<const SCEVSDivExpr *> S) {
+ Value *LHS = expand(S->getLHS());
+ Value *RHS = expand(S->getRHS());
+ if (S->mayTriggerUB(SE)) {
+ LHS = Builder.CreateFreeze(LHS);
+ RHS = Builder.CreateFreeze(RHS);
+ }
----------------
artagnon wrote:
Thanks, hopefully got the proof right this time around, and encoded it correctly? https://alive2.llvm.org/ce/z/Hzc85V
https://github.com/llvm/llvm-project/pull/216862
More information about the llvm-commits
mailing list