@@ -461,6 +461,66 @@ m_c_BinaryOr(const Op0_t &Op0, const Op1_t &Op1) {
461
461
return m_BinaryOr<Op0_t, Op1_t, /* Commutative*/ true >(Op0, Op1);
462
462
}
463
463
464
+ // / ICmp_match is a variant of BinaryRecipe_match that also binds the comparison
465
+ // / predicate.
466
+ template <typename Op0_t, typename Op1_t> struct ICmp_match {
467
+ CmpPredicate *Predicate = nullptr ;
468
+ Op0_t Op0;
469
+ Op1_t Op1;
470
+
471
+ ICmp_match (CmpPredicate &Pred, const Op0_t &Op0, const Op1_t &Op1)
472
+ : Predicate(&Pred), Op0(Op0), Op1(Op1) {}
473
+ ICmp_match (const Op0_t &Op0, const Op1_t &Op1) : Op0(Op0), Op1(Op1) {}
474
+
475
+ bool match (const VPValue *V) const {
476
+ auto *DefR = V->getDefiningRecipe ();
477
+ return DefR && match (DefR);
478
+ }
479
+
480
+ bool match (const VPRecipeBase *V) const {
481
+ if (m_Binary<Instruction::ICmp>(Op0, Op1).match (V)) {
482
+ if (Predicate)
483
+ *Predicate = cast<VPRecipeWithIRFlags>(V)->getPredicate ();
484
+ return true ;
485
+ }
486
+ return false ;
487
+ }
488
+ };
489
+
490
+ // / SpecificICmp_match is a variant of ICmp_match that matches the comparison
491
+ // / predicate, instead of binding it.
492
+ template <typename Op0_t, typename Op1_t> struct SpecificICmp_match {
493
+ const CmpPredicate Predicate;
494
+ Op0_t Op0;
495
+ Op1_t Op1;
496
+
497
+ SpecificICmp_match (CmpPredicate Pred, const Op0_t &LHS, const Op1_t &RHS)
498
+ : Predicate(Pred), Op0(LHS), Op1(RHS) {}
499
+
500
+ bool match (const VPValue *V) const {
501
+ CmpPredicate CurrentPred;
502
+ return ICmp_match<Op0_t, Op1_t>(CurrentPred, Op0, Op1).match (V) &&
503
+ CmpPredicate::getMatching (CurrentPred, Predicate);
504
+ }
505
+ };
506
+
507
+ template <typename Op0_t, typename Op1_t>
508
+ inline ICmp_match<Op0_t, Op1_t> m_ICmp (const Op0_t &Op0, const Op1_t &Op1) {
509
+ return ICmp_match<Op0_t, Op1_t>(Op0, Op1);
510
+ }
511
+
512
+ template <typename Op0_t, typename Op1_t>
513
+ inline ICmp_match<Op0_t, Op1_t> m_ICmp (CmpPredicate &Pred, const Op0_t &Op0,
514
+ const Op1_t &Op1) {
515
+ return ICmp_match<Op0_t, Op1_t>(Pred, Op0, Op1);
516
+ }
517
+
518
+ template <typename Op0_t, typename Op1_t>
519
+ inline SpecificICmp_match<Op0_t, Op1_t>
520
+ m_SpecificICmp (CmpPredicate MatchPred, const Op0_t &Op0, const Op1_t &Op1) {
521
+ return SpecificICmp_match<Op0_t, Op1_t>(MatchPred, Op0, Op1);
522
+ }
523
+
464
524
template <typename Op0_t, typename Op1_t>
465
525
using GEPLikeRecipe_match =
466
526
BinaryRecipe_match<Op0_t, Op1_t, Instruction::GetElementPtr, false ,
0 commit comments