[llvm] DAG: Handle poison in m_Undef (PR #168288)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 21 10:54:18 PST 2025


https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/168288

>From dced6a659d8e0ca2c9fd083f015772ec6e0bc65f Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Sun, 16 Nov 2025 12:34:45 -0800
Subject: [PATCH 1/3] DAG: Handle poison in m_Undef

---
 llvm/include/llvm/CodeGen/SDPatternMatch.h              | 4 +++-
 llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index a81b91e338cb8..cf70380f1b627 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -222,7 +222,9 @@ template <typename... Preds> auto m_NoneOf(const Preds &...preds) {
 
 inline Opcode_match m_Opc(unsigned Opcode) { return Opcode_match(Opcode); }
 
-inline Opcode_match m_Undef() { return Opcode_match(ISD::UNDEF); }
+template <typename... Preds> auto m_Undef() {
+  return m_AnyOf(Opcode_match(ISD::UNDEF), Opcode_match(ISD::POISON));
+}
 
 inline Opcode_match m_Poison() { return Opcode_match(ISD::POISON); }
 
diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
index ceaee52a3948b..d7f2749ee493a 100644
--- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
@@ -551,6 +551,8 @@ TEST_F(SelectionDAGPatternMatchTest, matchConstants) {
   SDValue PoisonVInt32VT = DAG->getPOISON(VInt32VT);
   EXPECT_TRUE(sd_match(PoisonInt32VT, m_Poison()));
   EXPECT_TRUE(sd_match(PoisonVInt32VT, m_Poison()));
+  EXPECT_TRUE(sd_match(PoisonInt32VT, m_Undef()));
+  EXPECT_TRUE(sd_match(PoisonVInt32VT, m_Undef()));
 }
 
 TEST_F(SelectionDAGPatternMatchTest, patternCombinators) {

>From 6662319041ce6bc5c1c19529d6bbdab74481ab5a Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 21 Nov 2025 13:28:59 -0500
Subject: [PATCH 2/3] Remove template arguments

---
 llvm/include/llvm/CodeGen/SDPatternMatch.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index cf70380f1b627..d9574221fbcec 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -222,7 +222,7 @@ template <typename... Preds> auto m_NoneOf(const Preds &...preds) {
 
 inline Opcode_match m_Opc(unsigned Opcode) { return Opcode_match(Opcode); }
 
-template <typename... Preds> auto m_Undef() {
+auto m_Undef() {
   return m_AnyOf(Opcode_match(ISD::UNDEF), Opcode_match(ISD::POISON));
 }
 

>From a1ad14606036927c41af018499f9a039916e3dbd Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 21 Nov 2025 13:50:49 -0500
Subject: [PATCH 3/3] inline

---
 llvm/include/llvm/CodeGen/SDPatternMatch.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index d9574221fbcec..f7851fed57b32 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -222,7 +222,7 @@ template <typename... Preds> auto m_NoneOf(const Preds &...preds) {
 
 inline Opcode_match m_Opc(unsigned Opcode) { return Opcode_match(Opcode); }
 
-auto m_Undef() {
+inline auto m_Undef() {
   return m_AnyOf(Opcode_match(ISD::UNDEF), Opcode_match(ISD::POISON));
 }
 



More information about the llvm-commits mailing list