[llvm] [VPlan] Introduce m_[Specific]ICmp matcher (PR #151540)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 6 03:08:17 PDT 2025
================
@@ -461,6 +461,71 @@ m_c_BinaryOr(const Op0_t &Op0, const Op1_t &Op1) {
return m_BinaryOr<Op0_t, Op1_t, /*Commutative*/ true>(Op0, Op1);
}
+/// ICmp_match is a variant of BinaryRecipe_match that also binds the comparison
+/// predicate.
+template <typename Op0_t, typename Op1_t> struct ICmp_match {
+ CmpPredicate *Predicate = nullptr;
+ Op0_t Op0;
+ Op1_t Op1;
+
+ ICmp_match(CmpPredicate &Pred, const Op0_t &Op0, const Op1_t &Op1)
+ : Predicate(&Pred), Op0(Op0), Op1(Op1) {}
+ ICmp_match(const Op0_t &Op0, const Op1_t &Op1) : Op0(Op0), Op1(Op1) {}
+
+ bool match(const VPValue *V) const {
+ auto *DefR = V->getDefiningRecipe();
+ return DefR && match(DefR);
+ }
+
+ bool match(const VPRecipeBase *V) const {
+ if (m_Binary<Instruction::ICmp>(Op0, Op1).match(V)) {
+ if (Predicate)
+ *Predicate = cast<VPRecipeWithIRFlags>(V)->getPredicate();
+ return true;
+ }
+ return false;
+ }
+};
+
+/// SpecificICmp_match is a variant of BinaryRecipe_match that also matches the
+/// comparison predicate.
+template <typename Op0_t, typename Op1_t> struct SpecificICmp_match {
+ const CmpPredicate Predicate;
+ Op0_t Op0;
+ Op1_t Op1;
+
+ SpecificICmp_match(CmpPredicate Pred, const Op0_t &LHS, const Op1_t &RHS)
+ : Predicate(Pred), Op0(LHS), Op1(RHS) {}
+
+ bool match(const VPValue *V) const {
+ auto *DefR = V->getDefiningRecipe();
+ return DefR && match(DefR);
+ }
+
+ bool match(const VPRecipeBase *V) const {
+ return m_Binary<Instruction::ICmp>(Op0, Op1).match(V) &&
+ CmpPredicate::getMatching(
+ cast<VPRecipeWithIRFlags>(V)->getPredicate(), Predicate);
+ }
----------------
fhahn wrote:
```suggestion
bool match(const VPValue *V) const {
CmpPredicate CurrentPred;
return match(V, m_ICmp(CurrentPred, Op0, Op1)) && CmpPredicate::getMatching(CurrentPred, Predicate);
}
```
Could the matcher be implemented in terms of ICmp_match? This would also have the benefit to test the `m_ICmp` matcher with predicate, which currently isn't tested
https://github.com/llvm/llvm-project/pull/151540
More information about the llvm-commits
mailing list