[llvm] [DAG] Add SDPatternMatch::m_VSelect (PR #100758)
Michael Maitland via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 26 07:54:28 PDT 2024
https://github.com/michaelmaitland updated https://github.com/llvm/llvm-project/pull/100758
>From 2514ca0f15be1676d798dfb99dcfaf38afeef5c3 Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Fri, 26 Jul 2024 07:48:54 -0700
Subject: [PATCH] [DAG] Add SDPatternMatch::m_VSelect
---
llvm/include/llvm/CodeGen/SDPatternMatch.h | 6 ++++++
llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp | 9 +++++++++
2 files changed, 15 insertions(+)
diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index 966e04f21334d..3c593cbafdecf 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -496,6 +496,12 @@ m_Select(const T0_P &Cond, const T1_P &T, const T2_P &F) {
return TernaryOpc_match<T0_P, T1_P, T2_P>(ISD::SELECT, Cond, T, F);
}
+template <typename T0_P, typename T1_P, typename T2_P>
+inline TernaryOpc_match<T0_P, T1_P, T2_P>
+m_VSelect(const T0_P &Cond, const T1_P &T, const T2_P &F) {
+ return TernaryOpc_match<T0_P, T1_P, T2_P>(ISD::VSELECT, Cond, T, F);
+}
+
// === Binary operations ===
template <typename LHS_P, typename RHS_P, bool Commutable = false,
bool ExcludeChain = false>
diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
index 549931b57e9af..9f1ea97129f63 100644
--- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
@@ -137,6 +137,11 @@ TEST_F(SelectionDAGPatternMatchTest, matchTernaryOp) {
SDValue F = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 5, Int1VT);
SDValue Select = DAG->getSelect(DL, MVT::i1, Cond, T, F);
+ auto VInt32VT = EVT::getVectorVT(Context, Int32VT, 4);
+ SDValue V1 = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 6, VInt32VT);
+ SDValue V2 = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 7, VInt32VT);
+ SDValue VSelect = DAG->getNode(ISD::VSELECT, DL, VInt32VT, Cond, V1, V2);
+
using namespace SDPatternMatch;
ISD::CondCode CC;
EXPECT_TRUE(sd_match(ICMP_UGT, m_SetCC(m_Value(), m_Value(),
@@ -166,6 +171,10 @@ TEST_F(SelectionDAGPatternMatchTest, matchTernaryOp) {
Select, m_Select(m_Specific(Cond), m_Specific(F), m_Specific(T))));
EXPECT_FALSE(sd_match(ICMP_EQ01, m_Select(m_Specific(Op0), m_Specific(Op1),
m_SpecificCondCode(ISD::SETEQ))));
+ EXPECT_TRUE(sd_match(
+ VSelect, m_VSelect(m_Specific(Cond), m_Specific(V1), m_Specific(V2))));
+ EXPECT_FALSE(sd_match(
+ Select, m_VSelect(m_Specific(Cond), m_Specific(V1), m_Specific(V2))));
}
TEST_F(SelectionDAGPatternMatchTest, matchBinaryOp) {
More information about the llvm-commits
mailing list