-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Add m_SelectCCLike matcher to match SELECT_CC or SELECT with SETCC #149646
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
Changes from 11 commits
432880f
060eba0
72ad2f7
f703bf7
42279f8
2e22456
ebab64b
6436237
065aa5a
eca282d
4e17482
d24f058
82b9b2c
4651216
06290be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -578,6 +578,16 @@ m_InsertSubvector(const LHS &Base, const RHS &Sub, const IDX &Idx) { | |
| return TernaryOpc_match<LHS, RHS, IDX>(ISD::INSERT_SUBVECTOR, Base, Sub, Idx); | ||
| } | ||
|
|
||
| template <typename LTy, typename RTy, typename TTy, typename FTy, typename CCTy> | ||
| inline auto m_SelectCC(LTy L, RTy R, TTy T, FTy F, CCTy CC) { | ||
| return m_Node(ISD::SELECT_CC, L, R, T, F, CC); | ||
| } | ||
|
|
||
| template <typename LTy, typename RTy, typename TTy, typename FTy, typename CCTy> | ||
| inline auto m_SelectCCLike(LTy L, RTy R, TTy T, FTy F, CCTy CC) { | ||
|
||
| return m_AnyOf(m_Select(m_SetCC(L, R, CC), T, F), m_SelectCC(L, R, T, F, CC)); | ||
| } | ||
|
|
||
| // === Binary operations === | ||
| template <typename LHS_P, typename RHS_P, bool Commutable = false, | ||
| bool ExcludeChain = false> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -949,3 +949,62 @@ TEST_F(SelectionDAGPatternMatchTest, MatchZeroOneAllOnes) { | |
| EXPECT_TRUE(sd_match(Vec, DAG.get(), m_AllOnes(true))); | ||
| } | ||
| } | ||
|
|
||
| TEST_F(SelectionDAGPatternMatchTest, MatchSelectCCLike) { | ||
|
||
| using namespace SDPatternMatch; | ||
|
|
||
| SDValue LHS = DAG->getConstant(1, SDLoc(), MVT::i32); | ||
| SDValue RHS = DAG->getConstant(2, SDLoc(), MVT::i32); | ||
| SDValue TVal = DAG->getConstant(3, SDLoc(), MVT::i32); | ||
| SDValue FVal = DAG->getConstant(4, SDLoc(), MVT::i32); | ||
| SDValue Select = DAG->getNode(ISD::SELECT_CC, SDLoc(), MVT::i32, LHS, RHS, | ||
| TVal, FVal, DAG->getCondCode(ISD::SETLT)); | ||
|
|
||
| ISD::CondCode CC = ISD::SETLT; | ||
| auto Matcher = | ||
| m_SelectCCLike(m_Specific(LHS), m_Specific(RHS), m_Specific(TVal), | ||
| m_Specific(FVal), m_CondCode(CC)); | ||
|
|
||
| struct DAGMatchContext { | ||
| SelectionDAG &DAG; | ||
| DAGMatchContext(SelectionDAG &DAG) : DAG(DAG) {} | ||
|
|
||
| bool match(SDValue N, unsigned Opcode) const { | ||
| return N.getOpcode() == Opcode; | ||
| } | ||
|
|
||
| unsigned getNumOperands(SDValue N) const { return N.getNumOperands(); } | ||
| }; | ||
|
||
|
|
||
| DAGMatchContext Ctx(*DAG); | ||
| EXPECT_TRUE(Matcher.match(Ctx, Select)); | ||
|
||
| } | ||
|
|
||
| TEST_F(SelectionDAGPatternMatchTest, MatchSelectCC) { | ||
| using namespace SDPatternMatch; | ||
|
|
||
| SDValue LHS = DAG->getConstant(1, SDLoc(), MVT::i32); | ||
| SDValue RHS = DAG->getConstant(2, SDLoc(), MVT::i32); | ||
| SDValue TVal = DAG->getConstant(3, SDLoc(), MVT::i32); | ||
| SDValue FVal = DAG->getConstant(4, SDLoc(), MVT::i32); | ||
| SDValue Select = DAG->getNode(ISD::SELECT_CC, SDLoc(), MVT::i32, LHS, RHS, | ||
| TVal, FVal, DAG->getCondCode(ISD::SETLT)); | ||
|
|
||
| ISD::CondCode CC = ISD::SETLT; | ||
| auto Matcher = m_SelectCC(m_Specific(LHS), m_Specific(RHS), m_Specific(TVal), | ||
| m_Specific(FVal), m_CondCode(CC)); | ||
|
|
||
| struct DAGMatchContext { | ||
| SelectionDAG &DAG; | ||
| DAGMatchContext(SelectionDAG &DAG) : DAG(DAG) {} | ||
|
|
||
| bool match(SDValue N, unsigned Opcode) const { | ||
| return N.getOpcode() == Opcode; | ||
| } | ||
|
|
||
| unsigned getNumOperands(SDValue N) const { return N.getNumOperands(); } | ||
| }; | ||
|
|
||
| DAGMatchContext Ctx(*DAG); | ||
| EXPECT_TRUE(Matcher.match(Ctx, Select)); | ||
| } | ||
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.
still need to by ref
m_SelectCC(LTy &L, RTy &R, TTy &T, FTy &F, CCTy &CC)(just not rvalue)