[llvm] [DAG] Adding m_FPToUI and m_FPToSI to SDPatternMatch.h (PR #104044)
Jorge Botto via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 14 08:43:57 PDT 2024
https://github.com/jf-botto created https://github.com/llvm/llvm-project/pull/104044
Fixes https://github.com/llvm/llvm-project/issues/103872.
Add sm_FPToUI/m_FPToSI matchers for ISD::FP_TO_UINT/ISD::FP_TO_SINT in SDPatternMatch.h with suitable test coverage.
>From f61ba4e59aa00f0247071a6bd81991515fd09278 Mon Sep 17 00:00:00 2001
From: Jorge Botto <jorge.botto.16 at ucl.ac.uk>
Date: Wed, 14 Aug 2024 16:41:14 +0100
Subject: [PATCH] Adding m_FPToUI and m_FPToSI to SDPatternMatch.h
---
llvm/include/llvm/CodeGen/SDPatternMatch.h | 8 ++++++++
llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp | 8 ++++++++
2 files changed, 16 insertions(+)
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..1ba4716022f1e0 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,9 @@ 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())));
}
TEST_F(SelectionDAGPatternMatchTest, matchConstants) {
More information about the llvm-commits
mailing list