Skip to content

Commit 323db5d

Browse files
committed
GlobalISel: Add matcher for G_LSHR
1 parent 1e926a9 commit 323db5d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ inline BinaryOp_match<LHS, RHS, TargetOpcode::G_OR, true> m_GOr(const LHS &L,
241241
return BinaryOp_match<LHS, RHS, TargetOpcode::G_OR, true>(L, R);
242242
}
243243

244+
template <typename LHS, typename RHS>
245+
inline BinaryOp_match<LHS, RHS, TargetOpcode::G_LSHR, false>
246+
m_GLShr(const LHS &L, const RHS &R) {
247+
return BinaryOp_match<LHS, RHS, TargetOpcode::G_LSHR, false>(L, R);
248+
}
249+
244250
// Helper for unary instructions (G_[ZSA]EXT/G_TRUNC) etc
245251
template <typename SrcTy, unsigned Opcode> struct UnaryOp_match {
246252
SrcTy L;

llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ TEST_F(GISelMITest, MatchBinaryOp) {
4545
setUp();
4646
if (!TM)
4747
return;
48+
LLT s32 = LLT::scalar(32);
4849
LLT s64 = LLT::scalar(64);
4950
auto MIBAdd = B.buildAdd(s64, Copies[0], Copies[1]);
5051
// Test case for no bind.
@@ -127,6 +128,15 @@ TEST_F(GISelMITest, MatchBinaryOp) {
127128
EXPECT_TRUE(match);
128129
EXPECT_EQ(Src0, Copies[0]);
129130
EXPECT_EQ(Src1, Copies[1]);
131+
132+
// Match lshr, and make sure a different shift amount type works.
133+
auto TruncCopy1 = B.buildTrunc(s32, Copies[1]);
134+
auto LShr = B.buildLShr(s64, Copies[0], TruncCopy1);
135+
match = mi_match(LShr.getReg(0), *MRI,
136+
m_GLShr(m_Reg(Src0), m_Reg(Src1)));
137+
EXPECT_TRUE(match);
138+
EXPECT_EQ(Src0, Copies[0]);
139+
EXPECT_EQ(Src1, TruncCopy1.getReg(0));
130140
}
131141

132142
TEST_F(GISelMITest, MatchICmp) {

0 commit comments

Comments
 (0)