@@ -445,23 +445,11 @@ ArrayRef<const SCEV *> SCEV::operands() const {
445445 llvm_unreachable("Unknown SCEV kind!");
446446}
447447
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()); }
453449
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()); }
459451
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()); }
465453
466454bool SCEV::isNonConstantNegative() const {
467455 const SCEVMulExpr *Mul = dyn_cast<SCEVMulExpr>(this);
@@ -10616,7 +10604,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::howFarToZero(const SCEV *V,
1061610604 // 1*N = -Start; -1*N = Start (mod 2^BW), so:
1061710605 // N = Distance (as unsigned)
1061810606
10619- if (match(Step, m_CombineOr(m_scev_One(), m_scev_MinusOne ()))) {
10607+ if (match(Step, m_CombineOr(m_scev_One(), m_scev_AllOnes ()))) {
1062010608 APInt MaxBECount = getUnsignedRangeMax(applyLoopGuards(Distance, Guards));
1062110609 MaxBECount = APIntOps::umin(MaxBECount, getUnsignedRangeMax(Distance));
1062210610
@@ -15511,9 +15499,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1551115499
1551215500 // If we have LHS == 0, check if LHS is computing a property of some unknown
1551315501 // 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())) {
1551715503 // If LHS is A % B, i.e. A % B == 0, rewrite A to (A /u B) * B to
1551815504 // explicitly express that.
1551915505 const SCEV *URemLHS = nullptr;
@@ -15694,8 +15680,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1569415680 To = RHS;
1569515681 break;
1569615682 case CmpInst::ICMP_NE:
15697- if (isa<SCEVConstant>(RHS) &&
15698- cast<SCEVConstant>(RHS)->getValue()->isNullValue()) {
15683+ if (match(RHS, m_scev_Zero())) {
1569915684 const SCEV *OneAlignedUp =
1570015685 DividesBy ? GetNextSCEVDividesByDivisor(One, DividesBy) : One;
1570115686 To = SE.getUMaxExpr(FromRewritten, OneAlignedUp);
0 commit comments