[llvm] [SCEV] BECount to zero if `((-1 + (1 smax %x))<nsw> /u %x)` holds (PR #104580)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 16 05:53:29 PDT 2024
================
@@ -3547,6 +3547,25 @@ const SCEV *ScalarEvolution::getUDivExpr(const SCEV *LHS,
}
}
+ // ((-1 + (1 smax %x))<nsw> /u %x) evaluates to zero, for any positive %x.
+ if (const auto *AE = dyn_cast<SCEVAddExpr>(LHS);
+ AE && AE->getNumOperands() == 2 && AE->hasNoSignedWrap()) {
+ bool FoundMinusOne = false, FoundOneSMaxRHS = false;
+ for (const SCEV *Op : AE->operands()) {
----------------
nikic wrote:
The constant operand is guaranteed to be first. You don't need to loop or use hasOperand, you know which operand will be which value.
https://github.com/llvm/llvm-project/pull/104580
More information about the llvm-commits
mailing list