[PATCH] D43206: [GISel]: Add pattern matcher for FMUL and FADD
Aditya Nandakumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 12 12:27:49 PST 2018
aditya_nandakumar created this revision.
aditya_nandakumar added reviewers: volkan, qcolombet, rovka, dsanders, ab.
Just adding patterns as we need them (out of tree target) with test cases.
Repository:
rL LLVM
https://reviews.llvm.org/D43206
Files:
include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
Index: unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
===================================================================
--- unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
+++ unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
@@ -201,6 +201,15 @@
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) {
Index: include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
===================================================================
--- include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
+++ include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
@@ -197,9 +197,15 @@
}
template <typename LHS, typename RHS>
-inline BinaryOp_match<LHS, RHS, TargetOpcode::G_FADD> m_GFAdd(const LHS &L,
- const RHS &R) {
- return BinaryOp_match<LHS, RHS, TargetOpcode::G_FADD>(L, R);
+inline BinaryOp_match<LHS, RHS, TargetOpcode::G_FADD, true>
+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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43206.133915.patch
Type: text/x-patch
Size: 1779 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180212/e8caa1b6/attachment.bin>
More information about the llvm-commits
mailing list