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