From 230bfd5b60425a9c5c769d690d97cc3ba0876805 Mon Sep 17 00:00:00 2001 From: Aditya Nandakumar Date: Thu, 31 May 2018 19:30:01 +0000 Subject: [PATCH] [GISel]: Pattern matchers for GFSUB, GFNEG https://reviews.llvm.org/D47547 Add matching templates for G_FSUB, and G_FNEG. Reviewed by: aemerson. llvm-svn: 333685 --- include/llvm/CodeGen/GlobalISel/MIPatternMatch.h | 11 +++++++++++ unittests/CodeGen/GlobalISel/PatternMatchTest.cpp | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h b/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h index 797f5e542fb..f77f9a8df7e 100644 --- a/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h +++ b/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h @@ -221,6 +221,12 @@ m_GFMul(const LHS &L, const RHS &R) { return BinaryOp_match(L, R); } +template +inline BinaryOp_match +m_GFSub(const LHS &L, const RHS &R) { + return BinaryOp_match(L, R); +} + template inline BinaryOp_match m_GAnd(const LHS &L, const RHS &R) { @@ -304,6 +310,11 @@ inline UnaryOp_match m_GFabs(const SrcTy &Src) { return UnaryOp_match(Src); } +template +inline UnaryOp_match m_GFNeg(const SrcTy &Src) { + return UnaryOp_match(Src); +} + template inline UnaryOp_match m_Copy(SrcTy &&Src) { return UnaryOp_match(std::forward(Src)); diff --git a/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp b/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp index 5fbbd76bbae..8f17b1991df 100644 --- a/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp +++ b/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp @@ -212,6 +212,14 @@ TEST(PatternMatchInstr, MatchBinaryOp) { ASSERT_EQ(Cst, 42); ASSERT_EQ(Src0, Copies[0]); + // FSUB + auto MIBFSub = B.buildInstr(TargetOpcode::G_FSUB, s64, Copies[0], + B.buildConstant(s64, 42)); + match = mi_match(MIBFSub->getOperand(0).getReg(), MRI, + m_GFSub(m_Reg(Src0), m_Reg())); + ASSERT_TRUE(match); + ASSERT_EQ(Src0, Copies[0]); + // Build AND %0, %1 auto MIBAnd = B.buildAnd(s64, Copies[0], Copies[1]); // Try to match AND. @@ -283,7 +291,13 @@ TEST(PatternMatchInstr, MatchFPUnaryOp) { auto MIBFabs = B.buildInstr(TargetOpcode::G_FABS, s32, Copy0s32); bool match = mi_match(MIBFabs->getOperand(0).getReg(), MRI, m_GFabs(m_Reg())); ASSERT_TRUE(match); + unsigned Src; + auto MIBFNeg = B.buildInstr(TargetOpcode::G_FNEG, s32, Copy0s32); + match = mi_match(MIBFNeg->getOperand(0).getReg(), MRI, m_GFNeg(m_Reg(Src))); + ASSERT_TRUE(match); + ASSERT_EQ(Src, Copy0s32->getOperand(0).getReg()); + match = mi_match(MIBFabs->getOperand(0).getReg(), MRI, m_GFabs(m_Reg(Src))); ASSERT_TRUE(match); ASSERT_EQ(Src, Copy0s32->getOperand(0).getReg());