Index: include/llvm/CodeGen/GlobalISel/MIPatternMatch.h =================================================================== --- include/llvm/CodeGen/GlobalISel/MIPatternMatch.h +++ include/llvm/CodeGen/GlobalISel/MIPatternMatch.h @@ -221,6 +221,12 @@ 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 @@ 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)); Index: unittests/CodeGen/GlobalISel/PatternMatchTest.cpp =================================================================== --- unittests/CodeGen/GlobalISel/PatternMatchTest.cpp +++ unittests/CodeGen/GlobalISel/PatternMatchTest.cpp @@ -212,6 +212,14 @@ 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 @@ 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());