[llvm] r326088 - [AMDGPU] Scratch setup fix on AMDPAL gfx9+ merge shader

Tim Renouf via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 26 06:46:43 PST 2018


Author: tpr
Date: Mon Feb 26 06:46:43 2018
New Revision: 326088

URL: http://llvm.org/viewvc/llvm-project?rev=326088&view=rev
Log:
[AMDGPU] Scratch setup fix on AMDPAL gfx9+ merge shader

Summary:
With OS type AMDPAL, the scratch descriptor is hardwired to be loaded
from offset 0 of the global information table, whose low pointer is
passed in s0. For a merge shader on gfx9+, it needs to be s8 instead, as
the hardware reserves s0-s7.

Reviewers: kzhuravl

Subscribers: arsenm, nhaehnle, dstuttard, llvm-commits, t-tye, yaxunl, wdng, kzhuravl

Differential Revision: https://reviews.llvm.org/D42203

Added:
    llvm/trunk/test/CodeGen/AMDGPU/amdpal_scratch_mergedshader.ll
Modified:
    llvm/trunk/lib/Target/AMDGPU/AMDGPUSubtarget.h
    llvm/trunk/lib/Target/AMDGPU/SIFrameLowering.cpp

Modified: llvm/trunk/lib/Target/AMDGPU/AMDGPUSubtarget.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDGPUSubtarget.h?rev=326088&r1=326087&r2=326088&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPUSubtarget.h (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDGPUSubtarget.h Mon Feb 26 06:46:43 2018
@@ -845,6 +845,12 @@ public:
     return getGeneration() >= GFX9;
   }
 
+  /// \returns true if the machine has merged shaders in which s0-s7 are
+  /// reserved by the hardware and user SGPRs start at s8
+  bool hasMergedShaders() const {
+    return getGeneration() >= GFX9;
+  }
+
   /// \returns SGPR allocation granularity supported by the subtarget.
   unsigned getSGPRAllocGranule() const {
     return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());

Modified: llvm/trunk/lib/Target/AMDGPU/SIFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIFrameLowering.cpp?rev=326088&r1=326087&r2=326088&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SIFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/SIFrameLowering.cpp Mon Feb 26 06:46:43 2018
@@ -387,8 +387,21 @@ void SIFrameLowering::emitEntryFunctionS
       const MCInstrDesc &GetPC64 = TII->get(AMDGPU::S_GETPC_B64);
       BuildMI(MBB, I, DL, GetPC64, Rsrc01);
     }
+    auto GitPtrLo = AMDGPU::SGPR0; // Low GIT address passed in
+    if (ST.hasMergedShaders()) {
+      switch (MF.getFunction().getCallingConv()) {
+        case CallingConv::AMDGPU_HS:
+        case CallingConv::AMDGPU_GS:
+          // Low GIT address is passed in s8 rather than s0 for an LS+HS or
+          // ES+GS merged shader on gfx9+.
+          GitPtrLo = AMDGPU::SGPR8;
+          break;
+        default:
+          break;
+      }
+    }
     BuildMI(MBB, I, DL, SMovB32, RsrcLo)
-      .addReg(AMDGPU::SGPR0) // Low address passed in
+      .addReg(GitPtrLo)
       .addReg(ScratchRsrcReg, RegState::ImplicitDefine);
 
     // We now have the GIT ptr - now get the scratch descriptor from the entry

Added: llvm/trunk/test/CodeGen/AMDGPU/amdpal_scratch_mergedshader.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/amdpal_scratch_mergedshader.ll?rev=326088&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/amdpal_scratch_mergedshader.ll (added)
+++ llvm/trunk/test/CodeGen/AMDGPU/amdpal_scratch_mergedshader.ll Mon Feb 26 06:46:43 2018
@@ -0,0 +1,34 @@
+; RUN: llc -mtriple=amdgcn--amdpal -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=GFX9 -enable-var-scope %s
+
+; On gfx9 and later, a HS is a merged shader, in which s0-s7 are reserved by the
+; hardware, so the PAL puts the GIT (global information table) in s8 rather
+; than s0.
+
+; GCN-LABEL: {{^}}_amdgpu_hs_main:
+; GCN: s_getpc_b64 s{{\[}}[[GITPTR:[0-9]+]]:
+; PREGFX9: s_mov_b32 s[[GITPTR]], s0
+; GFX9: s_mov_b32 s[[GITPTR]], s8
+
+define amdgpu_hs void @_amdgpu_hs_main(i32 inreg %arg, i32 inreg %arg1, i32 inreg %arg2, i32 inreg %arg3, i32 inreg %arg4, i32 inreg %arg5, i32 inreg %arg6, i32 inreg %arg7, <6 x i32> inreg %arg8) {
+.entry:
+  %__llpc_global_proxy_7.i = alloca [3 x <4 x float>], align 16, addrspace(5)
+  %tmp = icmp ult i32 undef, undef
+  br i1 %tmp, label %.beginls, label %.endls
+
+.beginls:                                         ; preds = %.entry
+  %tmp15 = extractelement <6 x i32> %arg8, i32 3
+  %.0.vec.insert.i = insertelement <2 x i32> undef, i32 %tmp15, i32 0
+  %.4.vec.insert.i = shufflevector <2 x i32> %.0.vec.insert.i, <2 x i32> undef, <2 x i32> <i32 0, i32 3>
+  %tmp16 = bitcast <2 x i32> %.4.vec.insert.i to i64
+  br label %.endls
+
+.endls:                                           ; preds = %.beginls, %.entry
+  %.fca.2.gep120.i = getelementptr inbounds [3 x <4 x float>], [3 x <4 x float>] addrspace(5)* %__llpc_global_proxy_7.i, i64 0, i64 2
+  store <4 x float> <float 9.000000e+00, float 1.000000e+01, float 1.100000e+01, float 1.200000e+01>, <4 x float> addrspace(5)* %.fca.2.gep120.i, align 16
+  br label %bb
+
+bb:                                               ; preds = %bb, %.endls
+  %lsr.iv182 = phi [3 x <4 x float>] addrspace(5)* [ undef, %bb ], [ %__llpc_global_proxy_7.i, %.endls ]
+  %scevgep183 = getelementptr [3 x <4 x float>], [3 x <4 x float>] addrspace(5)* %lsr.iv182, i32 0, i32 1
+  br label %bb
+}




More information about the llvm-commits mailing list