[llvm] [SCEV] Use APInt for DividesBy when collecting loop guard info (NFC). (PR #163017)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 11 14:53:23 PDT 2025
================
@@ -15633,47 +15633,34 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
return false;
};
- // Checks whether Expr is a non-negative constant, and Divisor is a positive
- // constant, and returns their APInt in ExprVal and in DivisorVal.
- auto GetNonNegExprAndPosDivisor = [&](const SCEV *Expr, const SCEV *Divisor,
- APInt &ExprVal, APInt &DivisorVal) {
- auto *ConstExpr = dyn_cast<SCEVConstant>(Expr);
- auto *ConstDivisor = dyn_cast<SCEVConstant>(Divisor);
- if (!ConstExpr || !ConstDivisor)
- return false;
- ExprVal = ConstExpr->getAPInt();
- DivisorVal = ConstDivisor->getAPInt();
- return ExprVal.isNonNegative() && !DivisorVal.isNonPositive();
- };
-
// Return a new SCEV that modifies \p Expr to the closest number divides by
// \p Divisor and greater or equal than Expr.
- // For now, only handle constant Expr and Divisor.
+ // For now, only handle constant Expr.
auto GetNextSCEVDividesByDivisor = [&](const SCEV *Expr,
- const SCEV *Divisor) {
- APInt ExprVal;
- APInt DivisorVal;
- if (!GetNonNegExprAndPosDivisor(Expr, Divisor, ExprVal, DivisorVal))
+ const APInt &DivisorVal) {
+ const APInt *ExprVal;
+ if (!match(Expr, m_scev_APInt(ExprVal)) ||
+ DivisorVal.isNonPositive())
----------------
nikic wrote:
This drops the `ExprVal.isNonNegative()` check. Is that intentional? (I haven't checked this carefully, but presumably negative values would need special handling for signed min/max?)
https://github.com/llvm/llvm-project/pull/163017
More information about the llvm-commits
mailing list