Skip to content

Conversation

ritter-x2a
Copy link
Member

This is used in a bunch of memory-related transforms.

For SWDEV-516125.

@llvmbot
Copy link
Member

llvmbot commented Jun 4, 2025

@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-backend-amdgpu

Author: Fabian Ritter (ritter-x2a)

Changes

This is used in a bunch of memory-related transforms.

For SWDEV-516125.


Full diff: https://github.com/llvm/llvm-project/pull/142778.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp (+3-3)
  • (modified) llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll (+8-20)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
index f2ab88851b780..da92aaa860b2b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
@@ -231,6 +231,7 @@ static BaseIndexOffset matchLSNode(const LSBaseSDNode *N,
         }
       break;
     case ISD::ADD:
+    case ISD::PTRADD:
       if (auto *C = dyn_cast<ConstantSDNode>(Base->getOperand(1))) {
         Offset += C->getSExtValue();
         Base = DAG.getTargetLoweringInfo().unwrapAddress(Base->getOperand(0));
@@ -259,7 +260,7 @@ static BaseIndexOffset matchLSNode(const LSBaseSDNode *N,
     break;
   }
 
-  if (Base->getOpcode() == ISD::ADD) {
+  if (Base->isAnyAdd()) {
     // TODO: The following code appears to be needless as it just
     //       bails on some Ptrs early, reducing the cases where we
     //       find equivalence. We should be able to remove this.
@@ -282,8 +283,7 @@ static BaseIndexOffset matchLSNode(const LSBaseSDNode *N,
     }
 
     // Check if Index Offset pattern
-    if (Index->getOpcode() != ISD::ADD ||
-        !isa<ConstantSDNode>(Index->getOperand(1)))
+    if (!Index->isAnyAdd() || !isa<ConstantSDNode>(Index->getOperand(1)))
       return BaseIndexOffset(PotentialBase, Index, Offset, IsIndexSignExt);
 
     Offset += cast<ConstantSDNode>(Index->getOperand(1))->getSExtValue();
diff --git a/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll b/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll
index bce59307446ce..1069339774894 100644
--- a/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll
+++ b/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll
@@ -136,26 +136,14 @@ declare noalias ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
 ; Taken from memcpy-param-combinations.ll, tests PTRADD handling in
 ; SelectionDAGAddressAnalysis.
 define void @memcpy_p1_p4_sz16_align_1_1(ptr addrspace(1) align 1 %dst, ptr addrspace(4) align 1 readonly %src) {
-; GFX942_PTRADD-LABEL: memcpy_p1_p4_sz16_align_1_1:
-; GFX942_PTRADD:       ; %bb.0: ; %entry
-; GFX942_PTRADD-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX942_PTRADD-NEXT:    global_load_dwordx2 v[4:5], v[2:3], off
-; GFX942_PTRADD-NEXT:    s_waitcnt vmcnt(0)
-; GFX942_PTRADD-NEXT:    global_store_dwordx2 v[0:1], v[4:5], off
-; GFX942_PTRADD-NEXT:    global_load_dwordx2 v[2:3], v[2:3], off offset:8
-; GFX942_PTRADD-NEXT:    s_waitcnt vmcnt(0)
-; GFX942_PTRADD-NEXT:    global_store_dwordx2 v[0:1], v[2:3], off offset:8
-; GFX942_PTRADD-NEXT:    s_waitcnt vmcnt(0)
-; GFX942_PTRADD-NEXT:    s_setpc_b64 s[30:31]
-;
-; GFX942_LEGACY-LABEL: memcpy_p1_p4_sz16_align_1_1:
-; GFX942_LEGACY:       ; %bb.0: ; %entry
-; GFX942_LEGACY-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX942_LEGACY-NEXT:    global_load_dwordx4 v[2:5], v[2:3], off
-; GFX942_LEGACY-NEXT:    s_waitcnt vmcnt(0)
-; GFX942_LEGACY-NEXT:    global_store_dwordx4 v[0:1], v[2:5], off
-; GFX942_LEGACY-NEXT:    s_waitcnt vmcnt(0)
-; GFX942_LEGACY-NEXT:    s_setpc_b64 s[30:31]
+; GFX942-LABEL: memcpy_p1_p4_sz16_align_1_1:
+; GFX942:       ; %bb.0: ; %entry
+; GFX942-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX942-NEXT:    global_load_dwordx4 v[2:5], v[2:3], off
+; GFX942-NEXT:    s_waitcnt vmcnt(0)
+; GFX942-NEXT:    global_store_dwordx4 v[0:1], v[2:5], off
+; GFX942-NEXT:    s_waitcnt vmcnt(0)
+; GFX942-NEXT:    s_setpc_b64 s[30:31]
 entry:
   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)
   ret void

@ritter-x2a ritter-x2a marked this pull request as ready for review June 4, 2025 13:55
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_add_test_for_isd_ptradd_handling_in_selectiondagaddressanalysis branch from 1fe91cb to b1fc342 Compare June 5, 2025 09:36
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_handle_isd_ptradd_in_selectiondagaddressanalysis branch 2 times, most recently from b961fc0 to 3199b6a Compare June 6, 2025 07:28
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_add_test_for_isd_ptradd_handling_in_selectiondagaddressanalysis branch 2 times, most recently from 5537fe6 to 14a92fd Compare June 10, 2025 10:01
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_handle_isd_ptradd_in_selectiondagaddressanalysis branch from 3199b6a to ecde1e1 Compare June 10, 2025 10:01
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_add_test_for_isd_ptradd_handling_in_selectiondagaddressanalysis branch from 14a92fd to df620d7 Compare June 13, 2025 09:02
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_handle_isd_ptradd_in_selectiondagaddressanalysis branch from ecde1e1 to c959592 Compare June 13, 2025 09:02
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_add_test_for_isd_ptradd_handling_in_selectiondagaddressanalysis branch from df620d7 to c0eab93 Compare June 13, 2025 12:06
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_handle_isd_ptradd_in_selectiondagaddressanalysis branch 2 times, most recently from 988d356 to 9e215a2 Compare June 13, 2025 12:12
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_add_test_for_isd_ptradd_handling_in_selectiondagaddressanalysis branch from c0eab93 to 5df6cfa Compare June 13, 2025 12:12
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_handle_isd_ptradd_in_selectiondagaddressanalysis branch from 9e215a2 to b212174 Compare June 13, 2025 13:28
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_add_test_for_isd_ptradd_handling_in_selectiondagaddressanalysis branch 2 times, most recently from a7d0f6b to e8eccce Compare June 13, 2025 14:03
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_handle_isd_ptradd_in_selectiondagaddressanalysis branch from b212174 to af2d3ea Compare June 13, 2025 14:03
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_handle_isd_ptradd_in_selectiondagaddressanalysis branch from af2d3ea to 86aa666 Compare June 23, 2025 13:37
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_add_test_for_isd_ptradd_handling_in_selectiondagaddressanalysis branch from e8eccce to 510b307 Compare June 23, 2025 13:37
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_add_test_for_isd_ptradd_handling_in_selectiondagaddressanalysis branch from 510b307 to ade6820 Compare June 24, 2025 06:46
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_handle_isd_ptradd_in_selectiondagaddressanalysis branch from 86aa666 to d6f5395 Compare June 24, 2025 06:47
Copy link
Member Author

ritter-x2a commented Jun 26, 2025

Merge activity

  • Jun 26, 7:27 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 26, 7:44 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 26, 7:47 AM UTC: @ritter-x2a merged this pull request with Graphite.

@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_add_test_for_isd_ptradd_handling_in_selectiondagaddressanalysis branch from ade6820 to a83dc2c Compare June 26, 2025 07:40
Base automatically changed from users/ritter-x2a/06-04-_amdgpu_sdag_add_test_for_isd_ptradd_handling_in_selectiondagaddressanalysis to main June 26, 2025 07:43
This is used in a bunch of memory-related transforms.

For SWDEV-516125.
@ritter-x2a ritter-x2a force-pushed the users/ritter-x2a/06-04-_amdgpu_sdag_handle_isd_ptradd_in_selectiondagaddressanalysis branch from d6f5395 to b9f3353 Compare June 26, 2025 07:44
@ritter-x2a ritter-x2a merged commit c225d6d into main Jun 26, 2025
5 of 7 checks passed
@ritter-x2a ritter-x2a deleted the users/ritter-x2a/06-04-_amdgpu_sdag_handle_isd_ptradd_in_selectiondagaddressanalysis branch June 26, 2025 07:47
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
…m#142778)

This is used in a bunch of memory-related transforms.

For SWDEV-516125.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants