@@ -163,18 +163,28 @@ template <typename SCEVTy, typename Op0_t, typename Op1_t>
163163struct SCEVBinaryExpr_match {
164164 Op0_t Op0;
165165 Op1_t Op1;
166+
167+ SCEVBinaryExpr_match (Op0_t Op0, Op1_t Op1) : Op0(Op0), Op1(Op1) {}
168+
169+ bool match (const SCEV *S) const {
170+ auto *E = dyn_cast<SCEVTy>(S);
171+ return E && E->getNumOperands () == 2 && Op0.match (E->getOperand (0 )) &&
172+ Op1.match (E->getOperand (1 ));
173+ }
174+ };
175+
176+ template <typename Op0_t, typename Op1_t> struct SCEVAffineAddRec_match {
177+ Op0_t Op0;
178+ Op1_t Op1;
166179 const Loop *L;
167180
168- SCEVBinaryExpr_match (Op0_t Op0, Op1_t Op1, const Loop *L = nullptr )
181+ SCEVAffineAddRec_match (Op0_t Op0, Op1_t Op1, const Loop *L = nullptr )
169182 : Op0(Op0), Op1(Op1), L(L) {}
170183
171184 bool match (const SCEV *S) const {
172- auto *E = dyn_cast<SCEVTy>(S);
173- bool LoopMatches = true ;
174- if constexpr (std::is_same_v<SCEVTy, SCEVAddRecExpr>)
175- LoopMatches = !L || (E && E->getLoop () == L);
185+ auto *E = dyn_cast<SCEVAddRecExpr>(S);
176186 return E && E->getNumOperands () == 2 && Op0.match (E->getOperand (0 )) &&
177- Op1.match (E->getOperand (1 )) && LoopMatches ;
187+ Op1.match (E->getOperand (1 )) && (!L || E-> getLoop () == L) ;
178188 }
179189};
180190
@@ -203,10 +213,10 @@ m_scev_UDiv(const Op0_t &Op0, const Op1_t &Op1) {
203213}
204214
205215template <typename Op0_t, typename Op1_t>
206- inline SCEVBinaryExpr_match<SCEVAddRecExpr, Op0_t, Op1_t>
216+ inline SCEVAffineAddRec_match< Op0_t, Op1_t>
207217m_scev_AffineAddRec (const Op0_t &Op0, const Op1_t &Op1,
208218 const Loop *L = nullptr ) {
209- return m_scev_Binary<SCEVAddRecExpr >(Op0, Op1);
219+ return SCEVAffineAddRec_match<Op0_t, Op1_t >(Op0, Op1, L );
210220}
211221} // namespace SCEVPatternMatch
212222} // namespace llvm
0 commit comments