[llvm] 05dfac2 - [DAG] Adding m_FPToUI and m_FPToSI to SDPatternMatch.h (#104044)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 15 01:49:44 PDT 2024
Author: Jorge Botto
Date: 2024-08-15T09:49:40+01:00
New Revision: 05dfac23f1121aabb9675a38628e919689f993b0
URL: https://github.com/llvm/llvm-project/commit/05dfac23f1121aabb9675a38628e919689f993b0
DIFF: https://github.com/llvm/llvm-project/commit/05dfac23f1121aabb9675a38628e919689f993b0.diff
LOG: [DAG] Adding m_FPToUI and m_FPToSI to SDPatternMatch.h (#104044)
Adds m_FPToUI/m_FPToSI matchers for ISD::FP_TO_UINT/ISD::FP_TO_SINT in SDPatternMatch.h with suitable test coverage.
Fixes https://github.com/llvm/llvm-project/issues/103872
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 96ece1559bc437..88ddd43a2a8913 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -737,6 +737,14 @@ template <typename Opnd> inline UnaryOpc_match<Opnd> m_VScale(const Opnd &Op) {
return UnaryOpc_match<Opnd>(ISD::VSCALE, Op);
}
+template <typename Opnd> inline UnaryOpc_match<Opnd> m_FPToUI(const Opnd &Op) {
+ return UnaryOpc_match<Opnd>(ISD::FP_TO_UINT, Op);
+}
+
+template <typename Opnd> inline UnaryOpc_match<Opnd> m_FPToSI(const Opnd &Op) {
+ return UnaryOpc_match<Opnd>(ISD::FP_TO_SINT, Op);
+}
+
// === Constants ===
struct ConstantInt_match {
APInt *BindVal;
diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
index 074247e6e7d184..b9414be98623af 100644
--- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
@@ -238,9 +238,11 @@ TEST_F(SelectionDAGPatternMatchTest, matchUnaryOp) {
SDLoc DL;
auto Int32VT = EVT::getIntegerVT(Context, 32);
auto Int64VT = EVT::getIntegerVT(Context, 64);
+ auto FloatVT = EVT::getFloatingPointVT(32);
SDValue Op0 = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, Int32VT);
SDValue Op1 = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, Int64VT);
+ SDValue Op2 = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, FloatVT);
SDValue ZExt = DAG->getNode(ISD::ZERO_EXTEND, DL, Int64VT, Op0);
SDValue SExt = DAG->getNode(ISD::SIGN_EXTEND, DL, Int64VT, Op0);
@@ -252,6 +254,9 @@ TEST_F(SelectionDAGPatternMatchTest, matchUnaryOp) {
SDValue VScale = DAG->getVScale(DL, Int32VT, APInt::getMaxValue(32));
+ SDValue FPToSI = DAG->getNode(ISD::FP_TO_SINT, DL, FloatVT, Op2);
+ SDValue FPToUI = DAG->getNode(ISD::FP_TO_UINT, DL, FloatVT, Op2);
+
using namespace SDPatternMatch;
EXPECT_TRUE(sd_match(ZExt, m_UnaryOp(ISD::ZERO_EXTEND, m_Value())));
EXPECT_TRUE(sd_match(SExt, m_SExt(m_Value())));
@@ -263,6 +268,11 @@ TEST_F(SelectionDAGPatternMatchTest, matchUnaryOp) {
EXPECT_FALSE(sd_match(Sub, m_Neg(m_Value())));
EXPECT_FALSE(sd_match(Neg, m_Not(m_Value())));
EXPECT_TRUE(sd_match(VScale, m_VScale(m_Value())));
+
+ EXPECT_TRUE(sd_match(FPToUI, m_FPToUI(m_Value())));
+ EXPECT_TRUE(sd_match(FPToSI, m_FPToSI(m_Value())));
+ EXPECT_FALSE(sd_match(FPToUI, m_FPToSI(m_Value())));
+ EXPECT_FALSE(sd_match(FPToSI, m_FPToUI(m_Value())));
}
TEST_F(SelectionDAGPatternMatchTest, matchConstants) {
More information about the llvm-commits
mailing list