@@ -445,23 +445,11 @@ ArrayRef<const SCEV *> SCEV::operands() const {
445
445
llvm_unreachable("Unknown SCEV kind!");
446
446
}
447
447
448
- bool SCEV::isZero() const {
449
- if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(this))
450
- return SC->getValue()->isZero();
451
- return false;
452
- }
448
+ bool SCEV::isZero() const { return match(this, m_scev_Zero()); }
453
449
454
- bool SCEV::isOne() const {
455
- if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(this))
456
- return SC->getValue()->isOne();
457
- return false;
458
- }
450
+ bool SCEV::isOne() const { return match(this, m_scev_One()); }
459
451
460
- bool SCEV::isAllOnesValue() const {
461
- if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(this))
462
- return SC->getValue()->isMinusOne();
463
- return false;
464
- }
452
+ bool SCEV::isAllOnesValue() const { return match(this, m_scev_AllOnes()); }
465
453
466
454
bool SCEV::isNonConstantNegative() const {
467
455
const SCEVMulExpr *Mul = dyn_cast<SCEVMulExpr>(this);
@@ -10616,7 +10604,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::howFarToZero(const SCEV *V,
10616
10604
// 1*N = -Start; -1*N = Start (mod 2^BW), so:
10617
10605
// N = Distance (as unsigned)
10618
10606
10619
- if (match(Step, m_CombineOr(m_scev_One(), m_scev_MinusOne ()))) {
10607
+ if (match(Step, m_CombineOr(m_scev_One(), m_scev_AllOnes ()))) {
10620
10608
APInt MaxBECount = getUnsignedRangeMax(applyLoopGuards(Distance, Guards));
10621
10609
MaxBECount = APIntOps::umin(MaxBECount, getUnsignedRangeMax(Distance));
10622
10610
@@ -15511,9 +15499,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
15511
15499
15512
15500
// If we have LHS == 0, check if LHS is computing a property of some unknown
15513
15501
// SCEV %v which we can rewrite %v to express explicitly.
15514
- const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS);
15515
- if (Predicate == CmpInst::ICMP_EQ && RHSC &&
15516
- RHSC->getValue()->isNullValue()) {
15502
+ if (Predicate == CmpInst::ICMP_EQ && match(RHS, m_scev_Zero())) {
15517
15503
// If LHS is A % B, i.e. A % B == 0, rewrite A to (A /u B) * B to
15518
15504
// explicitly express that.
15519
15505
const SCEV *URemLHS = nullptr;
@@ -15694,8 +15680,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
15694
15680
To = RHS;
15695
15681
break;
15696
15682
case CmpInst::ICMP_NE:
15697
- if (isa<SCEVConstant>(RHS) &&
15698
- cast<SCEVConstant>(RHS)->getValue()->isNullValue()) {
15683
+ if (match(RHS, m_scev_Zero())) {
15699
15684
const SCEV *OneAlignedUp =
15700
15685
DividesBy ? GetNextSCEVDividesByDivisor(One, DividesBy) : One;
15701
15686
To = SE.getUMaxExpr(FromRewritten, OneAlignedUp);
0 commit comments