1 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=fiji -enable-ipra=0 -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
2 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=hawaii -enable-ipra=0 -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
3 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -enable-ipra=0 -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
5 declare hidden void @external_void_func_void() #0
7 ; GCN-LABEL: {{^}}test_kernel_call_external_void_func_void_clobber_s30_s31_call_external_void_func_void:
8 ; GCN: s_mov_b32 s33, s7
9 ; GCN: s_getpc_b64 s[34:35]
10 ; GCN-NEXT: s_add_u32 s34, s34,
11 ; GCN-NEXT: s_addc_u32 s35, s35,
12 ; GCN-NEXT: s_mov_b32 s32, s33
13 ; GCN: s_swappc_b64 s[30:31], s[34:35]
17 ; GCN-NEXT: s_swappc_b64 s[30:31], s[34:35]
18 define amdgpu_kernel void @test_kernel_call_external_void_func_void_clobber_s30_s31_call_external_void_func_void() #0 {
19 call void @external_void_func_void()
20 call void asm sideeffect "", ""() #0
21 call void @external_void_func_void()
25 ; GCN-LABEL: {{^}}test_func_call_external_void_func_void_clobber_s30_s31_call_external_void_func_void:
26 ; GCN: buffer_store_dword
27 ; GCN: v_writelane_b32 v32, s34, 4
28 ; GCN: v_writelane_b32 v32, s36, 0
29 ; GCN: v_writelane_b32 v32, s37, 1
30 ; GCN: v_writelane_b32 v32, s30, 2
31 ; GCN: v_writelane_b32 v32, s31, 3
34 ; GCN-NEXT: ;;#ASMSTART
36 ; GCN-NEXT: s_swappc_b64
37 ; GCN-DAG: v_readlane_b32 s4, v32, 2
38 ; GCN-DAG: v_readlane_b32 s5, v32, 3
39 ; GCN: v_readlane_b32 s37, v32, 1
40 ; GCN: v_readlane_b32 s36, v32, 0
42 ; GCN: v_readlane_b32 s34, v32, 4
43 ; GCN: buffer_load_dword
45 define void @test_func_call_external_void_func_void_clobber_s30_s31_call_external_void_func_void() #0 {
46 call void @external_void_func_void()
47 call void asm sideeffect "", ""() #0
48 call void @external_void_func_void()
52 ; GCN-LABEL: {{^}}test_func_call_external_void_funcx2:
53 ; GCN: buffer_store_dword v32
54 ; GCN: v_writelane_b32 v32, s34, 4
56 ; GCN: s_mov_b32 s34, s32
57 ; GCN: s_add_u32 s32, s32, 0x400
59 ; GCN-NEXT: s_swappc_b64
61 ; GCN: v_readlane_b32 s34, v32, 4
62 ; GCN: buffer_load_dword v32,
63 define void @test_func_call_external_void_funcx2() #0 {
64 call void @external_void_func_void()
65 call void @external_void_func_void()
69 ; GCN-LABEL: {{^}}void_func_void_clobber_s30_s31:
71 ; GCN-NEXT: s_mov_b64 [[SAVEPC:s\[[0-9]+:[0-9]+\]]], s[30:31]
75 ; GCN-NEXT: s_setpc_b64 [[SAVEPC]]
76 define void @void_func_void_clobber_s30_s31() #2 {
77 call void asm sideeffect "; clobber", "~{s[30:31]}"() #0
81 ; GCN-LABEL: {{^}}void_func_void_clobber_vcc:
82 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
83 ; GCN-NEXT: ;;#ASMSTART
85 ; GCN-NEXT: s_setpc_b64 s[30:31]
86 define hidden void @void_func_void_clobber_vcc() #2 {
87 call void asm sideeffect "", "~{vcc}"() #0
91 ; GCN-LABEL: {{^}}test_call_void_func_void_clobber_vcc:
94 ; GCN-NEXT: s_addc_u32
95 ; GCN: s_mov_b64 s[34:35], vcc
96 ; GCN-NEXT: s_swappc_b64
97 ; GCN: s_mov_b64 vcc, s[34:35]
98 define amdgpu_kernel void @test_call_void_func_void_clobber_vcc(i32 addrspace(1)* %out) #0 {
99 %vcc = call i64 asm sideeffect "; def $0", "={vcc}"()
100 call void @void_func_void_clobber_vcc()
101 %val0 = load volatile i32, i32 addrspace(1)* undef
102 %val1 = load volatile i32, i32 addrspace(1)* undef
103 call void asm sideeffect "; use $0", "{vcc}"(i64 %vcc)
107 ; GCN-LABEL: {{^}}test_call_void_func_void_mayclobber_s31:
108 ; GCN: s_mov_b32 s34, s31
109 ; GCN-NEXT: s_swappc_b64
110 ; GCN-NEXT: s_mov_b32 s31, s34
111 define amdgpu_kernel void @test_call_void_func_void_mayclobber_s31(i32 addrspace(1)* %out) #0 {
112 %s31 = call i32 asm sideeffect "; def $0", "={s31}"()
113 call void @external_void_func_void()
114 call void asm sideeffect "; use $0", "{s31}"(i32 %s31)
118 ; GCN-LABEL: {{^}}test_call_void_func_void_mayclobber_v31:
119 ; GCN: v_mov_b32_e32 v32, v31
120 ; GCN-NEXT: s_swappc_b64
121 ; GCN-NEXT: v_mov_b32_e32 v31, v32
122 define amdgpu_kernel void @test_call_void_func_void_mayclobber_v31(i32 addrspace(1)* %out) #0 {
123 %v31 = call i32 asm sideeffect "; def $0", "={v31}"()
124 call void @external_void_func_void()
125 call void asm sideeffect "; use $0", "{v31}"(i32 %v31)
129 ; FIXME: What is the expected behavior for reserved registers here?
131 ; GCN-LABEL: {{^}}test_call_void_func_void_preserves_s33:
132 ; GCN: s_mov_b32 s33, s9
133 ; GCN: s_mov_b32 s32, s33
134 ; GCN: s_getpc_b64 s[4:5]
135 ; GCN-NEXT: s_add_u32 s4, s4, external_void_func_void@rel32@lo+4
136 ; GCN-NEXT: s_addc_u32 s5, s5, external_void_func_void@rel32@hi+4
138 ; GCN-NEXT: ; def s33
140 ; GCN: s_swappc_b64 s[30:31], s[4:5]
142 ; GCN-NEXT: ; use s33
143 ; GCN-NEXT: ;;#ASMEND
146 define amdgpu_kernel void @test_call_void_func_void_preserves_s33(i32 addrspace(1)* %out) #0 {
147 %s33 = call i32 asm sideeffect "; def $0", "={s33}"()
148 call void @external_void_func_void()
149 call void asm sideeffect "; use $0", "{s33}"(i32 %s33)
153 ; GCN-LABEL: {{^}}test_call_void_func_void_preserves_s34:
154 ; GCN: s_mov_b32 s33, s9
158 ; GCN: s_getpc_b64 s[4:5]
159 ; GCN-NEXT: s_add_u32 s4, s4, external_void_func_void@rel32@lo+4
160 ; GCN-NEXT: s_addc_u32 s5, s5, external_void_func_void@rel32@hi+4
164 ; GCN-NEXT: ; def s34
165 ; GCN-NEXT: ;;#ASMEND
168 ; GCN: s_swappc_b64 s[30:31], s[4:5]
172 ; GCN-NEXT: ;;#ASMSTART
173 ; GCN-NEXT: ; use s34
174 ; GCN-NEXT: ;;#ASMEND
176 define amdgpu_kernel void @test_call_void_func_void_preserves_s34(i32 addrspace(1)* %out) #0 {
177 %s34 = call i32 asm sideeffect "; def $0", "={s34}"()
178 call void @external_void_func_void()
179 call void asm sideeffect "; use $0", "{s34}"(i32 %s34)
183 ; GCN-LABEL: {{^}}test_call_void_func_void_preserves_v32:
184 ; GCN: s_mov_b32 s33, s9
187 ; GCN: s_getpc_b64 s[4:5]
188 ; GCN-NEXT: s_add_u32 s4, s4, external_void_func_void@rel32@lo+4
189 ; GCN-NEXT: s_addc_u32 s5, s5, external_void_func_void@rel32@hi+4
191 ; GCN-DAG: s_mov_b32 s32, s33
194 ; GCN-NEXT: ; def v32
195 ; GCN-NEXT: ;;#ASMEND
197 ; GCN: s_swappc_b64 s[30:31], s[4:5]
202 ; GCN-NEXT: ; use v32
203 ; GCN-NEXT: ;;#ASMEND
205 define amdgpu_kernel void @test_call_void_func_void_preserves_v32(i32 addrspace(1)* %out) #0 {
206 %v32 = call i32 asm sideeffect "; def $0", "={v32}"()
207 call void @external_void_func_void()
208 call void asm sideeffect "; use $0", "{v32}"(i32 %v32)
212 ; GCN-LABEL: {{^}}void_func_void_clobber_s33:
213 ; GCN: v_writelane_b32 v0, s33, 0
214 ; GCN-NEXT: #ASMSTART
215 ; GCN-NEXT: ; clobber
217 ; GCN-NEXT: v_readlane_b32 s33, v0, 0
219 define hidden void @void_func_void_clobber_s33() #2 {
220 call void asm sideeffect "; clobber", "~{s33}"() #0
224 ; GCN-LABEL: {{^}}void_func_void_clobber_s34:
225 ; GCN: v_writelane_b32 v0, s34, 0
226 ; GCN-NEXT: #ASMSTART
227 ; GCN-NEXT: ; clobber
229 ; GCN-NEXT: v_readlane_b32 s34, v0, 0
231 define hidden void @void_func_void_clobber_s34() #2 {
232 call void asm sideeffect "; clobber", "~{s34}"() #0
236 ; GCN-LABEL: {{^}}test_call_void_func_void_clobber_s33:
237 ; GCN: s_mov_b32 s33, s7
240 ; GCN-NEXT: s_add_u32
241 ; GCN-NEXT: s_addc_u32
242 ; GCN-NEXT: s_mov_b32 s32, s33
245 define amdgpu_kernel void @test_call_void_func_void_clobber_s33() #0 {
246 call void @void_func_void_clobber_s33()
250 ; GCN-LABEL: {{^}}test_call_void_func_void_clobber_s34:
251 ; GCN: s_mov_b32 s33, s7
253 ; GCN-NEXT: s_add_u32
254 ; GCN-NEXT: s_addc_u32
255 ; GCN-NEXT: s_mov_b32 s32, s33
258 define amdgpu_kernel void @test_call_void_func_void_clobber_s34() #0 {
259 call void @void_func_void_clobber_s34()
263 ; GCN-LABEL: {{^}}callee_saved_sgpr_func:
265 ; GCN: v_writelane_b32 v32, s40
270 ; GCN: v_readlane_b32 s40, v32
272 define void @callee_saved_sgpr_func() #2 {
273 %s40 = call i32 asm sideeffect "; def s40", "={s40}"() #0
274 call void @external_void_func_void()
275 call void asm sideeffect "; use $0", "s"(i32 %s40) #0
279 ; GCN-LABEL: {{^}}callee_saved_sgpr_kernel:
287 define amdgpu_kernel void @callee_saved_sgpr_kernel() #2 {
288 %s40 = call i32 asm sideeffect "; def s40", "={s40}"() #0
289 call void @external_void_func_void()
290 call void asm sideeffect "; use $0", "s"(i32 %s40) #0
294 ; First call preserved VGPR is used so it can't be used for SGPR spills.
295 ; GCN-LABEL: {{^}}callee_saved_sgpr_vgpr_func:
297 ; GCN: v_writelane_b32 v33, s40
302 ; GCN: v_readlane_b32 s40, v33
304 define void @callee_saved_sgpr_vgpr_func() #2 {
305 %s40 = call i32 asm sideeffect "; def s40", "={s40}"() #0
306 %v32 = call i32 asm sideeffect "; def v32", "={v32}"() #0
307 call void @external_void_func_void()
308 call void asm sideeffect "; use $0", "s"(i32 %s40) #0
309 call void asm sideeffect "; use $0", "v"(i32 %v32) #0
313 ; GCN-LABEL: {{^}}callee_saved_sgpr_vgpr_kernel:
321 define amdgpu_kernel void @callee_saved_sgpr_vgpr_kernel() #2 {
322 %s40 = call i32 asm sideeffect "; def s40", "={s40}"() #0
323 %v32 = call i32 asm sideeffect "; def v32", "={v32}"() #0
324 call void @external_void_func_void()
325 call void asm sideeffect "; use $0", "s"(i32 %s40) #0
326 call void asm sideeffect "; use $0", "v"(i32 %v32) #0
330 attributes #0 = { nounwind }
331 attributes #1 = { nounwind readnone }
332 attributes #2 = { nounwind noinline }