GlobalISel: Add matcher for G_LSHR

This commit is contained in:
Matt Arsenault 2020-02-15 16:46:04 -05:00 committed by Matt Arsenault
parent 10fe28f702
commit 529fcd14cb
2 changed files with 16 additions and 0 deletions

View File

@ -241,6 +241,12 @@ inline BinaryOp_match<LHS, RHS, TargetOpcode::G_OR, true> m_GOr(const LHS &L,
return BinaryOp_match<LHS, RHS, TargetOpcode::G_OR, true>(L, R);
}
template <typename LHS, typename RHS>
inline BinaryOp_match<LHS, RHS, TargetOpcode::G_LSHR, false>
m_GLShr(const LHS &L, const RHS &R) {
return BinaryOp_match<LHS, RHS, TargetOpcode::G_LSHR, false>(L, R);
}
// Helper for unary instructions (G_[ZSA]EXT/G_TRUNC) etc
template <typename SrcTy, unsigned Opcode> struct UnaryOp_match {
SrcTy L;

View File

@ -45,6 +45,7 @@ TEST_F(GISelMITest, MatchBinaryOp) {
setUp();
if (!TM)
return;
LLT s32 = LLT::scalar(32);
LLT s64 = LLT::scalar(64);
auto MIBAdd = B.buildAdd(s64, Copies[0], Copies[1]);
// Test case for no bind.
@ -127,6 +128,15 @@ TEST_F(GISelMITest, MatchBinaryOp) {
EXPECT_TRUE(match);
EXPECT_EQ(Src0, Copies[0]);
EXPECT_EQ(Src1, Copies[1]);
// Match lshr, and make sure a different shift amount type works.
auto TruncCopy1 = B.buildTrunc(s32, Copies[1]);
auto LShr = B.buildLShr(s64, Copies[0], TruncCopy1);
match = mi_match(LShr.getReg(0), *MRI,
m_GLShr(m_Reg(Src0), m_Reg(Src1)));
EXPECT_TRUE(match);
EXPECT_EQ(Src0, Copies[0]);
EXPECT_EQ(Src1, TruncCopy1.getReg(0));
}
TEST_F(GISelMITest, MatchICmp) {