[llvm] 0397dca - [AMDGPU] Fix crash with sgpr spills to vgpr disabled

Austin Kerbow via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 1 08:42:06 PST 2021


Author: Austin Kerbow
Date: 2021-02-01T08:35:25-08:00
New Revision: 0397dca0214ab50de41ac6c3d432aab93ff75c60

URL: https://github.com/llvm/llvm-project/commit/0397dca0214ab50de41ac6c3d432aab93ff75c60
DIFF: https://github.com/llvm/llvm-project/commit/0397dca0214ab50de41ac6c3d432aab93ff75c60.diff

LOG: [AMDGPU] Fix crash with sgpr spills to vgpr disabled

This would assert with amdgpu-spill-sgpr-to-vgpr disabled when trying to
spill the FP.

Fixes: SWDEV-262704

Reviewed By: RamNalamothu

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

Added: 
    llvm/test/CodeGen/AMDGPU/frame-setup-without-sgpr-to-vgpr-spills.ll

Modified: 
    llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
    llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp b/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
index 0398d27756db..a5de19a02b7b 100644
--- a/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
@@ -105,7 +105,7 @@ static void getVGPRSpillLaneOrTempRegister(MachineFunction &MF,
     int NewFI = FrameInfo.CreateStackObject(4, Align(4), true, nullptr,
                                             TargetStackID::SGPRSpill);
 
-    if (MFI->allocateSGPRSpillToVGPR(MF, NewFI)) {
+    if (TRI->spillSGPRToVGPR() && MFI->allocateSGPRSpillToVGPR(MF, NewFI)) {
       // 3: There's no free lane to spill, and no free register to save FP/BP,
       // so we're forced to spill another VGPR to use for the spill.
       FrameIndex = NewFI;

diff  --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 839437b5e3f8..31cdcfba76f3 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -11487,8 +11487,9 @@ void SITargetLowering::finalizeLowering(MachineFunction &MF) const {
   // Allocate a VGPR for future SGPR Spill if
   // "amdgpu-reserve-vgpr-for-sgpr-spill" option is used
   // FIXME: We won't need this hack if we split SGPR allocation from VGPR
-  if (VGPRReserveforSGPRSpill && !Info->VGPRReservedForSGPRSpill &&
-      !Info->isEntryFunction() && MF.getFrameInfo().hasStackObjects())
+  if (VGPRReserveforSGPRSpill && TRI->spillSGPRToVGPR() &&
+      !Info->VGPRReservedForSGPRSpill && !Info->isEntryFunction() &&
+      MF.getFrameInfo().hasStackObjects())
     Info->reserveVGPRforSGPRSpills(MF);
 }
 

diff  --git a/llvm/test/CodeGen/AMDGPU/frame-setup-without-sgpr-to-vgpr-spills.ll b/llvm/test/CodeGen/AMDGPU/frame-setup-without-sgpr-to-vgpr-spills.ll
new file mode 100644
index 000000000000..f1731c8f9474
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/frame-setup-without-sgpr-to-vgpr-spills.ll
@@ -0,0 +1,31 @@
+; RUN: llc -march=amdgcn -mcpu=gfx900 -verify-machineinstrs -amdgpu-spill-sgpr-to-vgpr=true < %s | FileCheck -check-prefixes=GCN,SPILL-TO-VGPR %s
+; RUN: llc -march=amdgcn -mcpu=gfx900 -verify-machineinstrs -amdgpu-spill-sgpr-to-vgpr=false < %s | FileCheck -check-prefixes=GCN,NO-SPILL-TO-VGPR %s
+
+; Check frame setup where SGPR spills to VGPRs are disabled or enabled.
+
+declare hidden void @external_void_func_void() #0
+
+; GCN-LABEL: {{^}}callee_with_stack_and_call:
+; SPILL-TO-VGPR:      buffer_store_dword v40, off, s[0:3], s32 offset:4 ; 4-byte Folded Spill
+; SPILL-TO-VGPR:      v_writelane_b32 v40, s33, 2
+; NO-SPILL-TO-VGPR:   v_mov_b32_e32 v0, s33
+; NO-SPILL-TO-VGPR:   buffer_store_dword v0, off, s[0:3], s32 offset:12 ; 4-byte Folded Spill
+
+; GCN:                s_swappc_b64 s[30:31], s[4:5]
+
+; SPILL-TO-VGPR:      v_readlane_b32 s4, v40, 0
+; SPILL-TO-VGPR:      v_readlane_b32 s5, v40, 1
+; NO-SPILL-TO-VGPR:   v_readlane_b32 s4, v1, 0
+; NO-SPILL-TO-VGPR:   v_readlane_b32 s5, v1, 1
+
+; SPILL-TO-VGPR:      v_readlane_b32 s33, v40, 2
+; NO-SPILL-TO-VGPR:   buffer_load_dword v0, off, s[0:3], s32 offset:12 ; 4-byte Folded Reload
+; NO-SPILL-TO-VGPR:   v_readfirstlane_b32 s33, v0
+define void @callee_with_stack_and_call() #0 {
+  %alloca = alloca i32, addrspace(5)
+  store volatile i32 0, i32 addrspace(5)* %alloca
+  call void @external_void_func_void()
+  ret void
+}
+
+attributes #0 = { nounwind }


        


More information about the llvm-commits mailing list