[ARM64] Support aggressive fastcc/tailcallopt breaking ABI by popping out argument...
[oota-llvm.git] / test / CodeGen / AArch64 / tail-call.ll
1 ; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu -tailcallopt | FileCheck %s
2 ; RUN: llc -verify-machineinstrs < %s -mtriple=arm64-none-linux-gnu -tailcallopt | FileCheck --check-prefix=CHECK-ARM64 %s
3
4 declare fastcc void @callee_stack0()
5 declare fastcc void @callee_stack8([8 x i32], i64)
6 declare fastcc void @callee_stack16([8 x i32], i64, i64)
7
8 define fastcc void @caller_to0_from0() nounwind {
9 ; CHECK-LABEL: caller_to0_from0:
10 ; CHECK-NEXT: // BB
11
12 ; CHECK-ARM64-LABEL: caller_to0_from0:
13 ; CHECK-ARM64-NEXT: // BB
14
15   tail call fastcc void @callee_stack0()
16   ret void
17
18 ; CHECK-NEXT: b callee_stack0
19
20 ; CHECK-ARM64-NEXT: b callee_stack0
21 }
22
23 define fastcc void @caller_to0_from8([8 x i32], i64) {
24 ; CHECK-LABEL: caller_to0_from8:
25
26 ; CHECK-ARM64-LABEL: caller_to0_from8:
27
28   tail call fastcc void @callee_stack0()
29   ret void
30
31 ; CHECK: add sp, sp, #16
32 ; CHECK-NEXT: b callee_stack0
33
34 ; CHECK-ARM64: add sp, sp, #16
35 ; CHECK-ARM64-NEXT: b callee_stack0
36 }
37
38 define fastcc void @caller_to8_from0() {
39 ; CHECK-LABEL: caller_to8_from0:
40 ; CHECK: sub sp, sp, #32
41
42 ; CHECK-ARM64-LABEL: caller_to8_from0:
43 ; CHECK-ARM64: sub sp, sp, #32
44
45 ; Key point is that the "42" should go #16 below incoming stack
46 ; pointer (we didn't have arg space to reuse).
47   tail call fastcc void @callee_stack8([8 x i32] undef, i64 42)
48   ret void
49
50 ; CHECK: str {{x[0-9]+}}, [sp, #16]
51 ; CHECK-NEXT: add sp, sp, #16
52 ; CHECK-NEXT: b callee_stack8
53
54 ; CHECK-ARM64: str {{x[0-9]+}}, [sp, #16]!
55 ; CHECK-ARM64-NEXT: b callee_stack8
56 }
57
58 define fastcc void @caller_to8_from8([8 x i32], i64 %a) {
59 ; CHECK-LABEL: caller_to8_from8:
60 ; CHECK: sub sp, sp, #16
61
62 ; CHECK-ARM64-LABEL: caller_to8_from8:
63 ; CHECK-ARM64: sub sp, sp, #16
64
65 ; Key point is that the "%a" should go where at SP on entry.
66   tail call fastcc void @callee_stack8([8 x i32] undef, i64 42)
67   ret void
68
69 ; CHECK: str {{x[0-9]+}}, [sp, #16]
70 ; CHECK-NEXT: add sp, sp, #16
71 ; CHECK-NEXT: b callee_stack8
72
73 ; CHECK-ARM64: str {{x[0-9]+}}, [sp, #16]!
74 ; CHECK-ARM64-NEXT: b callee_stack8
75 }
76
77 define fastcc void @caller_to16_from8([8 x i32], i64 %a) {
78 ; CHECK-LABEL: caller_to16_from8:
79 ; CHECK: sub sp, sp, #16
80
81 ; CHECK-ARM64-LABEL: caller_to16_from8:
82 ; CHECK-ARM64: sub sp, sp, #16
83
84 ; Important point is that the call reuses the "dead" argument space
85 ; above %a on the stack. If it tries to go below incoming-SP then the
86 ; callee will not deallocate the space, even in fastcc.
87   tail call fastcc void @callee_stack16([8 x i32] undef, i64 42, i64 2)
88
89 ; CHECK: str {{x[0-9]+}}, [sp, #24]
90 ; CHECK: str {{x[0-9]+}}, [sp, #16]
91 ; CHECK-NEXT: add sp, sp, #16
92 ; CHECK-NEXT: b callee_stack16
93
94 ; CHECK-ARM64: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #16]
95 ; CHECK-ARM64-NEXT: add sp, sp, #16
96 ; CHECK-ARM64-NEXT: b callee_stack16
97   ret void
98 }
99
100
101 define fastcc void @caller_to8_from24([8 x i32], i64 %a, i64 %b, i64 %c) {
102 ; CHECK-LABEL: caller_to8_from24:
103 ; CHECK: sub sp, sp, #16
104
105 ; CHECK-ARM64-LABEL: caller_to8_from24:
106 ; CHECK-ARM64: sub sp, sp, #16
107
108 ; Key point is that the "%a" should go where at #16 above SP on entry.
109   tail call fastcc void @callee_stack8([8 x i32] undef, i64 42)
110   ret void
111
112 ; CHECK: str {{x[0-9]+}}, [sp, #32]
113 ; CHECK-NEXT: add sp, sp, #32
114 ; CHECK-NEXT: b callee_stack8
115
116 ; CHECK-ARM64: str {{x[0-9]+}}, [sp, #32]!
117 ; CHECK-ARM64-NEXT: b callee_stack8
118 }
119
120
121 define fastcc void @caller_to16_from16([8 x i32], i64 %a, i64 %b) {
122 ; CHECK-LABEL: caller_to16_from16:
123 ; CHECK: sub sp, sp, #16
124
125 ; CHECK-ARM64-LABEL: caller_to16_from16:
126 ; CHECK-ARM64: sub sp, sp, #16
127
128 ; Here we want to make sure that both loads happen before the stores:
129 ; otherwise either %a or %b will be wrongly clobbered.
130   tail call fastcc void @callee_stack16([8 x i32] undef, i64 %b, i64 %a)
131   ret void
132
133 ; CHECK: ldr x0,
134 ; CHECK: ldr x1,
135 ; CHECK: str x1,
136 ; CHECK: str x0,
137
138 ; CHECK-NEXT: add sp, sp, #16
139 ; CHECK-NEXT: b callee_stack16
140
141 ; CHECK-ARM64: ldp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #16]
142 ; CHECK-ARM64: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #16]
143 ; CHECK-ARM64-NEXT: add sp, sp, #16
144 ; CHECK-ARM64-NEXT: b callee_stack16
145 }