diff --git a/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp b/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp @@ -196,8 +196,13 @@ // Assume a big number if there are any unknown sized objects. Info.HasDynamicallySizedStack = FrameInfo.hasVarSizedObjects(); - if (Info.HasDynamicallySizedStack) + if (Info.HasDynamicallySizedStack) { Info.PrivateSegmentSize += AssumedStackSizeForDynamicSizeObjects; + if (TM.getMCSubtargetInfo()->getTargetTriple().getOS() == Triple::AMDPAL) { + report_fatal_error( + "PAL ABI does not support dynamically sized stack objects"); + } + } if (MFI->isStackRealigned()) Info.PrivateSegmentSize += FrameInfo.getMaxAlign().value(); diff --git a/llvm/test/CodeGen/AMDGPU/amdpal-callable.ll b/llvm/test/CodeGen/AMDGPU/amdpal-callable.ll --- a/llvm/test/CodeGen/AMDGPU/amdpal-callable.ll +++ b/llvm/test/CodeGen/AMDGPU/amdpal-callable.ll @@ -1,6 +1,6 @@ -; RUN: llc -mtriple=amdgcn--amdpal -mattr=-xnack -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,SDAG,GFX8 -enable-var-scope %s -; RUN: llc -mtriple=amdgcn--amdpal -mcpu=gfx900 -mattr=-xnack -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,SDAG,GFX9 -enable-var-scope %s -; RUN: llc -global-isel -mtriple=amdgcn--amdpal -mattr=-xnack -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GISEL,GFX9 -enable-var-scope %s +; RUN: llc -mtriple=amdgcn--amdpal -mattr=-xnack -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GFX8 -enable-var-scope %s +; RUN: llc -mtriple=amdgcn--amdpal -mcpu=gfx900 -mattr=-xnack -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GFX9 -enable-var-scope %s +; RUN: llc -global-isel -mtriple=amdgcn--amdpal -mattr=-xnack -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GFX9 -enable-var-scope %s declare amdgpu_gfx float @extern_func(float) #0 declare amdgpu_gfx float @extern_func_many_args(<64 x float>) #0 @@ -32,41 +32,6 @@ ret float %add2 } -define amdgpu_gfx float @dynamic_stack(float %arg0) #0 { -bb0: - %cmp = fcmp ogt float %arg0, 0.0 - br i1 %cmp, label %bb1, label %bb2 - -bb1: - %stack = alloca float, i32 4, align 4, addrspace(5) - store volatile float 2.0, ptr addrspace(5) %stack - %val = load volatile float, ptr addrspace(5) %stack - %add = fadd float %arg0, %val - br label %bb2 - -bb2: - %res = phi float [ 0.0, %bb0 ], [ %add, %bb1 ] - ret float %res -} - -define amdgpu_gfx float @dynamic_stack_loop(float %arg0) #0 { -bb0: - br label %bb1 - -bb1: - %ctr = phi i32 [ 0, %bb0 ], [ %newctr, %bb1 ] - %stack = alloca float, i32 4, align 4, addrspace(5) - store volatile float 2.0, ptr addrspace(5) %stack - %val = load volatile float, ptr addrspace(5) %stack - %add = fadd float %arg0, %val - %cmp = icmp sgt i32 %ctr, 0 - %newctr = sub i32 %ctr, 1 - br i1 %cmp, label %bb1, label %bb2 - -bb2: - ret float %add -} - define amdgpu_gfx float @no_stack_call(float %arg0) #0 { %res = call amdgpu_gfx float @simple_stack(float %arg0) ret float %res @@ -145,19 +110,6 @@ ; GCN-NEXT: 0x2e12 (COMPUTE_PGM_RSRC1): 0xaf01ca{{$}} ; GCN-NEXT: 0x2e13 (COMPUTE_PGM_RSRC2): 0x8001{{$}} ; GCN-NEXT: .shader_functions: -; GCN-NEXT: dynamic_stack: -; GCN-NEXT: .lds_size: 0{{$}} -; GCN-NEXT: .sgpr_count: 0x28{{$}} -; GCN-NEXT: .stack_frame_size_in_bytes: 0x10{{$}} -; SDAG-NEXT: .vgpr_count: 0x2{{$}} -; GISEL-NEXT: .vgpr_count: 0x3{{$}} -; GCN-NEXT: dynamic_stack_loop: -; GCN-NEXT: .lds_size: 0{{$}} -; SDAG-NEXT: .sgpr_count: 0x25{{$}} -; GISEL-NEXT: .sgpr_count: 0x26{{$}} -; GCN-NEXT: .stack_frame_size_in_bytes: 0x10{{$}} -; SDAG-NEXT: .vgpr_count: 0x3{{$}} -; GISEL-NEXT: .vgpr_count: 0x4{{$}} ; GCN-NEXT: multiple_stack: ; GCN-NEXT: .lds_size: 0{{$}} ; GCN-NEXT: .sgpr_count: 0x21{{$}} diff --git a/llvm/test/CodeGen/AMDGPU/amdpal-no-dyn-alloca.ll b/llvm/test/CodeGen/AMDGPU/amdpal-no-dyn-alloca.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/amdpal-no-dyn-alloca.ll @@ -0,0 +1,40 @@ +; RUN: not --crash llc -mtriple=amdgcn--amdpal -mcpu=gfx1100 -o - %s 2>&1 | FileCheck %s + +; Check that dynamic allocas are an error with the amdpal ABI. + +; CHECK: LLVM ERROR: PAL ABI does not support dynamically sized stack objects + +define amdgpu_gfx float @dynamic_stack(float %arg0) #0 { +bb0: + %cmp = fcmp ogt float %arg0, 0.0 + br i1 %cmp, label %bb1, label %bb2 + +bb1: + %stack = alloca float, i32 4, align 4, addrspace(5) + store volatile float 2.0, ptr addrspace(5) %stack + %val = load volatile float, ptr addrspace(5) %stack + %add = fadd float %arg0, %val + br label %bb2 + +bb2: + %res = phi float [ 0.0, %bb0 ], [ %add, %bb1 ] + ret float %res +} + +define amdgpu_gfx float @dynamic_stack_loop(float %arg0) #0 { +bb0: + br label %bb1 + +bb1: + %ctr = phi i32 [ 0, %bb0 ], [ %newctr, %bb1 ] + %stack = alloca float, i32 4, align 4, addrspace(5) + store volatile float 2.0, ptr addrspace(5) %stack + %val = load volatile float, ptr addrspace(5) %stack + %add = fadd float %arg0, %val + %cmp = icmp sgt i32 %ctr, 0 + %newctr = sub i32 %ctr, 1 + br i1 %cmp, label %bb1, label %bb2 + +bb2: + ret float %add +}