1 ; RUN: llc -mtriple=amdgcn-amd-amdhsa-amdgiz -mcpu=fiji -mattr=-flat-for-global -enable-ipra=0 -amdgpu-sroa=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,VI,MESA %s
2 ; RUN: llc -mtriple=amdgcn-amd-amdhsa-amdgiz -mcpu=hawaii -enable-ipra=0 -amdgpu-sroa=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,CI,MESA %s
3 ; RUN: llc -mtriple=amdgcn-amd-amdhsa-amdgiz -mcpu=gfx900 -mattr=-flat-for-global -enable-ipra=0 -amdgpu-sroa=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9,VI,MESA %s
4 target datalayout = "A5"
6 ; GCN-LABEL: {{^}}i32_fastcc_i32_i32:
7 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
8 ; GCN-NEXT: v_add_{{[_coiu]*}}32_e32 v0, vcc, v1, v0
9 ; GCN-NEXT: s_setpc_b64
10 define fastcc i32 @i32_fastcc_i32_i32(i32 %arg0, i32 %arg1) #1 {
11 %add0 = add i32 %arg0, %arg1
15 ; GCN-LABEL: {{^}}i32_fastcc_i32_i32_stack_object:
16 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
17 ; GCN: v_add_{{[_coiu]*}}32_e32 v0, vcc, v1, v
18 ; GCN: s_mov_b32 s5, s32
19 ; GCN: buffer_store_dword v{{[0-9]+}}, off, s[0:3], s5 offset:24
20 ; GCN: s_waitcnt vmcnt(0)
22 ; GCN: ; ScratchSize: 68
23 define fastcc i32 @i32_fastcc_i32_i32_stack_object(i32 %arg0, i32 %arg1) #1 {
24 %alloca = alloca [16 x i32], align 4, addrspace(5)
25 %gep = getelementptr inbounds [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 5
26 store volatile i32 9, i32 addrspace(5)* %gep
27 %add0 = add i32 %arg0, %arg1
31 ; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32:
32 define fastcc i32 @sibling_call_i32_fastcc_i32_i32(i32 %a, i32 %b, i32 %c) #1 {
34 %ret = tail call fastcc i32 @i32_fastcc_i32_i32(i32 %a, i32 %b)
38 ; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32_stack_object:
39 ; GCN: v_mov_b32_e32 [[NINE:v[0-9]+]], 9
40 ; GCN: buffer_store_dword [[NINE]], off, s[0:3], s5 offset:24
42 ; GCN: ; ScratchSize: 68
43 define fastcc i32 @sibling_call_i32_fastcc_i32_i32_stack_object(i32 %a, i32 %b, i32 %c) #1 {
45 %alloca = alloca [16 x i32], align 4, addrspace(5)
46 %gep = getelementptr inbounds [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 5
47 store volatile i32 9, i32 addrspace(5)* %gep
48 %ret = tail call fastcc i32 @i32_fastcc_i32_i32(i32 %a, i32 %b)
52 ; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32_callee_stack_object:
53 ; GCN: v_mov_b32_e32 [[NINE:v[0-9]+]], 9
54 ; GCN: buffer_store_dword [[NINE]], off, s[0:3], s5 offset:24
56 ; GCN: ; ScratchSize: 136
57 define fastcc i32 @sibling_call_i32_fastcc_i32_i32_callee_stack_object(i32 %a, i32 %b, i32 %c) #1 {
59 %alloca = alloca [16 x i32], align 4, addrspace(5)
60 %gep = getelementptr inbounds [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 5
61 store volatile i32 9, i32 addrspace(5)* %gep
62 %ret = tail call fastcc i32 @i32_fastcc_i32_i32_stack_object(i32 %a, i32 %b)
66 ; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32_unused_result:
67 define fastcc void @sibling_call_i32_fastcc_i32_i32_unused_result(i32 %a, i32 %b, i32 %c) #1 {
69 %ret = tail call fastcc i32 @i32_fastcc_i32_i32(i32 %a, i32 %b)
73 ; It doesn't make sense to do a tail from a kernel
74 ; GCN-LABEL: {{^}}kernel_call_i32_fastcc_i32_i32_unused_result:
75 ;define amdgpu_kernel void @kernel_call_i32_fastcc_i32_i32_unused_result(i32 %a, i32 %b, i32 %c) #1 {
76 define amdgpu_kernel void @kernel_call_i32_fastcc_i32_i32_unused_result(i32 %a, i32 %b, i32 %c) #1 {
78 %ret = tail call fastcc i32 @i32_fastcc_i32_i32(i32 %a, i32 %b)
82 ; GCN-LABEL: {{^}}i32_fastcc_i32_byval_i32:
84 ; GCN-NEXT: s_mov_b32 s5, s32
85 ; GCN-NEXT: buffer_load_dword v1, off, s[0:3], s5 offset:4
86 ; GCN-NEXT: s_waitcnt vmcnt(0)
87 ; GCN-NEXT: v_add_{{[_coiu]*}}32_e32 v0, vcc, v1, v0
88 ; GCN-NEXT: s_setpc_b64 s[30:31]
89 define fastcc i32 @i32_fastcc_i32_byval_i32(i32 %arg0, i32 addrspace(5)* byval align 4 %arg1) #1 {
90 %arg1.load = load i32, i32 addrspace(5)* %arg1, align 4
91 %add0 = add i32 %arg0, %arg1.load
95 ; Tail call disallowed with byval in parent.
96 ; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_byval_i32_byval_parent:
97 ; GCN-NOT: v_writelane_b32 v{{[0-9]+}}, s32
98 ; GCN: buffer_store_dword v{{[0-9]+}}, off, s[0:3], s32 offset:4
100 ; GCN-NOT: v_readlane_b32 s32
102 define fastcc i32 @sibling_call_i32_fastcc_i32_byval_i32_byval_parent(i32 %a, i32 addrspace(5)* byval %b.byval, i32 %c) #1 {
104 %ret = tail call fastcc i32 @i32_fastcc_i32_byval_i32(i32 %a, i32 addrspace(5)* %b.byval)
108 ; Tail call disallowed with byval in parent, not callee.
109 ; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_byval_i32:
112 ; GCN: buffer_load_dword v1, off, s[0:3], s4 offset:16
113 ; GCN: s_mov_b32 s5, s32
114 ; GCN: buffer_store_dword v1, off, s[0:3], s5 offset:4
115 ; GCN-NEXT: s_setpc_b64
116 define fastcc i32 @sibling_call_i32_fastcc_i32_byval_i32(i32 %a, [16 x i32] %large) #1 {
118 %ret = tail call fastcc i32 @i32_fastcc_i32_byval_i32(i32 %a, i32 addrspace(5)* inttoptr (i32 16 to i32 addrspace(5)*))
122 ; GCN-LABEL: {{^}}i32_fastcc_i32_i32_a32i32:
123 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
124 ; GCN-DAG: buffer_load_dword [[LOAD_0:v[0-9]+]], off, s[0:3], s5 offset:4
125 ; GCN-DAG: buffer_load_dword [[LOAD_1:v[0-9]+]], off, s[0:3], s5 offset:8
126 ; GCN-DAG: v_add_{{[_coiu]*}}32_e32 v0, vcc, v1, v0
127 ; GCN: v_add_{{[_coiu]*}}32_e32 v0, vcc, [[LOAD_0]], v0
128 ; GCN: v_add_{{[_coiu]*}}32_e32 v0, vcc, [[LOAD_1]], v0
129 ; GCN-NEXT: s_setpc_b64
130 define fastcc i32 @i32_fastcc_i32_i32_a32i32(i32 %arg0, i32 %arg1, [32 x i32] %large) #1 {
131 %val_firststack = extractvalue [32 x i32] %large, 30
132 %val_laststack = extractvalue [32 x i32] %large, 31
133 %add0 = add i32 %arg0, %arg1
134 %add1 = add i32 %add0, %val_firststack
135 %add2 = add i32 %add1, %val_laststack
139 ; FIXME: Why load and store same location for stack args?
140 ; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32_a32i32:
141 ; GCN: s_mov_b32 s5, s32
143 ; GCN-DAG: buffer_store_dword v32, off, s[0:3], s5 offset:16 ; 4-byte Folded Spill
144 ; GCN-DAG: buffer_store_dword v33, off, s[0:3], s5 offset:12 ; 4-byte Folded Spill
146 ; GCN-DAG: buffer_load_dword [[LOAD_0:v[0-9]+]], off, s[0:3], s5 offset:4
147 ; GCN-DAG: buffer_load_dword [[LOAD_1:v[0-9]+]], off, s[0:3], s5 offset:8
151 ; GCN-DAG: buffer_store_dword [[LOAD_0]], off, s[0:3], s5 offset:4
152 ; GCN-DAG: buffer_store_dword [[LOAD_1]], off, s[0:3], s5 offset:8
154 ; GCN-DAG: buffer_load_dword v32, off, s[0:3], s5 offset:16 ; 4-byte Folded Reload
155 ; GCN-DAG: buffer_load_dword v33, off, s[0:3], s5 offset:12 ; 4-byte Folded Reload
159 define fastcc i32 @sibling_call_i32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] %c) #1 {
161 %ret = tail call fastcc i32 @i32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] %c)
165 ; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32_a32i32_stack_object:
166 ; GCN-DAG: s_mov_b32 s5, s32
168 ; GCN-DAG: v_mov_b32_e32 [[NINE:v[0-9]+]], 9
169 ; GCN: buffer_store_dword [[NINE]], off, s[0:3], s5 offset:44
173 define fastcc i32 @sibling_call_i32_fastcc_i32_i32_a32i32_stack_object(i32 %a, i32 %b, [32 x i32] %c) #1 {
175 %alloca = alloca [16 x i32], align 4, addrspace(5)
176 %gep = getelementptr inbounds [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 5
177 store volatile i32 9, i32 addrspace(5)* %gep
178 %ret = tail call fastcc i32 @i32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] %c)
182 ; If the callee requires more stack argument space than the caller,
183 ; don't do a tail call.
184 ; TODO: Do we really need this restriction?
186 ; GCN-LABEL: {{^}}no_sibling_call_callee_more_stack_space:
189 define fastcc i32 @no_sibling_call_callee_more_stack_space(i32 %a, i32 %b) #1 {
191 %ret = tail call fastcc i32 @i32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] zeroinitializer)
195 ; Have another non-tail in the function
196 ; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32_other_call:
197 ; GCN: s_mov_b32 s5, s32
198 ; GCN: buffer_store_dword v34, off, s[0:3], s5 offset:12
199 ; GCN: buffer_store_dword v32, off, s[0:3], s5 offset:8 ; 4-byte Folded Spill
200 ; GCN: buffer_store_dword v33, off, s[0:3], s5 offset:4 ; 4-byte Folded Spill
201 ; GCN-DAG: v_writelane_b32 v34, s33, 0
202 ; GCN-DAG: v_writelane_b32 v34, s34, 1
203 ; GCN-DAG: v_writelane_b32 v34, s35, 2
204 ; GCN-DAG: s_add_u32 s32, s32, 0x400
209 ; GCN: s_getpc_b64 s[6:7]
210 ; GCN: s_add_u32 s6, s6, sibling_call_i32_fastcc_i32_i32@rel32@lo+4
211 ; GCN: s_addc_u32 s7, s7, sibling_call_i32_fastcc_i32_i32@rel32@hi+4
213 ; GCN-DAG: v_readlane_b32 s33, v34, 0
214 ; GCN-DAG: v_readlane_b32 s34, v34, 1
215 ; GCN-DAG: v_readlane_b32 s35, v34, 2
217 ; GCN: buffer_load_dword v33, off, s[0:3], s5 offset:4
218 ; GCN: buffer_load_dword v32, off, s[0:3], s5 offset:8
219 ; GCN: buffer_load_dword v34, off, s[0:3], s5 offset:12
220 ; GCN: s_sub_u32 s32, s32, 0x400
221 ; GCN: s_setpc_b64 s[6:7]
222 define fastcc i32 @sibling_call_i32_fastcc_i32_i32_other_call(i32 %a, i32 %b, i32 %c) #1 {
224 %other.call = tail call fastcc i32 @i32_fastcc_i32_i32(i32 %a, i32 %b)
225 %ret = tail call fastcc i32 @sibling_call_i32_fastcc_i32_i32(i32 %a, i32 %b, i32 %other.call)
229 ; Have stack object in caller and stack passed arguments. SP should be
230 ; in same place at function exit.
232 ; GCN-LABEL: {{^}}sibling_call_stack_objecti32_fastcc_i32_i32_a32i32:
233 ; GCN: s_mov_b32 s5, s32
235 ; GCN: s_setpc_b64 s[6:7]
236 define fastcc i32 @sibling_call_stack_objecti32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] %c) #1 {
238 %alloca = alloca [16 x i32], align 4, addrspace(5)
239 %gep = getelementptr inbounds [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 5
240 store volatile i32 9, i32 addrspace(5)* %gep
241 %ret = tail call fastcc i32 @i32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] %c)
245 ; GCN-LABEL: {{^}}sibling_call_stack_objecti32_fastcc_i32_i32_a32i32_larger_arg_area:
246 ; GCN: s_mov_b32 s5, s32
248 ; GCN: s_setpc_b64 s[6:7]
249 define fastcc i32 @sibling_call_stack_objecti32_fastcc_i32_i32_a32i32_larger_arg_area(i32 %a, i32 %b, [36 x i32] %c) #1 {
251 %alloca = alloca [16 x i32], align 4, addrspace(5)
252 %gep = getelementptr inbounds [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 5
253 store volatile i32 9, i32 addrspace(5)* %gep
254 %ret = tail call fastcc i32 @i32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] zeroinitializer)
258 attributes #0 = { nounwind }
259 attributes #1 = { nounwind noinline }