[DAG] Implement SDPatternMatch m_SpecificScalarVT and m_SpecificVectorElementVT matchers (#144996)

Resolves https://github.com/llvm/llvm-project/issues/144477

---------

Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
This commit is contained in:
zhaohui
2025-06-30 20:26:00 +08:00
committed by GitHub
parent 749c7c5dc4
commit eb1a80bfd3
2 changed files with 36 additions and 0 deletions

View File

@@ -294,6 +294,34 @@ inline auto m_SpecificVT(EVT RefVT) {
inline auto m_Glue() { return m_SpecificVT(MVT::Glue); }
inline auto m_OtherVT() { return m_SpecificVT(MVT::Other); }
/// Match a scalar ValueType.
template <typename Pattern>
inline auto m_SpecificScalarVT(EVT RefVT, const Pattern &P) {
return ValueType_match{[=](EVT VT) { return VT.getScalarType() == RefVT; },
P};
}
inline auto m_SpecificScalarVT(EVT RefVT) {
return ValueType_match{[=](EVT VT) { return VT.getScalarType() == RefVT; },
m_Value()};
}
/// Match a vector ValueType.
template <typename Pattern>
inline auto m_SpecificVectorElementVT(EVT RefVT, const Pattern &P) {
return ValueType_match{[=](EVT VT) {
return VT.isVector() &&
VT.getVectorElementType() == RefVT;
},
P};
}
inline auto m_SpecificVectorElementVT(EVT RefVT) {
return ValueType_match{[=](EVT VT) {
return VT.isVector() &&
VT.getVectorElementType() == RefVT;
},
m_Value()};
}
/// Match any integer ValueTypes.
template <typename Pattern> inline auto m_IntegerVT(const Pattern &P) {
return ValueType_match{[](EVT VT) { return VT.isInteger(); }, P};

View File

@@ -110,6 +110,14 @@ TEST_F(SelectionDAGPatternMatchTest, matchValueType) {
using namespace SDPatternMatch;
EXPECT_TRUE(sd_match(Op0, m_SpecificVT(Int32VT)));
EXPECT_TRUE(sd_match(Op0, m_SpecificScalarVT(Int32VT)));
EXPECT_TRUE(sd_match(Op0, m_SpecificScalarVT(Int32VT, m_Value())));
EXPECT_FALSE(sd_match(Op0, m_SpecificScalarVT(Float32VT)));
EXPECT_FALSE(sd_match(Op0, m_SpecificScalarVT(Float32VT, m_Value())));
EXPECT_TRUE(sd_match(Op2, m_SpecificVectorElementVT(Int32VT)));
EXPECT_TRUE(sd_match(Op2, m_SpecificVectorElementVT(Int32VT, m_Value())));
EXPECT_FALSE(sd_match(Op2, m_SpecificVectorElementVT(Float32VT)));
EXPECT_FALSE(sd_match(Op2, m_SpecificVectorElementVT(Float32VT, m_Value())));
EVT BindVT;
EXPECT_TRUE(sd_match(Op1, m_VT(BindVT)));
EXPECT_EQ(BindVT, Float32VT);