[llvm] [SDPatternMatch] Add Matcher m_Undef (PR #122521)
Amr Hesham via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 11 00:17:19 PST 2025
https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/122521
>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 1/3] [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()));
+}
>From 546b9257d223c6a2f80c987aac65088dc0e90ad4 Mon Sep 17 00:00:00 2001
From: AmrDeveloper <amr96 at programmer.net>
Date: Fri, 10 Jan 2025 21:29:54 +0100
Subject: [PATCH 2/3] Fix format
---
llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
index bd6420b43cef7c..2d774de02dae53 100644
--- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
@@ -610,7 +610,7 @@ TEST_F(SelectionDAGPatternMatchTest, matchUndefined) {
auto VInt32VT = EVT::getVectorVT(Context, Int32VT, 4);
SDValue UndefBoolVT = DAG->getUNDEF(BoolVT);
- SDValue UndefInt32VT= DAG->getUNDEF(Int32VT);
+ SDValue UndefInt32VT = DAG->getUNDEF(Int32VT);
SDValue UndefVInt32VT = DAG->getUNDEF(VInt32VT);
using namespace SDPatternMatch;
>From b3d8f5c55d177705739e266a44de17fff6303af1 Mon Sep 17 00:00:00 2001
From: AmrDeveloper <amr96 at programmer.net>
Date: Sat, 11 Jan 2025 09:07:29 +0100
Subject: [PATCH 3/3] Move the test to matchConstants
---
.../CodeGen/SelectionDAGPatternMatchTest.cpp | 20 +++++--------------
1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
index 2d774de02dae53..24d1b7f855160d 100644
--- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
@@ -436,6 +436,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) {
@@ -603,18 +608,3 @@ 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