Skip to content

Commit ddcb0aa

Browse files
author
Jessica Paquette
committed
[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
1 parent 175288a commit ddcb0aa

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ m_GAdd(const LHS &L, const RHS &R) {
220220
return BinaryOp_match<LHS, RHS, TargetOpcode::G_ADD, true>(L, R);
221221
}
222222

223+
template <typename LHS, typename RHS>
224+
inline BinaryOp_match<LHS, RHS, TargetOpcode::G_PTR_ADD, true>
225+
m_GPtrAdd(const LHS &L, const RHS &R) {
226+
return BinaryOp_match<LHS, RHS, TargetOpcode::G_PTR_ADD, true>(L, R);
227+
}
228+
223229
template <typename LHS, typename RHS>
224230
inline BinaryOp_match<LHS, RHS, TargetOpcode::G_SUB> m_GSub(const LHS &L,
225231
const RHS &R) {

llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ TEST_F(AArch64GISelMITest, MatchBinaryOp) {
4747
return;
4848
LLT s32 = LLT::scalar(32);
4949
LLT s64 = LLT::scalar(64);
50+
LLT p0 = LLT::pointer(0, 64);
5051
auto MIBAdd = B.buildAdd(s64, Copies[0], Copies[1]);
5152
// Test case for no bind.
5253
bool match =
@@ -145,6 +146,13 @@ TEST_F(AArch64GISelMITest, MatchBinaryOp) {
145146
EXPECT_TRUE(match);
146147
EXPECT_EQ(Src0, Copies[0]);
147148
EXPECT_EQ(Src1, TruncCopy1.getReg(0));
149+
150+
// Build a G_PTR_ADD and check that we can match it.
151+
auto PtrAdd = B.buildPtrAdd(p0, {B.buildUndef(p0)}, Copies[0]);
152+
match = mi_match(PtrAdd.getReg(0), *MRI, m_GPtrAdd(m_Reg(Src0), m_Reg(Src1)));
153+
EXPECT_TRUE(match);
154+
EXPECT_EQ(Src0, PtrAdd->getOperand(1).getReg());
155+
EXPECT_EQ(Src1, Copies[0]);
148156
}
149157

150158
TEST_F(AArch64GISelMITest, MatchICmp) {

0 commit comments

Comments
 (0)