[GISel]: Add Pattern Matcher for G_FMUL.
authorAditya Nandakumar <aditya_nandakumar@apple.com>
Tue, 13 Feb 2018 20:09:13 +0000 (20:09 +0000)
committerAditya Nandakumar <aditya_nandakumar@apple.com>
Tue, 13 Feb 2018 20:09:13 +0000 (20:09 +0000)
https://reviews.llvm.org/D43206

llvm-svn: 325044

llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp

index caa2164..c6c9546 100644 (file)
@@ -202,6 +202,12 @@ m_GFAdd(const LHS &L, const RHS &R) {
   return BinaryOp_match<LHS, RHS, TargetOpcode::G_FADD, true>(L, R);
 }
 
+template <typename LHS, typename RHS>
+inline BinaryOp_match<LHS, RHS, TargetOpcode::G_FMUL, true>
+m_GFMul(const LHS &L, const RHS &R) {
+  return BinaryOp_match<LHS, RHS, TargetOpcode::G_FMUL, true>(L, R);
+}
+
 // Helper for unary instructions (G_[ZSA]EXT/G_TRUNC) etc
 template <typename SrcTy, unsigned Opcode> struct UnaryOp_match {
   SrcTy L;
index dd26e9b..dc41e54 100644 (file)
@@ -201,6 +201,15 @@ TEST(PatternMatchInstr, MatchBinaryOp) {
   match = mi_match(MIBSub->getOperand(0).getReg(), MRI,
                    m_GSub(m_ICst(Cst), m_Reg(Src0)));
   ASSERT_FALSE(match);
+
+  auto MIBFMul = B.buildInstr(TargetOpcode::G_FMUL, s64, Copies[0],
+                              B.buildConstant(s64, 42));
+  // Match and test commutativity for FMUL.
+  match = mi_match(MIBFMul->getOperand(0).getReg(), MRI,
+                   m_GFMul(m_ICst(Cst), m_Reg(Src0)));
+  ASSERT_TRUE(match);
+  ASSERT_EQ(Cst, (uint64_t)42);
+  ASSERT_EQ(Src0, Copies[0]);
 }
 
 TEST(PatternMatchInstr, MatchExtendsTrunc) {