Recommit r310809 with a fix for the spill problem
[llvm-core.git] / test / CodeGen / AArch64 / swifterror.ll
blobbcad19e391d0b30c8f6f43df031032b97d51cf83
1 ; RUN: llc -verify-machineinstrs -disable-fp-elim -enable-shrink-wrap=false < %s -mtriple=aarch64-apple-ios -disable-post-ra | FileCheck --check-prefix=CHECK-APPLE %s
2 ; RUN: llc -verify-machineinstrs -disable-fp-elim -O0 < %s -mtriple=aarch64-apple-ios -disable-post-ra | FileCheck --check-prefix=CHECK-O0 %s
4 declare i8* @malloc(i64)
5 declare void @free(i8*)
6 %swift_error = type {i64, i8}
8 ; This tests the basic usage of a swifterror parameter. "foo" is the function
9 ; that takes a swifterror parameter and "caller" is the caller of "foo".
10 define float @foo(%swift_error** swifterror %error_ptr_ref) {
11 ; CHECK-APPLE-LABEL: foo:
12 ; CHECK-APPLE: orr w0, wzr, #0x10
13 ; CHECK-APPLE: malloc
14 ; CHECK-APPLE: orr [[ID:w[0-9]+]], wzr, #0x1
15 ; CHECK-APPLE: strb [[ID]], [x0, #8]
16 ; CHECK-APPLE: mov x21, x0
17 ; CHECK-APPLE-NOT: x21
19 ; CHECK-O0-LABEL: foo:
20 ; CHECK-O0: orr w{{.*}}, wzr, #0x10
21 ; CHECK-O0: malloc
22 ; CHECK-O0: mov x21, x0
23 ; CHECK-O0-NOT: x21
24 ; CHECK-O0: orr [[ID:w[0-9]+]], wzr, #0x1
25 ; CHECK-O0-NOT: x21
26 ; CHECK-O0: strb [[ID]], [x0, #8]
27 ; CHECK-O0-NOT: x21
28 entry:
29   %call = call i8* @malloc(i64 16)
30   %call.0 = bitcast i8* %call to %swift_error*
31   store %swift_error* %call.0, %swift_error** %error_ptr_ref
32   %tmp = getelementptr inbounds i8, i8* %call, i64 8
33   store i8 1, i8* %tmp
34   ret float 1.0
37 ; "caller" calls "foo" that takes a swifterror parameter.
38 define float @caller(i8* %error_ref) {
39 ; CHECK-APPLE-LABEL: caller:
40 ; CHECK-APPLE: mov [[ID:x[0-9]+]], x0
41 ; CHECK-APPLE: mov x21, xzr
42 ; CHECK-APPLE: bl {{.*}}foo
43 ; CHECK-APPLE: cbnz x21
44 ; Access part of the error object and save it to error_ref
45 ; CHECK-APPLE: ldrb [[CODE:w[0-9]+]], [x21, #8]
46 ; CHECK-APPLE: strb [[CODE]], [{{.*}}[[ID]]]
47 ; CHECK-APPLE: mov x0, x21
48 ; CHECK-APPLE: bl {{.*}}free
50 ; CHECK-O0-LABEL: caller:
51 ; CHECK-O0: mov x21
52 ; CHECK-O0: bl {{.*}}foo
53 ; CHECK-O0: mov [[ID:x[0-9]+]], x21
54 ; CHECK-O0: cbnz x21
55 entry:
56   %error_ptr_ref = alloca swifterror %swift_error*
57   store %swift_error* null, %swift_error** %error_ptr_ref
58   %call = call float @foo(%swift_error** swifterror %error_ptr_ref)
59   %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref
60   %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null
61   %tmp = bitcast %swift_error* %error_from_foo to i8*
62   br i1 %had_error_from_foo, label %handler, label %cont
63 cont:
64   %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1
65   %t = load i8, i8* %v1
66   store i8 %t, i8* %error_ref
67   br label %handler
68 handler:
69   call void @free(i8* %tmp)
70   ret float 1.0
73 ; "caller2" is the caller of "foo", it calls "foo" inside a loop.
74 define float @caller2(i8* %error_ref) {
75 ; CHECK-APPLE-LABEL: caller2:
76 ; CHECK-APPLE: mov [[ID:x[0-9]+]], x0
77 ; CHECK-APPLE: fmov [[CMP:s[0-9]+]], #1.0
78 ; CHECK-APPLE: mov x21, xzr
79 ; CHECK-APPLE: bl {{.*}}foo
80 ; CHECK-APPLE: cbnz x21
81 ; CHECK-APPLE: fcmp s0, [[CMP]]
82 ; CHECK-APPLE: b.le
83 ; Access part of the error object and save it to error_ref
84 ; CHECK-APPLE: ldrb [[CODE:w[0-9]+]], [x21, #8]
85 ; CHECK-APPLE: strb [[CODE]], [{{.*}}[[ID]]]
86 ; CHECK-APPLE: mov x0, x21
87 ; CHECK-APPLE: bl {{.*}}free
89 ; CHECK-O0-LABEL: caller2:
90 ; CHECK-O0: mov x21
91 ; CHECK-O0: bl {{.*}}foo
92 ; CHECK-O0: mov [[ID:x[0-9]+]], x21
93 ; CHECK-O0: cbnz x21
94 entry:
95   %error_ptr_ref = alloca swifterror %swift_error*
96   br label %bb_loop
97 bb_loop:
98   store %swift_error* null, %swift_error** %error_ptr_ref
99   %call = call float @foo(%swift_error** swifterror %error_ptr_ref)
100   %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref
101   %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null
102   %tmp = bitcast %swift_error* %error_from_foo to i8*
103   br i1 %had_error_from_foo, label %handler, label %cont
104 cont:
105   %cmp = fcmp ogt float %call, 1.000000e+00
106   br i1 %cmp, label %bb_end, label %bb_loop
107 bb_end:
108   %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1
109   %t = load i8, i8* %v1
110   store i8 %t, i8* %error_ref
111   br label %handler
112 handler:
113   call void @free(i8* %tmp)
114   ret float 1.0
117 ; "foo_if" is a function that takes a swifterror parameter, it sets swifterror
118 ; under a certain condition.
119 define float @foo_if(%swift_error** swifterror %error_ptr_ref, i32 %cc) {
120 ; CHECK-APPLE-LABEL: foo_if:
121 ; CHECK-APPLE: cbz w0
122 ; CHECK-APPLE: orr w0, wzr, #0x10
123 ; CHECK-APPLE: malloc
124 ; CHECK-APPLE: orr [[ID:w[0-9]+]], wzr, #0x1
125 ; CHECK-APPLE: strb [[ID]], [x0, #8]
126 ; CHECK-APPLE: mov x21, x0
127 ; CHECK-APPLE-NOT: x21
128 ; CHECK-APPLE: ret
130 ; CHECK-O0-LABEL: foo_if:
131 ; spill x21
132 ; CHECK-O0: str x21, [sp, [[SLOT:#[0-9]+]]]
133 ; CHECK-O0: cbz w0
134 ; CHECK-O0: orr w{{.*}}, wzr, #0x10
135 ; CHECK-O0: malloc
136 ; CHECK-O0: mov [[ID:x[0-9]+]], x0
137 ; CHECK-O0: orr [[ID2:w[0-9]+]], wzr, #0x1
138 ; CHECK-O0: strb [[ID2]], [x0, #8]
139 ; CHECK-O0: mov x21, [[ID]]
140 ; CHECK-O0: ret
141 ; reload from stack
142 ; CHECK-O0: ldr [[ID3:x[0-9]+]], [sp, [[SLOT]]]
143 ; CHECK-O0: mov x21, [[ID3]]
144 ; CHECK-O0: ret
145 entry:
146   %cond = icmp ne i32 %cc, 0
147   br i1 %cond, label %gen_error, label %normal
149 gen_error:
150   %call = call i8* @malloc(i64 16)
151   %call.0 = bitcast i8* %call to %swift_error*
152   store %swift_error* %call.0, %swift_error** %error_ptr_ref
153   %tmp = getelementptr inbounds i8, i8* %call, i64 8
154   store i8 1, i8* %tmp
155   ret float 1.0
157 normal:
158   ret float 0.0
161 ; "foo_loop" is a function that takes a swifterror parameter, it sets swifterror
162 ; under a certain condition inside a loop.
163 define float @foo_loop(%swift_error** swifterror %error_ptr_ref, i32 %cc, float %cc2) {
164 ; CHECK-APPLE-LABEL: foo_loop:
165 ; CHECK-APPLE: mov x0, x21
166 ; CHECK-APPLE: cbz
167 ; CHECK-APPLE: orr w0, wzr, #0x10
168 ; CHECK-APPLE: malloc
169 ; CHECK-APPLE: strb w{{.*}}, [x0, #8]
170 ; CHECK-APPLE: fcmp
171 ; CHECK-APPLE: b.le
172 ; CHECK-APPLE: mov x21, x0
173 ; CHECK-APPLE: ret
175 ; CHECK-O0-LABEL: foo_loop:
176 ; spill x21
177 ; CHECK-O0: str x21, [sp, [[SLOT:#[0-9]+]]]
178 ; CHECK-O0: b [[BB1:[A-Za-z0-9_]*]]
179 ; CHECK-O0: [[BB1]]:
180 ; CHECK-O0: ldr     x0, [sp, [[SLOT]]]
181 ; CHECK-O0: str     x0, [sp, [[SLOT2:#[0-9]+]]]
182 ; CHECK-O0: cbz {{.*}}, [[BB2:[A-Za-z0-9_]*]]
183 ; CHECK-O0: orr w{{.*}}, wzr, #0x10
184 ; CHECK-O0: malloc
185 ; CHECK-O0: mov [[ID:x[0-9]+]], x0
186 ; CHECK-O0: strb w{{.*}}, [{{.*}}[[ID]], #8]
187 ; spill x0
188 ; CHECK-O0: str x0, [sp, [[SLOT2]]]
189 ; CHECK-O0:[[BB2]]:
190 ; CHECK-O0: ldr     x0, [sp, [[SLOT2]]]
191 ; CHECK-O0: fcmp
192 ; CHECK-O0: str     x0, [sp]
193 ; CHECK-O0: b.le [[BB1]]
194 ; reload from stack
195 ; CHECK-O0: ldr [[ID3:x[0-9]+]], [sp]
196 ; CHECK-O0: mov x21, [[ID3]]
197 ; CHECK-O0: ret
198 entry:
199   br label %bb_loop
201 bb_loop:
202   %cond = icmp ne i32 %cc, 0
203   br i1 %cond, label %gen_error, label %bb_cont
205 gen_error:
206   %call = call i8* @malloc(i64 16)
207   %call.0 = bitcast i8* %call to %swift_error*
208   store %swift_error* %call.0, %swift_error** %error_ptr_ref
209   %tmp = getelementptr inbounds i8, i8* %call, i64 8
210   store i8 1, i8* %tmp
211   br label %bb_cont
213 bb_cont:
214   %cmp = fcmp ogt float %cc2, 1.000000e+00
215   br i1 %cmp, label %bb_end, label %bb_loop
216 bb_end:
217   ret float 0.0
220 %struct.S = type { i32, i32, i32, i32, i32, i32 }
222 ; "foo_sret" is a function that takes a swifterror parameter, it also has a sret
223 ; parameter.
224 define void @foo_sret(%struct.S* sret %agg.result, i32 %val1, %swift_error** swifterror %error_ptr_ref) {
225 ; CHECK-APPLE-LABEL: foo_sret:
226 ; CHECK-APPLE: mov [[SRET:x[0-9]+]], x8
227 ; CHECK-APPLE: orr w0, wzr, #0x10
228 ; CHECK-APPLE: malloc
229 ; CHECK-APPLE: orr [[ID:w[0-9]+]], wzr, #0x1
230 ; CHECK-APPLE: strb [[ID]], [x0, #8]
231 ; CHECK-APPLE: str w{{.*}}, [{{.*}}[[SRET]], #4]
232 ; CHECK-APPLE: mov x21, x0
233 ; CHECK-APPLE-NOT: x21
235 ; CHECK-O0-LABEL: foo_sret:
236 ; CHECK-O0: orr w{{.*}}, wzr, #0x10
237 ; spill x8
238 ; CHECK-O0-DAG: str x8
239 ; spill x21
240 ; CHECK-O0-DAG: str x21
241 ; CHECK-O0: malloc
242 ; CHECK-O0: orr [[ID:w[0-9]+]], wzr, #0x1
243 ; CHECK-O0: strb [[ID]], [x0, #8]
244 ; reload from stack
245 ; CHECK-O0: ldr [[SRET:x[0-9]+]]
246 ; CHECK-O0: str w{{.*}}, [{{.*}}[[SRET]], #4]
247 ; CHECK-O0: mov x21
248 ; CHECK-O0-NOT: x21
249 entry:
250   %call = call i8* @malloc(i64 16)
251   %call.0 = bitcast i8* %call to %swift_error*
252   store %swift_error* %call.0, %swift_error** %error_ptr_ref
253   %tmp = getelementptr inbounds i8, i8* %call, i64 8
254   store i8 1, i8* %tmp
255   %v2 = getelementptr inbounds %struct.S, %struct.S* %agg.result, i32 0, i32 1
256   store i32 %val1, i32* %v2
257   ret void
260 ; "caller3" calls "foo_sret" that takes a swifterror parameter.
261 define float @caller3(i8* %error_ref) {
262 ; CHECK-APPLE-LABEL: caller3:
263 ; CHECK-APPLE: mov [[ID:x[0-9]+]], x0
264 ; CHECK-APPLE: mov x21, xzr
265 ; CHECK-APPLE: bl {{.*}}foo_sret
266 ; CHECK-APPLE: cbnz x21
267 ; Access part of the error object and save it to error_ref
268 ; CHECK-APPLE: ldrb [[CODE:w[0-9]+]], [x21, #8]
269 ; CHECK-APPLE: strb [[CODE]], [{{.*}}[[ID]]]
270 ; CHECK-APPLE: mov x0, x21
271 ; CHECK-APPLE: bl {{.*}}free
273 ; CHECK-O0-LABEL: caller3:
274 ; spill x0
275 ; CHECK-O0: str x0
276 ; CHECK-O0: mov x21
277 ; CHECK-O0: bl {{.*}}foo_sret
278 ; CHECK-O0: mov [[ID2:x[0-9]+]], x21
279 ; CHECK-O0: cbnz x21
280 ; Access part of the error object and save it to error_ref
281 ; reload from stack
282 ; CHECK-O0: ldrb [[CODE:w[0-9]+]]
283 ; CHECK-O0: ldr [[ID:x[0-9]+]]
284 ; CHECK-O0: strb [[CODE]], [{{.*}}[[ID]]]
285 ; CHECK-O0: bl {{.*}}free
286 entry:
287   %s = alloca %struct.S, align 8
288   %error_ptr_ref = alloca swifterror %swift_error*
289   store %swift_error* null, %swift_error** %error_ptr_ref
290   call void @foo_sret(%struct.S* sret %s, i32 1, %swift_error** swifterror %error_ptr_ref)
291   %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref
292   %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null
293   %tmp = bitcast %swift_error* %error_from_foo to i8*
294   br i1 %had_error_from_foo, label %handler, label %cont
295 cont:
296   %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1
297   %t = load i8, i8* %v1
298   store i8 %t, i8* %error_ref
299   br label %handler
300 handler:
301   call void @free(i8* %tmp)
302   ret float 1.0
305 ; "foo_vararg" is a function that takes a swifterror parameter, it also has
306 ; variable number of arguments.
307 declare void @llvm.va_start(i8*) nounwind
308 define float @foo_vararg(%swift_error** swifterror %error_ptr_ref, ...) {
309 ; CHECK-APPLE-LABEL: foo_vararg:
310 ; CHECK-APPLE: orr w0, wzr, #0x10
311 ; CHECK-APPLE: malloc
312 ; CHECK-APPLE-DAG: orr [[ID:w[0-9]+]], wzr, #0x1
313 ; CHECK-APPLE-DAG: add [[ARGS:x[0-9]+]], [[TMP:x[0-9]+]], #16
314 ; CHECK-APPLE-DAG: strb [[ID]], [x0, #8]
316 ; First vararg
317 ; CHECK-APPLE-DAG: orr {{x[0-9]+}}, [[ARGS]], #0x8
318 ; CHECK-APPLE-DAG: ldr {{w[0-9]+}}, [{{.*}}[[TMP]], #16]
319 ; CHECK-APPLE-DAG: add {{x[0-9]+}}, {{x[0-9]+}}, #8
320 ; Second vararg
321 ; CHECK-APPLE-DAG: ldr {{w[0-9]+}}, [{{x[0-9]+}}], #8
322 ; CHECK-APPLE-DAG: add {{x[0-9]+}}, {{x[0-9]+}}, #16
323 ; Third vararg
324 ; CHECK-APPLE: ldr {{w[0-9]+}}, [{{x[0-9]+}}]
326 ; CHECK-APPLE: mov x21, x0
327 ; CHECK-APPLE-NOT: x21
328 entry:
329   %call = call i8* @malloc(i64 16)
330   %call.0 = bitcast i8* %call to %swift_error*
331   store %swift_error* %call.0, %swift_error** %error_ptr_ref
332   %tmp = getelementptr inbounds i8, i8* %call, i64 8
333   store i8 1, i8* %tmp
335   %args = alloca i8*, align 8
336   %a10 = alloca i32, align 4
337   %a11 = alloca i32, align 4
338   %a12 = alloca i32, align 4
339   %v10 = bitcast i8** %args to i8*
340   call void @llvm.va_start(i8* %v10)
341   %v11 = va_arg i8** %args, i32
342   store i32 %v11, i32* %a10, align 4
343   %v12 = va_arg i8** %args, i32
344   store i32 %v12, i32* %a11, align 4
345   %v13 = va_arg i8** %args, i32
346   store i32 %v13, i32* %a12, align 4
348   ret float 1.0
351 ; "caller4" calls "foo_vararg" that takes a swifterror parameter.
352 define float @caller4(i8* %error_ref) {
353 ; CHECK-APPLE-LABEL: caller4:
355 ; CHECK-APPLE: mov [[ID:x[0-9]+]], x0
356 ; CHECK-APPLE: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #8]
357 ; CHECK-APPLE: str {{x[0-9]+}}, [sp]
359 ; CHECK-APPLE: mov x21, xzr
360 ; CHECK-APPLE: bl {{.*}}foo_vararg
361 ; CHECK-APPLE: cbnz x21
362 ; Access part of the error object and save it to error_ref
363 ; CHECK-APPLE: ldrb [[CODE:w[0-9]+]], [x21, #8]
364 ; CHECK-APPLE: strb [[CODE]], [{{.*}}[[ID]]]
365 ; CHECK-APPLE: mov x0, x21
366 ; CHECK-APPLE: bl {{.*}}free
367 entry:
368   %error_ptr_ref = alloca swifterror %swift_error*
369   store %swift_error* null, %swift_error** %error_ptr_ref
371   %a10 = alloca i32, align 4
372   %a11 = alloca i32, align 4
373   %a12 = alloca i32, align 4
374   store i32 10, i32* %a10, align 4
375   store i32 11, i32* %a11, align 4
376   store i32 12, i32* %a12, align 4
377   %v10 = load i32, i32* %a10, align 4
378   %v11 = load i32, i32* %a11, align 4
379   %v12 = load i32, i32* %a12, align 4
381   %call = call float (%swift_error**, ...) @foo_vararg(%swift_error** swifterror %error_ptr_ref, i32 %v10, i32 %v11, i32 %v12)
382   %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref
383   %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null
384   %tmp = bitcast %swift_error* %error_from_foo to i8*
385   br i1 %had_error_from_foo, label %handler, label %cont
387 cont:
388   %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1
389   %t = load i8, i8* %v1
390   store i8 %t, i8* %error_ref
391   br label %handler
392 handler:
393   call void @free(i8* %tmp)
394   ret float 1.0
397 ; Check that we don't blow up on tail calling swifterror argument functions.
398 define float @tailcallswifterror(%swift_error** swifterror %error_ptr_ref) {
399 entry:
400   %0 = tail call float @tailcallswifterror(%swift_error** swifterror %error_ptr_ref)
401   ret float %0
403 define swiftcc float @tailcallswifterror_swiftcc(%swift_error** swifterror %error_ptr_ref) {
404 entry:
405   %0 = tail call swiftcc float @tailcallswifterror_swiftcc(%swift_error** swifterror %error_ptr_ref)
406   ret float %0
409 ; CHECK-APPLE-LABEL: swifterror_clobber
410 ; CHECK-APPLE: mov [[REG:x[0-9]+]], x21
411 ; CHECK-APPLE: nop
412 ; CHECK-APPLE: mov x21, [[REG]]
413 define swiftcc void @swifterror_clobber(%swift_error** nocapture swifterror %err) {
414   call void asm sideeffect "nop", "~{x21}"()
415   ret void
418 ; CHECK-APPLE-LABEL: swifterror_reg_clobber
419 ; CHECK-APPLE: stp {{.*}}x21
420 ; CHECK-APPLE: nop
421 ; CHECK-APPLE: ldp  {{.*}}x21
422 define swiftcc void @swifterror_reg_clobber(%swift_error** nocapture %err) {
423   call void asm sideeffect "nop", "~{x21}"()
424   ret void
426 ; CHECK-APPLE-LABEL: params_in_reg
427 ; Save callee saved registers and swifterror since it will be clobbered by the first call to params_in_reg2.
428 ; CHECK-APPLE:  stp     x21, x28, [sp
429 ; CHECK-APPLE:  stp     x27, x26, [sp
430 ; CHECK-APPLE:  stp     x25, x24, [sp
431 ; CHECK-APPLE:  stp     x23, x22, [sp
432 ; CHECK-APPLE:  stp     x20, x19, [sp
433 ; CHECK-APPLE:  stp     x29, x30, [sp
434 ; CHECK-APPLE:  str     x20, [sp
435 ; Store argument registers.
436 ; CHECK-APPLE:  mov      x23, x7
437 ; CHECK-APPLE:  mov      x24, x6
438 ; CHECK-APPLE:  mov      x25, x5
439 ; CHECK-APPLE:  mov      x26, x4
440 ; CHECK-APPLE:  mov      x27, x3
441 ; CHECK-APPLE:  mov      x28, x2
442 ; CHECK-APPLE:  mov      x19, x1
443 ; CHECK-APPLE:  mov      x22, x0
444 ; Setup call.
445 ; CHECK-APPLE:  orr     w0, wzr, #0x1
446 ; CHECK-APPLE:  orr     w1, wzr, #0x2
447 ; CHECK-APPLE:  orr     w2, wzr, #0x3
448 ; CHECK-APPLE:  orr     w3, wzr, #0x4
449 ; CHECK-APPLE:  mov     w4, #5
450 ; CHECK-APPLE:  orr     w5, wzr, #0x6
451 ; CHECK-APPLE:  orr     w6, wzr, #0x7
452 ; CHECK-APPLE:  orr     w7, wzr, #0x8
453 ; CHECK-APPLE:  mov      x20, xzr
454 ; CHECK-APPLE:  mov      x21, xzr
455 ; CHECK-APPLE:  bl      _params_in_reg2
456 ; Restore original arguments for next call.
457 ; CHECK-APPLE:  mov      x0, x22
458 ; CHECK-APPLE:  mov      x1, x19
459 ; CHECK-APPLE:  mov      x2, x28
460 ; CHECK-APPLE:  mov      x3, x27
461 ; CHECK-APPLE:  mov      x4, x26
462 ; CHECK-APPLE:  mov      x5, x25
463 ; CHECK-APPLE:  mov      x6, x24
464 ; CHECK-APPLE:  mov      x7, x23
465 ; Restore original swiftself argument and swifterror %err.
466 ; CHECK-APPLE:  ldp             x20, x21, [sp
467 ; CHECK-APPLE:  bl      _params_in_reg2
468 ; Restore calle save registers but don't clober swifterror x21.
469 ; CHECK-APPLE-NOT: x21
470 ; CHECK-APPLE:  ldp     x29, x30, [sp
471 ; CHECK-APPLE-NOT: x21
472 ; CHECK-APPLE:  ldp     x20, x19, [sp
473 ; CHECK-APPLE-NOT: x21
474 ; CHECK-APPLE:  ldp     x23, x22, [sp
475 ; CHECK-APPLE-NOT: x21
476 ; CHECK-APPLE:  ldp     x25, x24, [sp
477 ; CHECK-APPLE-NOT: x21
478 ; CHECK-APPLE:  ldp     x27, x26, [sp
479 ; CHECK-APPLE-NOT: x21
480 ; CHECK-APPLE:  ldr     x28, [sp
481 ; CHECK-APPLE-NOT: x21
482 ; CHECK-APPLE:  ret
483 define swiftcc void @params_in_reg(i64, i64, i64, i64, i64, i64, i64, i64, i8* swiftself, %swift_error** nocapture swifterror %err) {
484   %error_ptr_ref = alloca swifterror %swift_error*, align 8
485   store %swift_error* null, %swift_error** %error_ptr_ref
486   call swiftcc void @params_in_reg2(i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i8* swiftself null, %swift_error** nocapture swifterror %error_ptr_ref)
487   call swiftcc void @params_in_reg2(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5, i64 %6, i64 %7, i8* swiftself %8, %swift_error** nocapture swifterror %err)
488   ret void
490 declare swiftcc void @params_in_reg2(i64, i64, i64, i64, i64, i64, i64, i64, i8* swiftself, %swift_error** nocapture swifterror %err)
492 ; CHECK-APPLE-LABEL: params_and_return_in_reg
493 ; Store callee saved registers.
494 ; CHECK-APPLE:  stp     x20, x28, [sp, #24
495 ; CHECK-APPLE:  stp     x27, x26, [sp
496 ; CHECK-APPLE:  stp     x25, x24, [sp
497 ; CHECK-APPLE:  stp     x23, x22, [sp
498 ; CHECK-APPLE:  stp     x20, x19, [sp
499 ; CHECK-APPLE:  stp     x29, x30, [sp
500 ; Save original arguments.
501 ; CHECK-APPLE:  mov      x23, x21
502 ; CHECK-APPLE:  str     x7, [sp, #16]
503 ; CHECK-APPLE:  mov      x24, x6
504 ; CHECK-APPLE:  mov      x25, x5
505 ; CHECK-APPLE:  mov      x26, x4
506 ; CHECK-APPLE:  mov      x27, x3
507 ; CHECK-APPLE:  mov      x28, x2
508 ; CHECK-APPLE:  mov      x19, x1
509 ; CHECK-APPLE:  mov      x22, x0
510 ; Setup call arguments.
511 ; CHECK-APPLE:  orr     w0, wzr, #0x1
512 ; CHECK-APPLE:  orr     w1, wzr, #0x2
513 ; CHECK-APPLE:  orr     w2, wzr, #0x3
514 ; CHECK-APPLE:  orr     w3, wzr, #0x4
515 ; CHECK-APPLE:  mov     w4, #5
516 ; CHECK-APPLE:  orr     w5, wzr, #0x6
517 ; CHECK-APPLE:  orr     w6, wzr, #0x7
518 ; CHECK-APPLE:  orr     w7, wzr, #0x8
519 ; CHECK-APPLE:  mov      x20, xzr
520 ; CHECK-APPLE:  mov      x21, xzr
521 ; CHECK-APPLE:  bl      _params_in_reg2
522 ; Store swifterror %error_ptr_ref.
523 ; CHECK-APPLE:  str     x21, [sp, #8]
524 ; Setup call arguments from original arguments.
525 ; CHECK-APPLE:  mov      x0, x22
526 ; CHECK-APPLE:  mov      x1, x19
527 ; CHECK-APPLE:  mov      x2, x28
528 ; CHECK-APPLE:  mov      x3, x27
529 ; CHECK-APPLE:  mov      x4, x26
530 ; CHECK-APPLE:  mov      x5, x25
531 ; CHECK-APPLE:  mov      x6, x24
532 ; CHECK-APPLE:  ldp     x7, x20, [sp, #16]
533 ; CHECK-APPLE:  mov      x21, x23
534 ; CHECK-APPLE:  bl      _params_and_return_in_reg2
535 ; Store return values.
536 ; CHECK-APPLE:  mov      x19, x0
537 ; CHECK-APPLE:  mov      x22, x1
538 ; CHECK-APPLE:  mov      x24, x2
539 ; CHECK-APPLE:  mov      x25, x3
540 ; CHECK-APPLE:  mov      x26, x4
541 ; CHECK-APPLE:  mov      x27, x5
542 ; CHECK-APPLE:  mov      x28, x6
543 ; CHECK-APPLE:  mov      x23, x7
544 ; Save swifterror %err.
545 ; CHECK-APPLE:  str     x21, [sp, #24]
546 ; Setup call.
547 ; CHECK-APPLE:  orr     w0, wzr, #0x1
548 ; CHECK-APPLE:  orr     w1, wzr, #0x2
549 ; CHECK-APPLE:  orr     w2, wzr, #0x3
550 ; CHECK-APPLE:  orr     w3, wzr, #0x4
551 ; CHECK-APPLE:  mov     w4, #5
552 ; CHECK-APPLE:  orr     w5, wzr, #0x6
553 ; CHECK-APPLE:  orr     w6, wzr, #0x7
554 ; CHECK-APPLE:  orr     w7, wzr, #0x8
555 ; CHECK-APPLE:  mov      x20, xzr
556 ; ... setup call with swiferror %error_ptr_ref.
557 ; CHECK-APPLE:  ldr     x21, [sp, #8]
558 ; CHECK-APPLE:  bl      _params_in_reg2
559 ; Restore return values for return from this function.
560 ; CHECK-APPLE:  mov      x0, x19
561 ; CHECK-APPLE:  mov      x1, x22
562 ; CHECK-APPLE:  mov      x2, x24
563 ; CHECK-APPLE:  mov      x3, x25
564 ; CHECK-APPLE:  mov      x4, x26
565 ; CHECK-APPLE:  mov      x5, x27
566 ; CHECK-APPLE:  mov      x6, x28
567 ; CHECK-APPLE:  mov      x7, x23
568 ; Restore swifterror %err and callee save registers.
569 ; CHECK-APPLE:  ldp     x21, x28, [sp, #24
570 ; CHECK-APPLE:  ldp     x29, x30, [sp
571 ; CHECK-APPLE:  ldp     x20, x19, [sp
572 ; CHECK-APPLE:  ldp     x23, x22, [sp
573 ; CHECK-APPLE:  ldp     x25, x24, [sp
574 ; CHECK-APPLE:  ldp     x27, x26, [sp
575 ; CHECK-APPLE:  ret
576 define swiftcc { i64, i64, i64, i64, i64, i64, i64, i64 } @params_and_return_in_reg(i64, i64, i64, i64, i64, i64, i64, i64, i8* swiftself, %swift_error** nocapture swifterror %err) {
577   %error_ptr_ref = alloca swifterror %swift_error*, align 8
578   store %swift_error* null, %swift_error** %error_ptr_ref
579   call swiftcc void @params_in_reg2(i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i8* swiftself null, %swift_error** nocapture swifterror %error_ptr_ref)
580   %val = call swiftcc  { i64, i64, i64, i64, i64, i64, i64, i64 } @params_and_return_in_reg2(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5, i64 %6, i64 %7, i8* swiftself %8, %swift_error** nocapture swifterror %err)
581   call swiftcc void @params_in_reg2(i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i8* swiftself null, %swift_error** nocapture swifterror %error_ptr_ref)
582   ret { i64, i64, i64, i64, i64, i64, i64, i64 } %val
585 declare swiftcc { i64, i64, i64, i64, i64, i64, i64, i64 } @params_and_return_in_reg2(i64, i64, i64, i64, i64, i64, i64, i64, i8* swiftself, %swift_error** nocapture swifterror %err)
587 declare void @acallee(i8*)
589 ; Make sure we don't tail call if the caller returns a swifterror value. We
590 ; would have to move into the swifterror register before the tail call.
591 ; CHECK-APPLE: tailcall_from_swifterror:
592 ; CHECK-APPLE-NOT: b _acallee
593 ; CHECK-APPLE: bl _acallee
595 define swiftcc void @tailcall_from_swifterror(%swift_error** swifterror %error_ptr_ref) {
596 entry:
597   tail call void @acallee(i8* null)
598   ret void
601 declare swiftcc void @foo2(%swift_error** swifterror)
603 ; Make sure we properly assign registers during fast-isel.
604 ; CHECK-O0-LABEL: testAssign
605 ; CHECK-O0: mov     [[TMP:x.*]], xzr
606 ; CHECK-O0: mov     x21, [[TMP]]
607 ; CHECK-O0: bl      _foo2
608 ; CHECK-O0: str     x21, [s[[STK:.*]]]
609 ; CHECK-O0: ldr     x0, [s[[STK]]]
611 ; CHECK-APPLE-LABEL: testAssign
612 ; CHECK-APPLE: mov      x21, xzr
613 ; CHECK-APPLE: bl      _foo2
614 ; CHECK-APPLE: mov      x0, x21
616 define swiftcc %swift_error* @testAssign(i8* %error_ref) {
617 entry:
618   %error_ptr = alloca swifterror %swift_error*
619   store %swift_error* null, %swift_error** %error_ptr
620   call swiftcc void @foo2(%swift_error** swifterror %error_ptr)
621   br label %a
624   %error = load %swift_error*, %swift_error** %error_ptr
625   ret %swift_error* %error