GlobalISel: Add matcher for G_SHL
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Sun, 29 Mar 2020 17:07:43 +0000 (13:07 -0400)
committerMatt Arsenault <arsenm2@gmail.com>
Sun, 29 Mar 2020 18:03:07 +0000 (14:03 -0400)
llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp

index 65b1948..1fae635 100644 (file)
@@ -242,6 +242,12 @@ inline BinaryOp_match<LHS, RHS, TargetOpcode::G_OR, true> m_GOr(const LHS &L,
 }
 
 template <typename LHS, typename RHS>
+inline BinaryOp_match<LHS, RHS, TargetOpcode::G_SHL, false>
+m_GShl(const LHS &L, const RHS &R) {
+  return BinaryOp_match<LHS, RHS, TargetOpcode::G_SHL, false>(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);
index 172eca4..6a54084 100644 (file)
@@ -137,6 +137,14 @@ TEST_F(AArch64GISelMITest, MatchBinaryOp) {
   EXPECT_TRUE(match);
   EXPECT_EQ(Src0, Copies[0]);
   EXPECT_EQ(Src1, TruncCopy1.getReg(0));
+
+  // Match shl, and make sure a different shift amount type works.
+  auto Shl = B.buildShl(s64, Copies[0], TruncCopy1);
+  match = mi_match(Shl.getReg(0), *MRI,
+                   m_GShl(m_Reg(Src0), m_Reg(Src1)));
+  EXPECT_TRUE(match);
+  EXPECT_EQ(Src0, Copies[0]);
+  EXPECT_EQ(Src1, TruncCopy1.getReg(0));
 }
 
 TEST_F(AArch64GISelMITest, MatchICmp) {