Skip to content

Commit d68a6fa

Browse files
committed
[DAG] Implement SDPatternMatch m_SpecificScalarVT and m_SpecificVectorElementVT matchers
1 parent b6b8fa3 commit d68a6fa

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

llvm/include/llvm/CodeGen/SDPatternMatch.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,34 @@ inline auto m_SpecificVT(EVT RefVT) {
277277
inline auto m_Glue() { return m_SpecificVT(MVT::Glue); }
278278
inline auto m_OtherVT() { return m_SpecificVT(MVT::Other); }
279279

280+
/// Match a scalar ValueType.
281+
template <typename Pattern>
282+
inline auto m_SpecificScalarVT(EVT RefVT, const Pattern &P) {
283+
return ValueType_match{[=](EVT VT) { return VT.getScalarType() == RefVT; },
284+
P};
285+
}
286+
inline auto m_SpecificScalarVT(EVT RefVT) {
287+
return ValueType_match{[=](EVT VT) { return VT.getScalarType() == RefVT; },
288+
m_Value()};
289+
}
290+
291+
/// Match a vector ValueType.
292+
template <typename Pattern>
293+
inline auto m_SpecificVectorElementVT(EVT RefVT, const Pattern &P) {
294+
return ValueType_match{[=](EVT VT) {
295+
return VT.isVector() &&
296+
VT.getVectorElementType() == RefVT;
297+
},
298+
P};
299+
}
300+
inline auto m_SpecificVectorElementVT(EVT RefVT) {
301+
return ValueType_match{[=](EVT VT) {
302+
return VT.isVector() &&
303+
VT.getVectorElementType() == RefVT;
304+
},
305+
m_Value()};
306+
}
307+
280308
/// Match any integer ValueTypes.
281309
template <typename Pattern> inline auto m_IntegerVT(const Pattern &P) {
282310
return ValueType_match{[](EVT VT) { return VT.isInteger(); }, P};

llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ TEST_F(SelectionDAGPatternMatchTest, matchValueType) {
110110

111111
using namespace SDPatternMatch;
112112
EXPECT_TRUE(sd_match(Op0, m_SpecificVT(Int32VT)));
113+
EXPECT_TRUE(sd_match(Op0, m_SpecificScalarVT(Int32VT)));
114+
EXPECT_FALSE(sd_match(Op0, m_SpecificScalarVT(Float32VT)));
115+
EXPECT_TRUE(sd_match(Op2, m_SpecificVectorElementVT(Int32VT)));
116+
EXPECT_FALSE(sd_match(Op2, m_SpecificVectorElementVT(Float32VT)));
113117
EVT BindVT;
114118
EXPECT_TRUE(sd_match(Op1, m_VT(BindVT)));
115119
EXPECT_EQ(BindVT, Float32VT);

0 commit comments

Comments
 (0)