[llvm] 1782e50 - DAG: Reorder SDPatternMatch combinators earlier (#168625)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 19 09:27:32 PST 2025
Author: Matt Arsenault
Date: 2025-11-19T12:27:28-05:00
New Revision: 1782e501f57ee5d3a1d2548f87ed4b82e7568b1d
URL: https://github.com/llvm/llvm-project/commit/1782e501f57ee5d3a1d2548f87ed4b82e7568b1d
DIFF: https://github.com/llvm/llvm-project/commit/1782e501f57ee5d3a1d2548f87ed4b82e7568b1d.diff
LOG: DAG: Reorder SDPatternMatch combinators earlier (#168625)
Split out from #168288
Added:
Modified:
llvm/include/llvm/CodeGen/SDPatternMatch.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index 557dbf8c7ca39..a81b91e338cb8 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -155,6 +155,71 @@ struct Opcode_match {
}
};
+// === Patterns combinators ===
+template <typename... Preds> struct And {
+ template <typename MatchContext> bool match(const MatchContext &, SDValue N) {
+ return true;
+ }
+};
+
+template <typename Pred, typename... Preds>
+struct And<Pred, Preds...> : And<Preds...> {
+ Pred P;
+ And(const Pred &p, const Preds &...preds) : And<Preds...>(preds...), P(p) {}
+
+ template <typename MatchContext>
+ bool match(const MatchContext &Ctx, SDValue N) {
+ return P.match(Ctx, N) && And<Preds...>::match(Ctx, N);
+ }
+};
+
+template <typename... Preds> struct Or {
+ template <typename MatchContext> bool match(const MatchContext &, SDValue N) {
+ return false;
+ }
+};
+
+template <typename Pred, typename... Preds>
+struct Or<Pred, Preds...> : Or<Preds...> {
+ Pred P;
+ Or(const Pred &p, const Preds &...preds) : Or<Preds...>(preds...), P(p) {}
+
+ template <typename MatchContext>
+ bool match(const MatchContext &Ctx, SDValue N) {
+ return P.match(Ctx, N) || Or<Preds...>::match(Ctx, N);
+ }
+};
+
+template <typename Pred> struct Not {
+ Pred P;
+
+ explicit Not(const Pred &P) : P(P) {}
+
+ template <typename MatchContext>
+ bool match(const MatchContext &Ctx, SDValue N) {
+ return !P.match(Ctx, N);
+ }
+};
+// Explicit deduction guide.
+template <typename Pred> Not(const Pred &P) -> Not<Pred>;
+
+/// Match if the inner pattern does NOT match.
+template <typename Pred> inline Not<Pred> m_Unless(const Pred &P) {
+ return Not{P};
+}
+
+template <typename... Preds> And<Preds...> m_AllOf(const Preds &...preds) {
+ return And<Preds...>(preds...);
+}
+
+template <typename... Preds> Or<Preds...> m_AnyOf(const Preds &...preds) {
+ return Or<Preds...>(preds...);
+}
+
+template <typename... Preds> auto m_NoneOf(const Preds &...preds) {
+ return m_Unless(m_AnyOf(preds...));
+}
+
inline Opcode_match m_Opc(unsigned Opcode) { return Opcode_match(Opcode); }
inline Opcode_match m_Undef() { return Opcode_match(ISD::UNDEF); }
@@ -373,71 +438,6 @@ template <typename Pattern> inline auto m_LegalType(const Pattern &P) {
P};
}
-// === Patterns combinators ===
-template <typename... Preds> struct And {
- template <typename MatchContext> bool match(const MatchContext &, SDValue N) {
- return true;
- }
-};
-
-template <typename Pred, typename... Preds>
-struct And<Pred, Preds...> : And<Preds...> {
- Pred P;
- And(const Pred &p, const Preds &...preds) : And<Preds...>(preds...), P(p) {}
-
- template <typename MatchContext>
- bool match(const MatchContext &Ctx, SDValue N) {
- return P.match(Ctx, N) && And<Preds...>::match(Ctx, N);
- }
-};
-
-template <typename... Preds> struct Or {
- template <typename MatchContext> bool match(const MatchContext &, SDValue N) {
- return false;
- }
-};
-
-template <typename Pred, typename... Preds>
-struct Or<Pred, Preds...> : Or<Preds...> {
- Pred P;
- Or(const Pred &p, const Preds &...preds) : Or<Preds...>(preds...), P(p) {}
-
- template <typename MatchContext>
- bool match(const MatchContext &Ctx, SDValue N) {
- return P.match(Ctx, N) || Or<Preds...>::match(Ctx, N);
- }
-};
-
-template <typename Pred> struct Not {
- Pred P;
-
- explicit Not(const Pred &P) : P(P) {}
-
- template <typename MatchContext>
- bool match(const MatchContext &Ctx, SDValue N) {
- return !P.match(Ctx, N);
- }
-};
-// Explicit deduction guide.
-template <typename Pred> Not(const Pred &P) -> Not<Pred>;
-
-/// Match if the inner pattern does NOT match.
-template <typename Pred> inline Not<Pred> m_Unless(const Pred &P) {
- return Not{P};
-}
-
-template <typename... Preds> And<Preds...> m_AllOf(const Preds &...preds) {
- return And<Preds...>(preds...);
-}
-
-template <typename... Preds> Or<Preds...> m_AnyOf(const Preds &...preds) {
- return Or<Preds...>(preds...);
-}
-
-template <typename... Preds> auto m_NoneOf(const Preds &...preds) {
- return m_Unless(m_AnyOf(preds...));
-}
-
// === Generic node matching ===
template <unsigned OpIdx, typename... OpndPreds> struct Operands_match {
template <typename MatchContext>
More information about the llvm-commits
mailing list