[llvm] d3d2d72 - [DAG] SDPatternMatch - add missing BSWAP/CTPOP/CTTZ matchers
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 03:58:08 PDT 2024
Author: Simon Pilgrim
Date: 2024-10-16T11:52:58+01:00
New Revision: d3d2d72549e03403317ce325c17ad7d516643e2b
URL: https://github.com/llvm/llvm-project/commit/d3d2d72549e03403317ce325c17ad7d516643e2b
DIFF: https://github.com/llvm/llvm-project/commit/d3d2d72549e03403317ce325c17ad7d516643e2b.diff
LOG: [DAG] SDPatternMatch - add missing BSWAP/CTPOP/CTTZ matchers
Added:
Modified:
llvm/include/llvm/CodeGen/SDPatternMatch.h
llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index 0af4f73b869c3c..f0e12f28c9e6d1 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -822,6 +822,11 @@ inline UnaryOpc_match<Opnd, true> m_ChainedUnaryOp(unsigned Opc,
return UnaryOpc_match<Opnd, true>(Opc, Op);
}
+template <typename Opnd>
+inline UnaryOpc_match<Opnd> m_BSwap(const Opnd &Op) {
+ return UnaryOpc_match<Opnd>(ISD::BSWAP, Op);
+}
+
template <typename Opnd>
inline UnaryOpc_match<Opnd> m_BitReverse(const Opnd &Op) {
return UnaryOpc_match<Opnd>(ISD::BITREVERSE, Op);
@@ -892,10 +897,18 @@ template <typename Opnd> inline UnaryOpc_match<Opnd> m_FPToSI(const Opnd &Op) {
return UnaryOpc_match<Opnd>(ISD::FP_TO_SINT, Op);
}
+template <typename Opnd> inline UnaryOpc_match<Opnd> m_Ctpop(const Opnd &Op) {
+ return UnaryOpc_match<Opnd>(ISD::CTPOP, Op);
+}
+
template <typename Opnd> inline UnaryOpc_match<Opnd> m_Ctlz(const Opnd &Op) {
return UnaryOpc_match<Opnd>(ISD::CTLZ, Op);
}
+template <typename Opnd> inline UnaryOpc_match<Opnd> m_Cttz(const Opnd &Op) {
+ return UnaryOpc_match<Opnd>(ISD::CTTZ, Op);
+}
+
// === Constants ===
struct ConstantInt_match {
APInt *BindVal;
diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
index 7400b6c1984f72..a28e2b2b47dfa9 100644
--- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
@@ -302,7 +302,12 @@ TEST_F(SelectionDAGPatternMatchTest, matchUnaryOp) {
SDValue FPToSI = DAG->getNode(ISD::FP_TO_SINT, DL, FloatVT, Op2);
SDValue FPToUI = DAG->getNode(ISD::FP_TO_UINT, DL, FloatVT, Op2);
+ SDValue Brev = DAG->getNode(ISD::BITREVERSE, DL, Int32VT, Op0);
+ SDValue Bswap = DAG->getNode(ISD::BSWAP, DL, Int32VT, Op0);
+
+ SDValue Ctpop = DAG->getNode(ISD::CTPOP, DL, Int32VT, Op0);
SDValue Ctlz = DAG->getNode(ISD::CTLZ, DL, Int32VT, Op0);
+ SDValue Cttz = DAG->getNode(ISD::CTTZ, DL, Int32VT, Op0);
using namespace SDPatternMatch;
EXPECT_TRUE(sd_match(ZExt, m_UnaryOp(ISD::ZERO_EXTEND, m_Value())));
@@ -328,7 +333,17 @@ TEST_F(SelectionDAGPatternMatchTest, matchUnaryOp) {
EXPECT_FALSE(sd_match(FPToUI, m_FPToSI(m_Value())));
EXPECT_FALSE(sd_match(FPToSI, m_FPToUI(m_Value())));
+ EXPECT_TRUE(sd_match(Brev, m_BitReverse(m_Value())));
+ EXPECT_TRUE(sd_match(Bswap, m_BSwap(m_Value())));
+ EXPECT_FALSE(sd_match(Brev, m_BSwap(m_Value())));
+ EXPECT_FALSE(sd_match(Bswap, m_BitReverse(m_Value())));
+
+ EXPECT_TRUE(sd_match(Ctpop, m_Ctpop(m_Value())));
EXPECT_TRUE(sd_match(Ctlz, m_Ctlz(m_Value())));
+ EXPECT_TRUE(sd_match(Cttz, m_Cttz(m_Value())));
+ EXPECT_FALSE(sd_match(Ctpop, m_Ctlz(m_Value())));
+ EXPECT_FALSE(sd_match(Ctlz, m_Cttz(m_Value())));
+ EXPECT_FALSE(sd_match(Cttz, m_Ctlz(m_Value())));
}
TEST_F(SelectionDAGPatternMatchTest, matchConstants) {
More information about the llvm-commits
mailing list