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) #0 {
20 ; COMMON-LABEL: caller_to0_from8:
22 tail call tailcc void @callee_stack0()
25 ; COMMON: add sp, sp, #16
26 ; COMMON: .cfi_def_cfa_offset -16
27 ; COMMON-NEXT: b callee_stack0
30 define tailcc void @caller_to8_from0() "frame-pointer"="all" uwtable {
31 ; COMMON-LABEL: caller_to8_from0:
33 ; Key point is that the "42" should go #16 below incoming stack
34 ; pointer (we didn't have arg space to reuse).
35 tail call tailcc void @callee_stack8([8 x i64] undef, i64 42)
38 ; COMMON: str {{x[0-9]+}}, [x29, #16]
39 ; COMMON: ldp x29, x30, [sp], #16
40 ; If there is a sub here then the 42 will be briefly exposed to corruption
41 ; from an interrupt if the kernel does not honour a red-zone, and a larger
42 ; call could well overflow the red zone even if it is present.
44 ; COMMON-NEXT: .cfi_def_cfa_offset 16
45 ; COMMON-NEXT: .cfi_restore w30
46 ; COMMON-NEXT: .cfi_restore w29
47 ; COMMON-NEXT: b callee_stack8
50 define tailcc void @caller_to8_from8([8 x i64], i64 %a) #0 {
51 ; COMMON-LABEL: caller_to8_from8:
54 ; Key point is that the "%a" should go where at SP on entry.
55 tail call tailcc void @callee_stack8([8 x i64] undef, i64 42)
58 ; COMMON: str {{x[0-9]+}}, [sp]
59 ; COMMON-NEXT: b callee_stack8
62 define tailcc void @caller_to16_from8([8 x i64], i64 %a) #0 {
63 ; COMMON-LABEL: caller_to16_from8:
66 ; Important point is that the call reuses the "dead" argument space
67 ; above %a on the stack. If it tries to go below incoming-SP then the
68 ; callee will not deallocate the space, even in tailcc.
69 tail call tailcc void @callee_stack16([8 x i64] undef, i64 42, i64 2)
71 ; COMMON: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp]
72 ; COMMON-NEXT: b callee_stack16
77 define tailcc void @caller_to8_from24([8 x i64], i64 %a, i64 %b, i64 %c) #0 {
78 ; COMMON-LABEL: caller_to8_from24:
81 ; Key point is that the "%a" should go where at #16 above SP on entry.
82 tail call tailcc void @callee_stack8([8 x i64] undef, i64 42)
85 ; COMMON: str {{x[0-9]+}}, [sp, #16]!
86 ; COMMON-NEXT: .cfi_def_cfa_offset -16
87 ; COMMON-NEXT: b callee_stack8
91 define tailcc void @caller_to16_from16([8 x i64], i64 %a, i64 %b) #0 {
92 ; COMMON-LABEL: caller_to16_from16:
95 ; Here we want to make sure that both loads happen before the stores:
96 ; otherwise either %a or %b will be wrongly clobbered.
97 tail call tailcc void @callee_stack16([8 x i64] undef, i64 %b, i64 %a)
100 ; COMMON: ldp {{x[0-9]+}}, {{x[0-9]+}}, [sp]
101 ; COMMON: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp]
102 ; COMMON-NEXT: b callee_stack16
105 define tailcc void @disable_tail_calls() nounwind "disable-tail-calls"="true" {
106 ; COMMON-LABEL: disable_tail_calls:
107 ; COMMON-NEXT: // %bb.
109 tail call tailcc void @callee_stack0()
112 ; COMMON: bl callee_stack0
116 ; Weakly-referenced extern functions cannot be tail-called, as AAELF does
117 ; not define the behaviour of branch instructions to undefined weak symbols.
118 define tailcc void @caller_weak() #0 {
119 ; COMMON-LABEL: caller_weak:
120 ; COMMON: bl callee_weak
121 tail call void @callee_weak()
125 declare { [2 x float] } @get_vec2()
127 define { [3 x float] } @test_add_elem() #0 {
128 ; SDAG-LABEL: test_add_elem:
130 ; SDAG: fmov s2, #1.0
132 ; GISEL-LABEL: test_add_elem:
133 ; GISEL: str x30, [sp, #-16]!
135 ; GISEL: fmov s2, #1.0
136 ; GISEL: ldr x30, [sp], #16
139 %call = tail call { [2 x float] } @get_vec2()
140 %arr = extractvalue { [2 x float] } %call, 0
141 %arr.0 = extractvalue [2 x float] %arr, 0
142 %arr.1 = extractvalue [2 x float] %arr, 1
144 %res.0 = insertvalue { [3 x float] } undef, float %arr.0, 0, 0
145 %res.01 = insertvalue { [3 x float] } %res.0, float %arr.1, 0, 1
146 %res.012 = insertvalue { [3 x float] } %res.01, float 1.000000e+00, 0, 2
147 ret { [3 x float] } %res.012
150 declare double @get_double()
151 define { double, [2 x double] } @test_mismatched_insert() #0 {
152 ; COMMON-LABEL: test_mismatched_insert:
153 ; COMMON: bl get_double
154 ; COMMON: bl get_double
155 ; COMMON: bl get_double
158 %val0 = call double @get_double()
159 %val1 = call double @get_double()
160 %val2 = tail call double @get_double()
162 %res.0 = insertvalue { double, [2 x double] } undef, double %val0, 0
163 %res.01 = insertvalue { double, [2 x double] } %res.0, double %val1, 1, 0
164 %res.012 = insertvalue { double, [2 x double] } %res.01, double %val2, 1, 1
166 ret { double, [2 x double] } %res.012
169 define void @fromC_totail() #0 {
170 ; COMMON-LABEL: fromC_totail:
171 ; COMMON: sub sp, sp, #32
173 ; COMMON-NOT: sub sp,
174 ; COMMON: mov w[[TMP:[0-9]+]], #42
175 ; COMMON: str x[[TMP]], [sp]
176 ; COMMON: bl callee_stack8
177 ; We must reset the stack to where it was before the call by undoing its extra stack pop.
178 ; COMMON: str x[[TMP]], [sp, #-16]!
179 ; COMMON: bl callee_stack8
180 ; COMMON: sub sp, sp, #16
182 call tailcc void @callee_stack8([8 x i64] undef, i64 42)
183 call tailcc void @callee_stack8([8 x i64] undef, i64 42)
187 define void @fromC_totail_noreservedframe(i32 %len) #0 {
188 ; COMMON-LABEL: fromC_totail_noreservedframe:
189 ; COMMON: stp x29, x30, [sp, #-32]!
191 ; COMMON: mov w[[TMP:[0-9]+]], #42
192 ; Note stack is subtracted here to allocate space for arg
193 ; COMMON: str x[[TMP]], [sp, #-16]!
194 ; COMMON: bl callee_stack8
196 ; COMMON: str x[[TMP]], [sp, #-16]!
197 ; COMMON: bl callee_stack8
198 ; But not restored here because callee_stack8 did that for us.
199 ; COMMON-NOT: sub sp,
201 ; Variable sized allocation prevents reserving frame at start of function so each call must allocate any stack space it needs.
202 %var = alloca i32, i32 %len
204 call tailcc void @callee_stack8([8 x i64] undef, i64 42)
205 call tailcc void @callee_stack8([8 x i64] undef, i64 42)
209 declare void @Ccallee_stack8([8 x i64], i64)
211 define tailcc void @fromtail_toC() #0 {
212 ; COMMON-LABEL: fromtail_toC:
213 ; COMMON: sub sp, sp, #32
215 ; COMMON-NOT: sub sp,
216 ; COMMON: mov w[[TMP:[0-9]+]], #42
217 ; COMMON: str x[[TMP]], [sp]
218 ; COMMON: bl Ccallee_stack8
219 ; C callees will return with the stack exactly where we left it, so we mustn't try to fix anything.
220 ; COMMON-NOT: add sp,
221 ; COMMON-NOT: sub sp,
222 ; COMMON: str x[[TMP]], [sp]{{$}}
223 ; COMMON: bl Ccallee_stack8
224 ; COMMON-NOT: sub sp,
227 call void @Ccallee_stack8([8 x i64] undef, i64 42)
228 call void @Ccallee_stack8([8 x i64] undef, i64 42)
232 attributes #0 = { uwtable }