-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[DAG] Enhance SDPatternMatch to match integer minimum and maximum patterns in addition to the existing ISD nodes. #111774
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
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -542,6 +542,80 @@ struct BinaryOpc_match { | |
| } | ||
| }; | ||
|
|
||
| template <typename LHS_P, typename RHS_P, typename Pred_t, | ||
| bool Commutable = false, bool ExcludeChain = false> | ||
| struct MaxMin_match { | ||
| using PredType = Pred_t; | ||
| LHS_P LHS; | ||
| RHS_P RHS; | ||
|
|
||
| MaxMin_match(const LHS_P &L, const RHS_P &R) : LHS(L), RHS(R) {} | ||
|
|
||
| template <typename MatchContext> | ||
| bool match(const MatchContext &Ctx, SDValue N) { | ||
| if (sd_context_match(N, Ctx, m_Opc(ISD::SELECT))) { | ||
| EffectiveOperands<ExcludeChain> EO_SELECT(N, Ctx); | ||
| assert(EO_SELECT.Size == 3); | ||
| SDValue Cond = N->getOperand(EO_SELECT.FirstIndex); | ||
| SDValue TrueValue = N->getOperand(EO_SELECT.FirstIndex + 1); | ||
| SDValue FalseValue = N->getOperand(EO_SELECT.FirstIndex + 2); | ||
|
|
||
| if (sd_context_match(Cond, Ctx, m_Opc(ISD::SETCC))) { | ||
| EffectiveOperands<ExcludeChain> EO_SETCC(Cond, Ctx); | ||
| assert(EO_SETCC.Size == 3); | ||
| SDValue L = Cond->getOperand(EO_SETCC.FirstIndex); | ||
| SDValue R = Cond->getOperand(EO_SETCC.FirstIndex + 1); | ||
| CondCodeSDNode *CondNode = | ||
|
||
| cast<CondCodeSDNode>(Cond->getOperand(EO_SETCC.FirstIndex + 2)); | ||
|
|
||
| if ((TrueValue != L || FalseValue != R) && | ||
| (TrueValue != R || FalseValue != L)) { | ||
| return false; | ||
| } | ||
|
|
||
| ISD::CondCode Cond = | ||
| TrueValue == L ? CondNode->get() | ||
| : getSetCCInverse(CondNode->get(), L.getValueType()); | ||
| if (!Pred_t::match(Cond)) { | ||
| return false; | ||
| } | ||
| return (LHS.match(Ctx, L) && RHS.match(Ctx, R)) || | ||
| (Commutable && LHS.match(Ctx, R) && RHS.match(Ctx, L)); | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| // Helper class for identifying signed max predicates. | ||
| struct smax_pred_ty { | ||
| static bool match(ISD::CondCode Cond) { | ||
| return Cond == ISD::CondCode::SETGT || Cond == ISD::CondCode::SETGE; | ||
| } | ||
| }; | ||
|
|
||
| // Helper class for identifying unsigned max predicates. | ||
| struct umax_pred_ty { | ||
| static bool match(ISD::CondCode Cond) { | ||
| return Cond == ISD::CondCode::SETUGT || Cond == ISD::CondCode::SETUGE; | ||
| } | ||
| }; | ||
|
|
||
| // Helper class for identifying signed min predicates. | ||
| struct smin_pred_ty { | ||
| static bool match(ISD::CondCode Cond) { | ||
| return Cond == ISD::CondCode::SETLT || Cond == ISD::CondCode::SETLE; | ||
| } | ||
| }; | ||
|
|
||
| // Helper class for identifying unsigned min predicates. | ||
| struct umin_pred_ty { | ||
| static bool match(ISD::CondCode Cond) { | ||
| return Cond == ISD::CondCode::SETULT || Cond == ISD::CondCode::SETULE; | ||
| } | ||
| }; | ||
|
|
||
| template <typename LHS, typename RHS> | ||
| inline BinaryOpc_match<LHS, RHS> m_BinOp(unsigned Opc, const LHS &L, | ||
| const RHS &R) { | ||
|
|
@@ -613,21 +687,45 @@ inline BinaryOpc_match<LHS, RHS, true> m_SMin(const LHS &L, const RHS &R) { | |
| return BinaryOpc_match<LHS, RHS, true>(ISD::SMIN, L, R); | ||
| } | ||
|
|
||
| template <typename LHS, typename RHS> | ||
| inline auto m_SMinLike(const LHS &L, const RHS &R) { | ||
| return m_AnyOf(BinaryOpc_match<LHS, RHS, true>(ISD::SMIN, L, R), | ||
| MaxMin_match<LHS, RHS, smin_pred_ty, true>(L, R)); | ||
| } | ||
|
|
||
| template <typename LHS, typename RHS> | ||
| inline BinaryOpc_match<LHS, RHS, true> m_SMax(const LHS &L, const RHS &R) { | ||
| return BinaryOpc_match<LHS, RHS, true>(ISD::SMAX, L, R); | ||
| } | ||
|
|
||
| template <typename LHS, typename RHS> | ||
| inline auto m_SMaxLike(const LHS &L, const RHS &R) { | ||
| return m_AnyOf(BinaryOpc_match<LHS, RHS, true>(ISD::SMAX, L, R), | ||
| MaxMin_match<LHS, RHS, smax_pred_ty, true>(L, R)); | ||
| } | ||
|
|
||
| template <typename LHS, typename RHS> | ||
| inline BinaryOpc_match<LHS, RHS, true> m_UMin(const LHS &L, const RHS &R) { | ||
| return BinaryOpc_match<LHS, RHS, true>(ISD::UMIN, L, R); | ||
| } | ||
|
|
||
| template <typename LHS, typename RHS> | ||
| inline auto m_UMinLike(const LHS &L, const RHS &R) { | ||
| return m_AnyOf(BinaryOpc_match<LHS, RHS, true>(ISD::UMIN, L, R), | ||
| MaxMin_match<LHS, RHS, umin_pred_ty, true>(L, R)); | ||
| } | ||
|
|
||
| template <typename LHS, typename RHS> | ||
| inline BinaryOpc_match<LHS, RHS, true> m_UMax(const LHS &L, const RHS &R) { | ||
| return BinaryOpc_match<LHS, RHS, true>(ISD::UMAX, L, R); | ||
| } | ||
|
|
||
| template <typename LHS, typename RHS> | ||
| inline auto m_UMaxLike(const LHS &L, const RHS &R) { | ||
| return m_AnyOf(BinaryOpc_match<LHS, RHS, true>(ISD::UMAX, L, R), | ||
| MaxMin_match<LHS, RHS, umax_pred_ty, true>(L, R)); | ||
| } | ||
|
|
||
| template <typename LHS, typename RHS> | ||
| inline BinaryOpc_match<LHS, RHS> m_UDiv(const LHS &L, const RHS &R) { | ||
| return BinaryOpc_match<LHS, RHS>(ISD::UDIV, L, R); | ||
|
|
||
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
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
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
Oops, something went wrong.
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.
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.
What about ISD::VSELECT?
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.
Done.