1; RUN: llc -march=amdgcn -mcpu=fiji -mattr=-flat-for-global -amdgpu-sroa=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN -check-prefix=VI %s
2; RUN: llc -march=amdgcn -mcpu=hawaii -amdgpu-sroa=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN -check-prefix=CI %s
3; RUN: llc -march=amdgcn -mcpu=gfx900 -mattr=-flat-for-global -amdgpu-sroa=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN -check-prefix=GFX9 -check-prefix=VI %s
4
5; Test calls when called by other callable functions rather than
6; kernels.
7
8declare void @external_void_func_i32(i32) #0
9
10; GCN-LABEL: {{^}}test_func_call_external_void_func_i32_imm:
11; GCN: s_waitcnt
12
13; Spill CSR VGPR used for SGPR spilling
14; GCN: s_or_saveexec_b64 [[COPY_EXEC0:s\[[0-9]+:[0-9]+\]]], -1{{$}}
15; GCN-NEXT: buffer_store_dword v40, off, s[0:3], s32 ; 4-byte Folded Spill
16; GCN-NEXT: s_mov_b64 exec, [[COPY_EXEC0]]
17; GCN-DAG: v_writelane_b32 v40, s33, 2
18; GCN-DAG: s_mov_b32 s33, s32
19; GCN-DAG: s_add_u32 s32, s32, 0x400
20; GCN-DAG: v_writelane_b32 v40, s30, 0
21; GCN-DAG: v_writelane_b32 v40, s31, 1
22
23; GCN: s_swappc_b64
24
25; GCN: v_readlane_b32 s4, v40, 0
26; GCN: v_readlane_b32 s5, v40, 1
27
28; GCN-NEXT: s_sub_u32 s32, s32, 0x400
29; GCN-NEXT: v_readlane_b32 s33, v40, 2
30; GCN: s_or_saveexec_b64 [[COPY_EXEC1:s\[[0-9]+:[0-9]+\]]], -1{{$}}
31; GCN-NEXT: buffer_load_dword v40, off, s[0:3], s32 ; 4-byte Folded Reload
32; GCN-NEXT: s_mov_b64 exec, [[COPY_EXEC1]]
33; GCN-NEXT: s_waitcnt vmcnt(0)
34; GCN-NEXT: s_setpc_b64 s[4:5]
35define void @test_func_call_external_void_func_i32_imm() #0 {
36  call void @external_void_func_i32(i32 42)
37  ret void
38}
39
40; GCN-LABEL: {{^}}test_func_call_external_void_func_i32_imm_stack_use:
41; GCN: s_waitcnt
42; GCN: s_mov_b32 s33, s32
43; GCN-DAG: s_add_u32 s32, s32, 0x1400{{$}}
44; GCN-DAG: buffer_store_dword v{{[0-9]+}}, off, s[0:3], s33 offset:
45; GCN: s_swappc_b64
46; GCN: s_sub_u32 s32, s32, 0x1400{{$}}
47; GCN: s_setpc_b64
48define void @test_func_call_external_void_func_i32_imm_stack_use() #0 {
49  %alloca = alloca [16 x i32], align 4, addrspace(5)
50  %gep0 = getelementptr inbounds [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 0
51  %gep15 = getelementptr inbounds [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 16
52  store volatile i32 0, i32 addrspace(5)* %gep0
53  store volatile i32 0, i32 addrspace(5)* %gep15
54  call void @external_void_func_i32(i32 42)
55  ret void
56}
57
58attributes #0 = { nounwind }
59attributes #1 = { nounwind readnone }
60attributes #2 = { nounwind noinline }
61