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
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)
8 define fastcc void @caller_to0_from0() nounwind {
9 ; CHECK-LABEL: caller_to0_from0:
12 ; CHECK-ARM64-LABEL: caller_to0_from0:
13 ; CHECK-ARM64-NEXT: // BB
15 tail call fastcc void @callee_stack0()
18 ; CHECK-NEXT: b callee_stack0
20 ; CHECK-ARM64-NEXT: b callee_stack0
23 define fastcc void @caller_to0_from8([8 x i32], i64) {
24 ; CHECK-LABEL: caller_to0_from8:
26 ; CHECK-ARM64-LABEL: caller_to0_from8:
28 tail call fastcc void @callee_stack0()
31 ; CHECK: add sp, sp, #16
32 ; CHECK-NEXT: b callee_stack0
34 ; CHECK-ARM64: add sp, sp, #16
35 ; CHECK-ARM64-NEXT: b callee_stack0
38 define fastcc void @caller_to8_from0() {
39 ; CHECK-LABEL: caller_to8_from0:
40 ; CHECK: sub sp, sp, #32
42 ; CHECK-ARM64-LABEL: caller_to8_from0:
43 ; CHECK-ARM64: sub sp, sp, #32
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)
50 ; CHECK: str {{x[0-9]+}}, [sp, #16]
51 ; CHECK-NEXT: add sp, sp, #16
52 ; CHECK-NEXT: b callee_stack8
54 ; CHECK-ARM64: str {{x[0-9]+}}, [sp, #16]!
55 ; CHECK-ARM64-NEXT: b callee_stack8
58 define fastcc void @caller_to8_from8([8 x i32], i64 %a) {
59 ; CHECK-LABEL: caller_to8_from8:
60 ; CHECK: sub sp, sp, #16
62 ; CHECK-ARM64-LABEL: caller_to8_from8:
63 ; CHECK-ARM64: sub sp, sp, #16
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)
69 ; CHECK: str {{x[0-9]+}}, [sp, #16]
70 ; CHECK-NEXT: add sp, sp, #16
71 ; CHECK-NEXT: b callee_stack8
73 ; CHECK-ARM64: str {{x[0-9]+}}, [sp, #16]!
74 ; CHECK-ARM64-NEXT: b callee_stack8
77 define fastcc void @caller_to16_from8([8 x i32], i64 %a) {
78 ; CHECK-LABEL: caller_to16_from8:
79 ; CHECK: sub sp, sp, #16
81 ; CHECK-ARM64-LABEL: caller_to16_from8:
82 ; CHECK-ARM64: sub sp, sp, #16
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)
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
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
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
105 ; CHECK-ARM64-LABEL: caller_to8_from24:
106 ; CHECK-ARM64: sub sp, sp, #16
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)
112 ; CHECK: str {{x[0-9]+}}, [sp, #32]
113 ; CHECK-NEXT: add sp, sp, #32
114 ; CHECK-NEXT: b callee_stack8
116 ; CHECK-ARM64: str {{x[0-9]+}}, [sp, #32]!
117 ; CHECK-ARM64-NEXT: b callee_stack8
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
125 ; CHECK-ARM64-LABEL: caller_to16_from16:
126 ; CHECK-ARM64: sub sp, sp, #16
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)
138 ; CHECK-NEXT: add sp, sp, #16
139 ; CHECK-NEXT: b callee_stack16
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