[llvm] [AMDGPU] iglp.opt does not clobber memory operands (PR #126976)

Jeffrey Byrnes via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 12 14:10:58 PST 2025


https://github.com/jrbyrnes updated https://github.com/llvm/llvm-project/pull/126976

>From c688773dcf2a4caf87e9c4b97ed5b0ccbee4cf0c Mon Sep 17 00:00:00 2001
From: Jeffrey Byrnes <Jeffrey.Byrnes at amd.com>
Date: Wed, 12 Feb 2025 13:38:52 -0800
Subject: [PATCH 1/2] [AMDGPU] iglp.opt does not clobber memory operands

Change-Id: I2a35580b3935a1578d537e869ac17b2a0052eb9a
---
 llvm/lib/Target/AMDGPU/AMDGPUMemoryUtils.cpp |  1 +
 llvm/test/CodeGen/AMDGPU/iglp-no-clobber.ll  | 39 ++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 llvm/test/CodeGen/AMDGPU/iglp-no-clobber.ll

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMemoryUtils.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMemoryUtils.cpp
index a5bfdb7bf6eac..57289c3e8bbf4 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMemoryUtils.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMemoryUtils.cpp
@@ -367,6 +367,7 @@ bool isReallyAClobber(const Value *Ptr, MemoryDef *Def, AAResults *AA) {
     case Intrinsic::amdgcn_wave_barrier:
     case Intrinsic::amdgcn_sched_barrier:
     case Intrinsic::amdgcn_sched_group_barrier:
+    case Intrinsic::amdgcn_iglp_opt:
       return false;
     default:
       break;
diff --git a/llvm/test/CodeGen/AMDGPU/iglp-no-clobber.ll b/llvm/test/CodeGen/AMDGPU/iglp-no-clobber.ll
new file mode 100644
index 0000000000000..6346f632e537f
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/iglp-no-clobber.ll
@@ -0,0 +1,39 @@
+; RUN: llc -mtriple=amdgcn -mcpu=gfx942 --stop-after=si-fix-sgpr-copies < %s | FileCheck %s
+
+; iglp.opt should not be flagged as clobbering the memory operand for the global_load, and we should be able to
+; lower into the scalar version (i.e. should not need to lower into vector version with waterfall loop)
+; CHECK-NOT: WATERFALL
+
+define amdgpu_kernel void @_attn_forward_fp8e5_128x32x64_BW128(ptr addrspace(1) %in, ptr addrspace(3) %out) {
+.lr.ph:
+  br label %1
+
+1:                                                ; preds = %1, %.lr.ph
+  %addr = phi ptr addrspace(1) [ null, %.lr.ph ], [ %gep, %1 ]
+  %offset = phi i64 [ 0, %.lr.ph ], [ %nextOff, %1 ]
+  %inc = phi i32 [0, %.lr.ph], [ %incCond, %1 ] 
+  %rsrc = tail call ptr addrspace(8) @llvm.amdgcn.make.buffer.rsrc.p1(ptr addrspace(1) %addr, i16 0, i32 0, i32 0)
+  %load = tail call <2 x i32> @llvm.amdgcn.raw.ptr.buffer.load.v2i32(ptr addrspace(8) %rsrc, i32 0, i32 0, i32 0)
+  %load.bc = bitcast <2 x i32> %load to <8 x i8>
+  %load.elem = extractelement <8 x i8> %load.bc, i64 0
+  tail call void @llvm.amdgcn.iglp.opt(i32 0)
+  %vec = insertelement <4 x i8> zeroinitializer, i8 %load.elem, i64 0
+  %vec.bc = bitcast <4 x i8> %vec to <2 x half>
+  %shuff = shufflevector <2 x half> %vec.bc, <2 x half> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+  %gep = getelementptr i8, ptr addrspace(1) %in, i64 %offset
+  %unmaskedload49 = load <1 x i64>, ptr addrspace(1) null, align 8
+  %nextOff = extractelement <1 x i64> %unmaskedload49, i64 0
+  %incCond = add i32 %inc, 1
+  %cond = icmp eq i32 %incCond, 32
+  br i1 %cond, label %2, label %1 
+
+2:
+  store <4 x half> %shuff, ptr addrspace(3) %out, align 8
+  ret void
+}
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare ptr addrspace(8) @llvm.amdgcn.make.buffer.rsrc.p1(ptr addrspace(1) readnone, i16, i32, i32) #0
+
+; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: read)
+declare <2 x i32> @llvm.amdgcn.raw.ptr.buffer.load.v2i32(ptr addrspace(8) nocapture readonly, i32, i32, i32 immarg) #1
\ No newline at end of file

>From 6ea351c0421f153f1fa11b2565aa74a6cb9ddbe7 Mon Sep 17 00:00:00 2001
From: Jeffrey Byrnes <Jeffrey.Byrnes at amd.com>
Date: Wed, 12 Feb 2025 14:10:03 -0800
Subject: [PATCH 2/2] Add newline to test

Change-Id: Id2ffadfb30dd2aa0edf5d01507c98994c3e41876
---
 llvm/test/CodeGen/AMDGPU/iglp-no-clobber.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/CodeGen/AMDGPU/iglp-no-clobber.ll b/llvm/test/CodeGen/AMDGPU/iglp-no-clobber.ll
index 6346f632e537f..200d68b2dc1a9 100644
--- a/llvm/test/CodeGen/AMDGPU/iglp-no-clobber.ll
+++ b/llvm/test/CodeGen/AMDGPU/iglp-no-clobber.ll
@@ -36,4 +36,4 @@ define amdgpu_kernel void @_attn_forward_fp8e5_128x32x64_BW128(ptr addrspace(1)
 declare ptr addrspace(8) @llvm.amdgcn.make.buffer.rsrc.p1(ptr addrspace(1) readnone, i16, i32, i32) #0
 
 ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: read)
-declare <2 x i32> @llvm.amdgcn.raw.ptr.buffer.load.v2i32(ptr addrspace(8) nocapture readonly, i32, i32, i32 immarg) #1
\ No newline at end of file
+declare <2 x i32> @llvm.amdgcn.raw.ptr.buffer.load.v2i32(ptr addrspace(8) nocapture readonly, i32, i32, i32 immarg) #1



More information about the llvm-commits mailing list