Skip to content

Commit edf0b82

Browse files
committed
[SDPatternMatch] Add Matcher m_Undef
1 parent 43e663d commit edf0b82

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

llvm/include/llvm/CodeGen/SDPatternMatch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ struct Opcode_match {
138138

139139
inline Opcode_match m_Opc(unsigned Opcode) { return Opcode_match(Opcode); }
140140

141+
inline Opcode_match m_Undef() { return Opcode_match(ISD::UNDEF); }
142+
141143
template <unsigned NumUses, typename Pattern> struct NUses_match {
142144
Pattern P;
143145

llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,3 +603,18 @@ TEST_F(SelectionDAGPatternMatchTest, matchAdvancedProperties) {
603603
EXPECT_TRUE(sd_match(Add, DAG.get(),
604604
m_LegalOp(m_IntegerVT(m_Add(m_Value(), m_Value())))));
605605
}
606+
607+
TEST_F(SelectionDAGPatternMatchTest, matchUndefined) {
608+
auto BoolVT = EVT::getIntegerVT(Context, 1);
609+
auto Int32VT = EVT::getIntegerVT(Context, 32);
610+
auto VInt32VT = EVT::getVectorVT(Context, Int32VT, 4);
611+
612+
SDValue UndefBoolVT = DAG->getUNDEF(BoolVT);
613+
SDValue UndefInt32VT= DAG->getUNDEF(Int32VT);
614+
SDValue UndefVInt32VT = DAG->getUNDEF(VInt32VT);
615+
616+
using namespace SDPatternMatch;
617+
EXPECT_TRUE(sd_match(UndefBoolVT, m_Undef()));
618+
EXPECT_TRUE(sd_match(UndefInt32VT, m_Undef()));
619+
EXPECT_TRUE(sd_match(UndefVInt32VT, m_Undef()));
620+
}

0 commit comments

Comments
 (0)