blob: 08c6dc9dbc1e7a4a9c62b0d46f4f6904df4724ea [file] [log] [blame]
Matt Arsenault71bcbd42017-08-11 20:42:08 +00001; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=fiji -mattr=-flat-for-global -amdgpu-sroa=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,VI,MESA %s
2; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=hawaii -amdgpu-sroa=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,CI,MESA %s
3; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -mattr=-flat-for-global -amdgpu-sroa=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9,VI,MESA %s
4
5; GCN-LABEL: {{^}}i32_fastcc_i32_i32:
6; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
7; GCN-NEXT: v_add_i32_e32 v0, vcc, v1, v0
8; GCN-NEXT: s_setpc_b64
9define fastcc i32 @i32_fastcc_i32_i32(i32 %arg0, i32 %arg1) #1 {
10 %add0 = add i32 %arg0, %arg1
11 ret i32 %add0
12}
13
14; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32:
15define fastcc i32 @sibling_call_i32_fastcc_i32_i32(i32 %a, i32 %b, i32 %c) #1 {
16entry:
17 %ret = tail call fastcc i32 @i32_fastcc_i32_i32(i32 %a, i32 %b)
18 ret i32 %ret
19}
20
21; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32_stack_object:
22; GCN: v_mov_b32_e32 [[NINE:v[0-9]+]], 9
23; GCN: buffer_store_dword [[NINE]], off, s[0:3], s5 offset:24
24; GCN: s_setpc_b64
25define fastcc i32 @sibling_call_i32_fastcc_i32_i32_stack_object(i32 %a, i32 %b, i32 %c) #1 {
26entry:
27 %alloca = alloca [16 x i32], align 4
28 %gep = getelementptr inbounds [16 x i32], [16 x i32]* %alloca, i32 0, i32 5
29 store volatile i32 9, i32* %gep
30 %ret = tail call fastcc i32 @i32_fastcc_i32_i32(i32 %a, i32 %b)
31 ret i32 %ret
32}
33
34; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32_unused_result:
35define fastcc void @sibling_call_i32_fastcc_i32_i32_unused_result(i32 %a, i32 %b, i32 %c) #1 {
36entry:
37 %ret = tail call fastcc i32 @i32_fastcc_i32_i32(i32 %a, i32 %b)
38 ret void
39}
40
41; It doesn't make sense to do a tail from a kernel
42; GCN-LABEL: {{^}}kernel_call_i32_fastcc_i32_i32_unused_result:
43;define amdgpu_kernel void @kernel_call_i32_fastcc_i32_i32_unused_result(i32 %a, i32 %b, i32 %c) #1 {
44define amdgpu_kernel void @kernel_call_i32_fastcc_i32_i32_unused_result(i32 %a, i32 %b, i32 %c) #1 {
45entry:
46 %ret = tail call fastcc i32 @i32_fastcc_i32_i32(i32 %a, i32 %b)
47 ret void
48}
49
50; GCN-LABEL: {{^}}i32_fastcc_i32_byval_i32:
51; GCN: s_waitcnt
52; GCN-NEXT: s_mov_b32 s5, s32
53; GCN-NEXT: buffer_load_dword v1, off, s[0:3], s5 offset:4
54; GCN-NEXT: s_waitcnt vmcnt(0)
55; GCN-NEXT: v_add_i32_e32 v0, vcc, v1, v0
56; GCN-NEXT: s_setpc_b64 s[30:31]
57define fastcc i32 @i32_fastcc_i32_byval_i32(i32 %arg0, i32* byval align 4 %arg1) #1 {
58 %arg1.load = load i32, i32* %arg1, align 4
59 %add0 = add i32 %arg0, %arg1.load
60 ret i32 %add0
61}
62
63; Tail call disallowed with byval in parent.
64; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_byval_i32_byval_parent:
65; GCN: buffer_store_dword v{{[0-9]+}}, off, s[0:3], s32 offset:4
66; GCN: s_swappc_b64
67; GCN: s_setpc_b64
68define fastcc i32 @sibling_call_i32_fastcc_i32_byval_i32_byval_parent(i32 %a, i32* byval %b.byval, i32 %c) #1 {
69entry:
70 %ret = tail call fastcc i32 @i32_fastcc_i32_byval_i32(i32 %a, i32* %b.byval)
71 ret i32 %ret
72}
73
74; Tail call disallowed with byval in parent, not callee.
75; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_byval_i32:
76; GCN-NOT: v0
77; GCN-NOT: s32
78; GCN: buffer_load_dword v1, off, s[0:3], s4 offset:16
79; GCN: s_mov_b32 s5, s32
80; GCN: buffer_store_dword v1, off, s[0:3], s5 offset:4
81; GCN-NEXT: s_setpc_b64
82define fastcc i32 @sibling_call_i32_fastcc_i32_byval_i32(i32 %a, [16 x i32] %large) #1 {
83entry:
84 %ret = tail call fastcc i32 @i32_fastcc_i32_byval_i32(i32 %a, i32* inttoptr (i32 16 to i32*))
85 ret i32 %ret
86}
87
88; GCN-LABEL: {{^}}i32_fastcc_i32_i32_a32i32:
89; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
90; GCN-DAG: buffer_load_dword [[LOAD_0:v[0-9]+]], off, s[0:3], s5 offset:4
91; GCN-DAG: buffer_load_dword [[LOAD_1:v[0-9]+]], off, s[0:3], s5 offset:8
92; GCN-DAG: v_add_i32_e32 v0, vcc, v1, v0
93; GCN: v_add_i32_e32 v0, vcc, [[LOAD_0]], v0
94; GCN: v_add_i32_e32 v0, vcc, [[LOAD_1]], v0
95; GCN-NEXT: s_setpc_b64
96define fastcc i32 @i32_fastcc_i32_i32_a32i32(i32 %arg0, i32 %arg1, [32 x i32] %large) #1 {
97 %val_firststack = extractvalue [32 x i32] %large, 30
98 %val_laststack = extractvalue [32 x i32] %large, 31
99 %add0 = add i32 %arg0, %arg1
100 %add1 = add i32 %add0, %val_firststack
101 %add2 = add i32 %add1, %val_laststack
102 ret i32 %add2
103}
104
105; FIXME: Why load and store same location for stack args?
106; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32_a32i32:
107; GCN: s_mov_b32 s5, s32
108
109; GCN-DAG: buffer_store_dword v32, off, s[0:3], s5 offset:16 ; 4-byte Folded Spill
110; GCN-DAG: buffer_store_dword v33, off, s[0:3], s5 offset:12 ; 4-byte Folded Spill
111
112; GCN-DAG: buffer_load_dword [[LOAD_0:v[0-9]+]], off, s[0:3], s5 offset:4
113; GCN-DAG: buffer_load_dword [[LOAD_1:v[0-9]+]], off, s[0:3], s5 offset:8
114
115; GCN-NOT: s32
116
117; GCN-DAG: buffer_store_dword [[LOAD_0]], off, s[0:3], s5 offset:4
118; GCN-DAG: buffer_store_dword [[LOAD_1]], off, s[0:3], s5 offset:8
119
120; GCN-DAG: buffer_load_dword v32, off, s[0:3], s5 offset:16 ; 4-byte Folded Reload
121; GCN-DAG: buffer_load_dword v33, off, s[0:3], s5 offset:12 ; 4-byte Folded Reload
122
123; GCN-NOT: s32
124; GCN: s_setpc_b64
125define fastcc i32 @sibling_call_i32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] %c) #1 {
126entry:
127 %ret = tail call fastcc i32 @i32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] %c)
128 ret i32 %ret
129}
130
131; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32_a32i32_stack_object:
132; GCN-DAG: s_mov_b32 s5, s32
133; GCN-NOT: s32
134; GCN-DAG: v_mov_b32_e32 [[NINE:v[0-9]+]], 9
135; GCN: buffer_store_dword [[NINE]], off, s[0:3], s5 offset:44
136
137; GCN-NOT: s32
138; GCN: s_setpc_b64
139define fastcc i32 @sibling_call_i32_fastcc_i32_i32_a32i32_stack_object(i32 %a, i32 %b, [32 x i32] %c) #1 {
140entry:
141 %alloca = alloca [16 x i32], align 4
142 %gep = getelementptr inbounds [16 x i32], [16 x i32]* %alloca, i32 0, i32 5
143 store volatile i32 9, i32* %gep
144 %ret = tail call fastcc i32 @i32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] %c)
145 ret i32 %ret
146}
147
148; If the callee requires more stack argument space than the caller,
149; don't do a tail call.
150; TODO: Do we really need this restriction?
151
152; GCN-LABEL: {{^}}no_sibling_call_callee_more_stack_space:
153; GCN: s_swappc_b64
154; GCN: s_setpc_b64
155define fastcc i32 @no_sibling_call_callee_more_stack_space(i32 %a, i32 %b) #1 {
156entry:
157 %ret = tail call fastcc i32 @i32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] zeroinitializer)
158 ret i32 %ret
159}
160
161; Have another non-tail in the function
162; GCN-LABEL: {{^}}sibling_call_i32_fastcc_i32_i32_other_call:
163; GCN: s_mov_b32 s5, s32
164; GCN: buffer_store_dword v34, off, s[0:3], s5 offset:12
165; GCN: buffer_store_dword v32, off, s[0:3], s5 offset:8 ; 4-byte Folded Spill
166; GCN: buffer_store_dword v33, off, s[0:3], s5 offset:4 ; 4-byte Folded Spill
167; GCN-DAG: v_writelane_b32 v34, s33, 0
168; GCN-DAG: v_writelane_b32 v34, s34, 1
169; GCN-DAG: v_writelane_b32 v34, s35, 2
170; GCN-DAG: s_add_u32 s32, s32, 0x400
171
172; GCN: s_getpc_b64
173; GCN: s_swappc_b64
174
175; GCN: s_getpc_b64 s[6:7]
176; GCN: s_add_u32 s6, s6, sibling_call_i32_fastcc_i32_i32@rel32@lo+4
177; GCN: s_addc_u32 s7, s7, sibling_call_i32_fastcc_i32_i32@rel32@hi+4
178
179; GCN-DAG: v_readlane_b32 s33, v34, 0
180; GCN-DAG: v_readlane_b32 s34, v34, 1
181; GCN-DAG: v_readlane_b32 s35, v34, 2
182
183; GCN: buffer_load_dword v33, off, s[0:3], s5 offset:4
184; GCN: buffer_load_dword v32, off, s[0:3], s5 offset:8
185; GCN: buffer_load_dword v34, off, s[0:3], s5 offset:12
186; GCN: s_sub_u32 s32, s32, 0x400
187; GCN: s_setpc_b64 s[6:7]
188define fastcc i32 @sibling_call_i32_fastcc_i32_i32_other_call(i32 %a, i32 %b, i32 %c) #1 {
189entry:
190 %other.call = tail call fastcc i32 @i32_fastcc_i32_i32(i32 %a, i32 %b)
191 %ret = tail call fastcc i32 @sibling_call_i32_fastcc_i32_i32(i32 %a, i32 %b, i32 %other.call)
192 ret i32 %ret
193}
194
195; Have stack object in caller and stack passed arguments. SP should be
196; in same place at function exit.
197
198; GCN-LABEL: {{^}}sibling_call_stack_objecti32_fastcc_i32_i32_a32i32:
199; GCN: s_mov_b32 s5, s32
200; GCN-NOT: s32
201; GCN: s_setpc_b64 s[6:7]
202define fastcc i32 @sibling_call_stack_objecti32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] %c) #1 {
203entry:
204 %alloca = alloca [16 x i32], align 4
205 %gep = getelementptr inbounds [16 x i32], [16 x i32]* %alloca, i32 0, i32 5
206 store volatile i32 9, i32* %gep
207 %ret = tail call fastcc i32 @i32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] %c)
208 ret i32 %ret
209}
210
211; GCN-LABEL: {{^}}sibling_call_stack_objecti32_fastcc_i32_i32_a32i32_larger_arg_area:
212; GCN: s_mov_b32 s5, s32
213; GCN-NOT: s32
214; GCN: s_setpc_b64 s[6:7]
215define fastcc i32 @sibling_call_stack_objecti32_fastcc_i32_i32_a32i32_larger_arg_area(i32 %a, i32 %b, [36 x i32] %c) #1 {
216entry:
217 %alloca = alloca [16 x i32], align 4
218 %gep = getelementptr inbounds [16 x i32], [16 x i32]* %alloca, i32 0, i32 5
219 store volatile i32 9, i32* %gep
220 %ret = tail call fastcc i32 @i32_fastcc_i32_i32_a32i32(i32 %a, i32 %b, [32 x i32] zeroinitializer)
221 ret i32 %ret
222}
223
224attributes #0 = { nounwind }
225attributes #1 = { nounwind noinline }