[llvm] [SDPatternMatch] Add Matcher m_Undef (PR #122521)

Amr Hesham via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 10 12:25:04 PST 2025


https://github.com/AmrDeveloper created https://github.com/llvm/llvm-project/pull/122521

Add Matcher `m_Undef`

Fixes: 122439

>From edf0b82d157da73ab39d2614e2861f3c6f367358 Mon Sep 17 00:00:00 2001
From: AmrDeveloper <amr96 at programmer.net>
Date: Fri, 10 Jan 2025 21:17:25 +0100
Subject: [PATCH] [SDPatternMatch] Add Matcher m_Undef

---
 llvm/include/llvm/CodeGen/SDPatternMatch.h        |  2 ++
 .../CodeGen/SelectionDAGPatternMatchTest.cpp      | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index fc8ef717c74f6a..a2495267ee3526 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 <unsigned NumUses, typename Pattern> struct NUses_match {
   Pattern P;
 
diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
index a2e1e588d03dea..bd6420b43cef7c 100644
--- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
@@ -603,3 +603,18 @@ TEST_F(SelectionDAGPatternMatchTest, matchAdvancedProperties) {
   EXPECT_TRUE(sd_match(Add, DAG.get(),
                        m_LegalOp(m_IntegerVT(m_Add(m_Value(), m_Value())))));
 }
+
+TEST_F(SelectionDAGPatternMatchTest, matchUndefined) {
+  auto BoolVT = EVT::getIntegerVT(Context, 1);
+  auto Int32VT = EVT::getIntegerVT(Context, 32);
+  auto VInt32VT = EVT::getVectorVT(Context, Int32VT, 4);
+
+  SDValue UndefBoolVT = DAG->getUNDEF(BoolVT);
+  SDValue UndefInt32VT= DAG->getUNDEF(Int32VT);
+  SDValue UndefVInt32VT = DAG->getUNDEF(VInt32VT);
+
+  using namespace SDPatternMatch;
+  EXPECT_TRUE(sd_match(UndefBoolVT, m_Undef()));
+  EXPECT_TRUE(sd_match(UndefInt32VT, m_Undef()));
+  EXPECT_TRUE(sd_match(UndefVInt32VT, m_Undef()));
+}



More information about the llvm-commits mailing list