Skip to content

Commit c959592

Browse files
committed
[AMDGPU][SDAG] Handle ISD::PTRADD in SelectionDAGAddressAnalysis
This is used in a bunch of memory-related transforms. For SWDEV-516125.
1 parent df620d7 commit c959592

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ static BaseIndexOffset matchLSNode(const LSBaseSDNode *N,
231231
}
232232
break;
233233
case ISD::ADD:
234+
case ISD::PTRADD:
234235
if (auto *C = dyn_cast<ConstantSDNode>(Base->getOperand(1))) {
235236
Offset += C->getSExtValue();
236237
Base = DAG.getTargetLoweringInfo().unwrapAddress(Base->getOperand(0));
@@ -259,7 +260,7 @@ static BaseIndexOffset matchLSNode(const LSBaseSDNode *N,
259260
break;
260261
}
261262

262-
if (Base->getOpcode() == ISD::ADD) {
263+
if (Base->isAnyAdd()) {
263264
// TODO: The following code appears to be needless as it just
264265
// bails on some Ptrs early, reducing the cases where we
265266
// find equivalence. We should be able to remove this.
@@ -282,8 +283,7 @@ static BaseIndexOffset matchLSNode(const LSBaseSDNode *N,
282283
}
283284

284285
// Check if Index Offset pattern
285-
if (Index->getOpcode() != ISD::ADD ||
286-
!isa<ConstantSDNode>(Index->getOperand(1)))
286+
if (!Index->isAnyAdd() || !isa<ConstantSDNode>(Index->getOperand(1)))
287287
return BaseIndexOffset(PotentialBase, Index, Offset, IsIndexSignExt);
288288

289289
Offset += cast<ConstantSDNode>(Index->getOperand(1))->getSExtValue();

llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,14 @@ define amdgpu_kernel void @llvm_amdgcn_queue_ptr(ptr addrspace(1) %ptr) #0 {
130130
; Taken from memcpy-param-combinations.ll, tests PTRADD handling in
131131
; SelectionDAGAddressAnalysis.
132132
define void @memcpy_p1_p4_sz16_align_1_1(ptr addrspace(1) align 1 %dst, ptr addrspace(4) align 1 readonly %src) {
133-
; GFX942_PTRADD-LABEL: memcpy_p1_p4_sz16_align_1_1:
134-
; GFX942_PTRADD: ; %bb.0: ; %entry
135-
; GFX942_PTRADD-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
136-
; GFX942_PTRADD-NEXT: global_load_dwordx2 v[4:5], v[2:3], off
137-
; GFX942_PTRADD-NEXT: s_waitcnt vmcnt(0)
138-
; GFX942_PTRADD-NEXT: global_store_dwordx2 v[0:1], v[4:5], off
139-
; GFX942_PTRADD-NEXT: global_load_dwordx2 v[2:3], v[2:3], off offset:8
140-
; GFX942_PTRADD-NEXT: s_waitcnt vmcnt(0)
141-
; GFX942_PTRADD-NEXT: global_store_dwordx2 v[0:1], v[2:3], off offset:8
142-
; GFX942_PTRADD-NEXT: s_waitcnt vmcnt(0)
143-
; GFX942_PTRADD-NEXT: s_setpc_b64 s[30:31]
144-
;
145-
; GFX942_LEGACY-LABEL: memcpy_p1_p4_sz16_align_1_1:
146-
; GFX942_LEGACY: ; %bb.0: ; %entry
147-
; GFX942_LEGACY-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
148-
; GFX942_LEGACY-NEXT: global_load_dwordx4 v[2:5], v[2:3], off
149-
; GFX942_LEGACY-NEXT: s_waitcnt vmcnt(0)
150-
; GFX942_LEGACY-NEXT: global_store_dwordx4 v[0:1], v[2:5], off
151-
; GFX942_LEGACY-NEXT: s_waitcnt vmcnt(0)
152-
; GFX942_LEGACY-NEXT: s_setpc_b64 s[30:31]
133+
; GFX942-LABEL: memcpy_p1_p4_sz16_align_1_1:
134+
; GFX942: ; %bb.0: ; %entry
135+
; GFX942-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
136+
; GFX942-NEXT: global_load_dwordx4 v[2:5], v[2:3], off
137+
; GFX942-NEXT: s_waitcnt vmcnt(0)
138+
; GFX942-NEXT: global_store_dwordx4 v[0:1], v[2:5], off
139+
; GFX942-NEXT: s_waitcnt vmcnt(0)
140+
; GFX942-NEXT: s_setpc_b64 s[30:31]
153141
entry:
154142
tail call void @llvm.memcpy.p1.p4.i64(ptr addrspace(1) noundef nonnull align 1 %dst, ptr addrspace(4) noundef nonnull align 1 %src, i64 16, i1 false)
155143
ret void

0 commit comments

Comments
 (0)