[llvm] ddcb0aa - [MIPatternMatch] Add matcher for G_PTR_ADD
Jessica Paquette via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 12 15:23:10 PST 2021
Author: Jessica Paquette
Date: 2021-01-12T15:21:19-08:00
New Revision: ddcb0aae8b0dd87414105d264d1ee9eac9567476
URL: https://github.com/llvm/llvm-project/commit/ddcb0aae8b0dd87414105d264d1ee9eac9567476
DIFF: https://github.com/llvm/llvm-project/commit/ddcb0aae8b0dd87414105d264d1ee9eac9567476.diff
LOG: [MIPatternMatch] Add matcher for G_PTR_ADD
Add a matcher which recognizes G_PTR_ADD and add a test.
Differential Revision: https://reviews.llvm.org/D94348
Added:
Modified:
llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h b/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
index 427906db6696..ed93dae24c05 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
@@ -220,6 +220,12 @@ m_GAdd(const LHS &L, const RHS &R) {
return BinaryOp_match<LHS, RHS, TargetOpcode::G_ADD, true>(L, R);
}
+template <typename LHS, typename RHS>
+inline BinaryOp_match<LHS, RHS, TargetOpcode::G_PTR_ADD, true>
+m_GPtrAdd(const LHS &L, const RHS &R) {
+ return BinaryOp_match<LHS, RHS, TargetOpcode::G_PTR_ADD, true>(L, R);
+}
+
template <typename LHS, typename RHS>
inline BinaryOp_match<LHS, RHS, TargetOpcode::G_SUB> m_GSub(const LHS &L,
const RHS &R) {
diff --git a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
index f95b19f22e7b..a63a34f91545 100644
--- a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
@@ -47,6 +47,7 @@ TEST_F(AArch64GISelMITest, MatchBinaryOp) {
return;
LLT s32 = LLT::scalar(32);
LLT s64 = LLT::scalar(64);
+ LLT p0 = LLT::pointer(0, 64);
auto MIBAdd = B.buildAdd(s64, Copies[0], Copies[1]);
// Test case for no bind.
bool match =
@@ -145,6 +146,13 @@ TEST_F(AArch64GISelMITest, MatchBinaryOp) {
EXPECT_TRUE(match);
EXPECT_EQ(Src0, Copies[0]);
EXPECT_EQ(Src1, TruncCopy1.getReg(0));
+
+ // Build a G_PTR_ADD and check that we can match it.
+ auto PtrAdd = B.buildPtrAdd(p0, {B.buildUndef(p0)}, Copies[0]);
+ match = mi_match(PtrAdd.getReg(0), *MRI, m_GPtrAdd(m_Reg(Src0), m_Reg(Src1)));
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, PtrAdd->getOperand(1).getReg());
+ EXPECT_EQ(Src1, Copies[0]);
}
TEST_F(AArch64GISelMITest, MatchICmp) {
More information about the llvm-commits
mailing list