diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp @@ -1342,6 +1342,18 @@ if (CanTailCallOpt) return lowerTailCall(MIRBuilder, Info, OutArgs); + if (AMDGPU::isShader(Info.CallConv)) { + // Note the issue is with the CC of the called function, not of the call + // itself. + return false; + } + + if (AMDGPU::isShader(MF.getFunction().getCallingConv()) && + Info.CallConv != CallingConv::AMDGPU_Gfx) { + // Only allow calls with specific calling conventions. + return false; + } + // Find out which ABI gets to decide where things go. CCAssignFn *AssignFnFixed; CCAssignFn *AssignFnVarArg; diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call.ll --- a/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call.ll +++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call.ll @@ -5292,41 +5292,6 @@ ret void } -define amdgpu_ps void @amdgpu_ps_call_default_cc() { - ; CHECK-LABEL: name: amdgpu_ps_call_default_cc - ; CHECK: bb.1.main_body: - ; CHECK-NEXT: [[C:%[0-9]+]]:_(p0) = G_CONSTANT i64 0 - ; CHECK-NEXT: ADJCALLSTACKUP 0, 0, implicit-def $scc - ; CHECK-NEXT: [[DEF:%[0-9]+]]:_(p4) = G_IMPLICIT_DEF - ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p4) = COPY [[DEF]](p4) - ; CHECK-NEXT: [[C1:%[0-9]+]]:_(p4) = G_CONSTANT i64 0 - ; CHECK-NEXT: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 0 - ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(p4) = COPY [[C1]](p4) - ; CHECK-NEXT: [[DEF1:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF - ; CHECK-NEXT: [[DEF2:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF - ; CHECK-NEXT: [[COPY2:%[0-9]+]]:_(s32) = COPY [[DEF2]](s32) - ; CHECK-NEXT: [[COPY3:%[0-9]+]]:_(s32) = COPY [[DEF2]](s32) - ; CHECK-NEXT: [[COPY4:%[0-9]+]]:_(s32) = COPY [[DEF2]](s32) - ; CHECK-NEXT: [[COPY5:%[0-9]+]]:_(s32) = COPY [[DEF2]](s32) - ; CHECK-NEXT: [[COPY6:%[0-9]+]]:_(<4 x s32>) = COPY $private_rsrc_reg - ; CHECK-NEXT: $sgpr0_sgpr1_sgpr2_sgpr3 = COPY [[COPY6]](<4 x s32>) - ; CHECK-NEXT: $sgpr4_sgpr5 = COPY [[DEF]](p4) - ; CHECK-NEXT: $sgpr6_sgpr7 = COPY [[COPY]](p4) - ; CHECK-NEXT: $sgpr8_sgpr9 = COPY [[COPY1]](p4) - ; CHECK-NEXT: $sgpr10_sgpr11 = COPY [[DEF1]](s64) - ; CHECK-NEXT: $sgpr12 = COPY [[DEF2]](s32) - ; CHECK-NEXT: $sgpr13 = COPY [[COPY2]](s32) - ; CHECK-NEXT: $sgpr14 = COPY [[COPY3]](s32) - ; CHECK-NEXT: $sgpr15 = COPY [[COPY4]](s32) - ; CHECK-NEXT: $vgpr31 = COPY [[COPY5]](s32) - ; CHECK-NEXT: $sgpr30_sgpr31 = G_SI_CALL [[C]](p0), 0, csr_amdgpu, implicit $sgpr0_sgpr1_sgpr2_sgpr3, implicit $sgpr4_sgpr5, implicit $sgpr6_sgpr7, implicit $sgpr8_sgpr9, implicit $sgpr10_sgpr11, implicit $sgpr12, implicit $sgpr13, implicit $sgpr14, implicit $sgpr15, implicit $vgpr31 - ; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def $scc - ; CHECK-NEXT: S_ENDPGM 0 -main_body: - call void null() - ret void -} - attributes #0 = { nounwind } attributes #1 = { nounwind readnone } attributes #2 = { nounwind noinline } diff --git a/llvm/test/CodeGen/AMDGPU/unsupported-calls.ll b/llvm/test/CodeGen/AMDGPU/unsupported-calls.ll --- a/llvm/test/CodeGen/AMDGPU/unsupported-calls.ll +++ b/llvm/test/CodeGen/AMDGPU/unsupported-calls.ll @@ -1,9 +1,13 @@ +; RUN: not llc -march=amdgcn -mtriple=armgcn-- -mcpu=gfx1100 -tailcallopt -global-isel=1 -global-isel-abort=0 < %s 2>&1 | FileCheck -check-prefix=GISEL %s ; RUN: not llc -march=amdgcn -mtriple=amdgcn-mesa-mesa3d -tailcallopt < %s 2>&1 | FileCheck --check-prefix=GCN %s ; RUN: not llc -march=amdgcn -mtriple=amdgcn--amdpal -tailcallopt < %s 2>&1 | FileCheck --check-prefix=GCN %s ; RUN: not llc -march=r600 -mtriple=r600-- -mcpu=cypress -tailcallopt < %s 2>&1 | FileCheck -check-prefix=R600 %s +; FIXME: Remove -global-isel-abort=0 when global isel can handle these. + declare i32 @external_function(i32) nounwind +; GISEL-NOT: error ; GCN-NOT: error ; R600: in function test_call_external{{.*}}: unsupported call to function external_function define amdgpu_kernel void @test_call_external(ptr addrspace(1) %out, ptr addrspace(1) %in) { @@ -21,6 +25,7 @@ ret i32 %y } +; GISEL-NOT: error ; GCN-NOT: error ; R600: in function test_call{{.*}}: unsupported call to function defined_function define amdgpu_kernel void @test_call(ptr addrspace(1) %out, ptr addrspace(1) %in) { @@ -33,6 +38,7 @@ ret void } +; FIXME: GISEL ; GCN: error: :0:0: in function test_tail_call i32 (ptr addrspace(1), ptr addrspace(1)): unsupported required tail call to function defined_function ; R600: in function test_tail_call{{.*}}: unsupported call to function defined_function define i32 @test_tail_call(ptr addrspace(1) %out, ptr addrspace(1) %in) { @@ -45,6 +51,7 @@ declare void @external.varargs(i32, double, i64, ...) +; GISEL: error: :0:0: in function test_call_varargs void (): unsupported call to variadic function external.varargs ; GCN: error: :0:0: in function test_call_varargs void (): unsupported call to variadic function external.varargs ; R600: in function test_call_varargs{{.*}}: unsupported call to function external.varargs define void @test_call_varargs() { @@ -54,6 +61,7 @@ declare i32 @extern_variadic(...) +; FIXME: GISEL ; GCN: in function test_tail_call_bitcast_extern_variadic{{.*}}: unsupported required tail call to function extern_variadic ; R600: in function test_tail_call_bitcast_extern_variadic{{.*}}: unsupported call to function extern_variadic define i32 @test_tail_call_bitcast_extern_variadic(<4 x float> %arg0, <4 x float> %arg1, i32 %arg2) { @@ -62,6 +70,7 @@ ret i32 %call } +; GISEL: in function test_c_call_from_shader i32 (): unsupported calling convention for call from graphics shader of function defined_function ; GCN: :0:0: in function test_c_call_from_shader i32 (): unsupported calling convention for call from graphics shader of function defined_function ; R600: in function test_c_call{{.*}}: unsupported call to function defined_function define amdgpu_ps i32 @test_c_call_from_shader() { @@ -69,6 +78,7 @@ ret i32 %call } +; GISEL-NOT: in function test_gfx_call{{.*}}unsupported ; GCN-NOT: in function test_gfx_call{{.*}}unsupported ; R600: in function test_gfx_call{{.*}}: unsupported call to function defined_function define amdgpu_ps i32 @test_gfx_call_from_shader() {