-
Notifications
You must be signed in to change notification settings - Fork 15.2k
DAG: Reorder SDPatternMatch combinators earlier #168625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arsenm
merged 1 commit into
main
from
users/arsenm/dag/reorder-sdpatternmatch-combinators-earlier
Nov 19, 2025
Merged
DAG: Reorder SDPatternMatch combinators earlier #168625
arsenm
merged 1 commit into
main
from
users/arsenm/dag/reorder-sdpatternmatch-combinators-earlier
Nov 19, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Split out from #168288
Member
|
@llvm/pr-subscribers-llvm-selectiondag Author: Matt Arsenault (arsenm) ChangesSplit out from #168288 Full diff: https://github.com/llvm/llvm-project/pull/168625.diff 1 Files Affected:
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>
|
🐧 Linux x64 Test Results
|
RKSimon
approved these changes
Nov 19, 2025
Collaborator
RKSimon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Split out from #168288