@@ -4623,17 +4623,11 @@ const SCEV *ScalarEvolution::getNegativeSCEV(const SCEV *V,
46234623
46244624/// If Expr computes ~A, return A else return nullptr
46254625static const SCEV *MatchNotExpr(const SCEV *Expr) {
4626- const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Expr);
4627- if (!Add || Add->getNumOperands() != 2 ||
4628- !Add->getOperand(0)->isAllOnesValue())
4629- return nullptr;
4630-
4631- const SCEVMulExpr *AddRHS = dyn_cast<SCEVMulExpr>(Add->getOperand(1));
4632- if (!AddRHS || AddRHS->getNumOperands() != 2 ||
4633- !AddRHS->getOperand(0)->isAllOnesValue())
4634- return nullptr;
4635-
4636- return AddRHS->getOperand(1);
4626+ const SCEV *MulOp;
4627+ if (match(Expr, m_scev_Add(m_scev_AllOnes(),
4628+ m_scev_Mul(m_scev_AllOnes(), m_SCEV(MulOp)))))
4629+ return MulOp;
4630+ return nullptr;
46374631}
46384632
46394633/// Return a SCEV corresponding to ~V = -1-V
@@ -12220,12 +12214,11 @@ ScalarEvolution::computeConstantDifference(const SCEV *More, const SCEV *Less) {
1222012214 // Try to match a common constant multiply.
1222112215 auto MatchConstMul =
1222212216 [](const SCEV *S) -> std::optional<std::pair<const SCEV *, APInt>> {
12223- auto *M = dyn_cast<SCEVMulExpr>(S);
12224- if (!M || M->getNumOperands() != 2 ||
12225- !isa<SCEVConstant>(M->getOperand(0)))
12226- return std::nullopt;
12227- return {
12228- {M->getOperand(1), cast<SCEVConstant>(M->getOperand(0))->getAPInt()}};
12217+ const APInt *C;
12218+ const SCEV *Op;
12219+ if (match(S, m_scev_Mul(m_scev_APInt(C), m_SCEV(Op))))
12220+ return {{Op, *C}};
12221+ return std::nullopt;
1222912222 };
1223012223 if (auto MatchedMore = MatchConstMul(More)) {
1223112224 if (auto MatchedLess = MatchConstMul(Less)) {
0 commit comments