1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[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
This commit is contained in:
Aditya Nandakumar 2018-05-31 19:30:01 +00:00
parent 11b19ef172
commit 230bfd5b60
2 changed files with 25 additions and 0 deletions

View File

@ -221,6 +221,12 @@ m_GFMul(const LHS &L, const RHS &R) {
return BinaryOp_match<LHS, RHS, TargetOpcode::G_FMUL, true>(L, R);
}
template <typename LHS, typename RHS>
inline BinaryOp_match<LHS, RHS, TargetOpcode::G_FSUB, false>
m_GFSub(const LHS &L, const RHS &R) {
return BinaryOp_match<LHS, RHS, TargetOpcode::G_FSUB, false>(L, R);
}
template <typename LHS, typename RHS>
inline BinaryOp_match<LHS, RHS, TargetOpcode::G_AND, true>
m_GAnd(const LHS &L, const RHS &R) {
@ -304,6 +310,11 @@ inline UnaryOp_match<SrcTy, TargetOpcode::G_FABS> m_GFabs(const SrcTy &Src) {
return UnaryOp_match<SrcTy, TargetOpcode::G_FABS>(Src);
}
template <typename SrcTy>
inline UnaryOp_match<SrcTy, TargetOpcode::G_FNEG> m_GFNeg(const SrcTy &Src) {
return UnaryOp_match<SrcTy, TargetOpcode::G_FNEG>(Src);
}
template <typename SrcTy>
inline UnaryOp_match<SrcTy, TargetOpcode::COPY> m_Copy(SrcTy &&Src) {
return UnaryOp_match<SrcTy, TargetOpcode::COPY>(std::forward<SrcTy>(Src));

View File

@ -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());