From 1d58699f5ce1a79634ea81f576cd4975cb04f046 Mon Sep 17 00:00:00 2001 From: Amr Hesham Date: Sat, 11 Jan 2025 13:23:37 +0100 Subject: [PATCH] [SDPatternMatch] Add Matcher m_Undef (#122521) Add Matcher `m_Undef` Fixes: #122439 --- llvm/include/llvm/CodeGen/SDPatternMatch.h | 2 ++ llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h index 2ccefa33abbf..4faa090901a6 100644 --- a/llvm/include/llvm/CodeGen/SDPatternMatch.h +++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h @@ -138,6 +138,8 @@ struct Opcode_match { inline Opcode_match m_Opc(unsigned Opcode) { return Opcode_match(Opcode); } +inline Opcode_match m_Undef() { return Opcode_match(ISD::UNDEF); } + template struct NUses_match { Pattern P; diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp index 9b759ef19efe..bf9c597d8ac5 100644 --- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp +++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp @@ -474,6 +474,11 @@ TEST_F(SelectionDAGPatternMatchTest, matchConstants) { EXPECT_EQ(CC, ISD::SETULT); EXPECT_TRUE(sd_match(SetCC, m_Node(ISD::SETCC, m_Value(), m_Value(), m_SpecificCondCode(ISD::SETULT)))); + + SDValue UndefInt32VT = DAG->getUNDEF(Int32VT); + SDValue UndefVInt32VT = DAG->getUNDEF(VInt32VT); + EXPECT_TRUE(sd_match(UndefInt32VT, m_Undef())); + EXPECT_TRUE(sd_match(UndefVInt32VT, m_Undef())); } TEST_F(SelectionDAGPatternMatchTest, patternCombinators) {