[GISel]: Add Pattern Matcher for G_FMUL.

https://reviews.llvm.org/D43206

llvm-svn: 325044
This commit is contained in:
Aditya Nandakumar 2018-02-13 20:09:13 +00:00
parent 413495fbe7
commit 6250b18831
2 changed files with 15 additions and 0 deletions

View 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;

View 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) {