1 ; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu | FileCheck %s --check-prefixes=SDAG,COMMON
2 ; RUN: llc -global-isel -global-isel-abort=1 -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu | FileCheck %s --check-prefixes=GISEL,COMMON
4 declare tailcc void @callee_stack0()
5 declare tailcc void @callee_stack8([8 x i64], i64)
6 declare tailcc void @callee_stack16([8 x i64], i64, i64)
7 declare extern_weak tailcc void @callee_weak()
9 define tailcc void @caller_to0_from0() nounwind {
10 ; COMMON-LABEL: caller_to0_from0:
11 ; COMMON-NEXT: // %bb.
13 tail call tailcc void @callee_stack0()
16 ; COMMON-NEXT: b callee_stack0
19 define tailcc void @caller_to0_from8([8 x i64], i64) {
20 ; COMMON-LABEL: caller_to0_from8:
22 tail call tailcc void @callee_stack0()
25 ; COMMON: add sp, sp, #16
26 ; COMMON-NEXT: b callee_stack0
29 define tailcc void @caller_to8_from0() "frame-pointer"="all"{
30 ; COMMON-LABEL: caller_to8_from0:
32 ; Key point is that the "42" should go #16 below incoming stack
33 ; pointer (we didn't have arg space to reuse).
34 tail call tailcc void @callee_stack8([8 x i64] undef, i64 42)
37 ; COMMON: str {{x[0-9]+}}, [x29, #16]
38 ; COMMON: ldp x29, x30, [sp], #16
39 ; If there is a sub here then the 42 will be briefly exposed to corruption
40 ; from an interrupt if the kernel does not honour a red-zone, and a larger
41 ; call could well overflow the red zone even if it is present.
43 ; COMMON-NEXT: b callee_stack8
46 define tailcc void @caller_to8_from8([8 x i64], i64 %a) {
47 ; COMMON-LABEL: caller_to8_from8:
50 ; Key point is that the "%a" should go where at SP on entry.
51 tail call tailcc void @callee_stack8([8 x i64] undef, i64 42)
54 ; COMMON: str {{x[0-9]+}}, [sp]
55 ; COMMON-NEXT: b callee_stack8
58 define tailcc void @caller_to16_from8([8 x i64], i64 %a) {
59 ; COMMON-LABEL: caller_to16_from8:
62 ; Important point is that the call reuses the "dead" argument space
63 ; above %a on the stack. If it tries to go below incoming-SP then the
64 ; callee will not deallocate the space, even in tailcc.
65 tail call tailcc void @callee_stack16([8 x i64] undef, i64 42, i64 2)
67 ; COMMON: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp]
68 ; COMMON-NEXT: b callee_stack16
73 define tailcc void @caller_to8_from24([8 x i64], i64 %a, i64 %b, i64 %c) {
74 ; COMMON-LABEL: caller_to8_from24:
77 ; Key point is that the "%a" should go where at #16 above SP on entry.
78 tail call tailcc void @callee_stack8([8 x i64] undef, i64 42)
81 ; COMMON: str {{x[0-9]+}}, [sp, #16]!
82 ; COMMON-NEXT: b callee_stack8
86 define tailcc void @caller_to16_from16([8 x i64], i64 %a, i64 %b) {
87 ; COMMON-LABEL: caller_to16_from16:
90 ; Here we want to make sure that both loads happen before the stores:
91 ; otherwise either %a or %b will be wrongly clobbered.
92 tail call tailcc void @callee_stack16([8 x i64] undef, i64 %b, i64 %a)
95 ; COMMON: ldp {{x[0-9]+}}, {{x[0-9]+}}, [sp]
96 ; COMMON: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp]
97 ; COMMON-NEXT: b callee_stack16
100 define tailcc void @disable_tail_calls() nounwind "disable-tail-calls"="true" {
101 ; COMMON-LABEL: disable_tail_calls:
102 ; COMMON-NEXT: // %bb.
104 tail call tailcc void @callee_stack0()
107 ; COMMON: bl callee_stack0
111 ; Weakly-referenced extern functions cannot be tail-called, as AAELF does
112 ; not define the behaviour of branch instructions to undefined weak symbols.
113 define tailcc void @caller_weak() {
114 ; COMMON-LABEL: caller_weak:
115 ; COMMON: bl callee_weak
116 tail call void @callee_weak()
120 declare { [2 x float] } @get_vec2()
122 define { [3 x float] } @test_add_elem() {
123 ; SDAG-LABEL: test_add_elem:
125 ; SDAG: fmov s2, #1.0
127 ; GISEL-LABEL: test_add_elem:
128 ; GISEL: str x30, [sp, #-16]!
130 ; GISEL: fmov s2, #1.0
131 ; GISEL: ldr x30, [sp], #16
134 %call = tail call { [2 x float] } @get_vec2()
135 %arr = extractvalue { [2 x float] } %call, 0
136 %arr.0 = extractvalue [2 x float] %arr, 0
137 %arr.1 = extractvalue [2 x float] %arr, 1
139 %res.0 = insertvalue { [3 x float] } undef, float %arr.0, 0, 0
140 %res.01 = insertvalue { [3 x float] } %res.0, float %arr.1, 0, 1
141 %res.012 = insertvalue { [3 x float] } %res.01, float 1.000000e+00, 0, 2
142 ret { [3 x float] } %res.012
145 declare double @get_double()
146 define { double, [2 x double] } @test_mismatched_insert() {
147 ; COMMON-LABEL: test_mismatched_insert:
148 ; COMMON: bl get_double
149 ; COMMON: bl get_double
150 ; COMMON: bl get_double
153 %val0 = call double @get_double()
154 %val1 = call double @get_double()
155 %val2 = tail call double @get_double()
157 %res.0 = insertvalue { double, [2 x double] } undef, double %val0, 0
158 %res.01 = insertvalue { double, [2 x double] } %res.0, double %val1, 1, 0
159 %res.012 = insertvalue { double, [2 x double] } %res.01, double %val2, 1, 1
161 ret { double, [2 x double] } %res.012
164 define void @fromC_totail() {
165 ; COMMON-LABEL: fromC_totail:
166 ; COMMON: sub sp, sp, #32
168 ; COMMON-NOT: sub sp,
169 ; COMMON: mov w[[TMP:[0-9]+]], #42
170 ; COMMON: str x[[TMP]], [sp]
171 ; COMMON: bl callee_stack8
172 ; We must reset the stack to where it was before the call by undoing its extra stack pop.
173 ; COMMON: str x[[TMP]], [sp, #-16]!
174 ; COMMON: bl callee_stack8
175 ; COMMON: sub sp, sp, #16
177 call tailcc void @callee_stack8([8 x i64] undef, i64 42)
178 call tailcc void @callee_stack8([8 x i64] undef, i64 42)
182 define void @fromC_totail_noreservedframe(i32 %len) {
183 ; COMMON-LABEL: fromC_totail_noreservedframe:
184 ; COMMON: stp x29, x30, [sp, #-32]!
186 ; COMMON: mov w[[TMP:[0-9]+]], #42
187 ; Note stack is subtracted here to allocate space for arg
188 ; COMMON: str x[[TMP]], [sp, #-16]!
189 ; COMMON: bl callee_stack8
191 ; COMMON: str x[[TMP]], [sp, #-16]!
192 ; COMMON: bl callee_stack8
193 ; But not restored here because callee_stack8 did that for us.
194 ; COMMON-NOT: sub sp,
196 ; Variable sized allocation prevents reserving frame at start of function so each call must allocate any stack space it needs.
197 %var = alloca i32, i32 %len
199 call tailcc void @callee_stack8([8 x i64] undef, i64 42)
200 call tailcc void @callee_stack8([8 x i64] undef, i64 42)
204 declare void @Ccallee_stack8([8 x i64], i64)
206 define tailcc void @fromtail_toC() {
207 ; COMMON-LABEL: fromtail_toC:
208 ; COMMON: sub sp, sp, #32
210 ; COMMON-NOT: sub sp,
211 ; COMMON: mov w[[TMP:[0-9]+]], #42
212 ; COMMON: str x[[TMP]], [sp]
213 ; COMMON: bl Ccallee_stack8
214 ; C callees will return with the stack exactly where we left it, so we mustn't try to fix anything.
215 ; COMMON-NOT: add sp,
216 ; COMMON-NOT: sub sp,
217 ; COMMON: str x[[TMP]], [sp]{{$}}
218 ; COMMON: bl Ccallee_stack8
219 ; COMMON-NOT: sub sp,
222 call void @Ccallee_stack8([8 x i64] undef, i64 42)
223 call void @Ccallee_stack8([8 x i64] undef, i64 42)