blob: da05848dcc59327bfb5d2a34fdd77f118b323e6c [file] [log] [blame]
Tim Northovere3d42362013-02-01 11:40:47 +00001; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu -tailcallopt | FileCheck %s
Jiangning Liu09cc5642014-05-15 01:33:17 +00002; RUN: llc -verify-machineinstrs < %s -mtriple=arm64-none-linux-gnu -tailcallopt | FileCheck --check-prefix=CHECK-ARM64 %s
Tim Northovere0e3aef2013-01-31 12:12:40 +00003
4declare fastcc void @callee_stack0()
5declare fastcc void @callee_stack8([8 x i32], i64)
6declare fastcc void @callee_stack16([8 x i32], i64, i64)
7
8define fastcc void @caller_to0_from0() nounwind {
Stephen Lind24ab202013-07-14 06:24:09 +00009; CHECK-LABEL: caller_to0_from0:
Tim Northovere0e3aef2013-01-31 12:12:40 +000010; CHECK-NEXT: // BB
Jiangning Liu09cc5642014-05-15 01:33:17 +000011
12; CHECK-ARM64-LABEL: caller_to0_from0:
13; CHECK-ARM64-NEXT: // BB
14
Tim Northovere0e3aef2013-01-31 12:12:40 +000015 tail call fastcc void @callee_stack0()
16 ret void
Jiangning Liu09cc5642014-05-15 01:33:17 +000017
Tim Northovere0e3aef2013-01-31 12:12:40 +000018; CHECK-NEXT: b callee_stack0
Jiangning Liu09cc5642014-05-15 01:33:17 +000019
20; CHECK-ARM64-NEXT: b callee_stack0
Tim Northovere0e3aef2013-01-31 12:12:40 +000021}
22
23define fastcc void @caller_to0_from8([8 x i32], i64) {
Stephen Lind24ab202013-07-14 06:24:09 +000024; CHECK-LABEL: caller_to0_from8:
Tim Northovere0e3aef2013-01-31 12:12:40 +000025
Jiangning Liu09cc5642014-05-15 01:33:17 +000026; CHECK-ARM64-LABEL: caller_to0_from8:
27
Tim Northovere0e3aef2013-01-31 12:12:40 +000028 tail call fastcc void @callee_stack0()
29 ret void
Jiangning Liu09cc5642014-05-15 01:33:17 +000030
Tim Northovere0e3aef2013-01-31 12:12:40 +000031; CHECK: add sp, sp, #16
32; CHECK-NEXT: b callee_stack0
Jiangning Liu09cc5642014-05-15 01:33:17 +000033
34; CHECK-ARM64: add sp, sp, #16
35; CHECK-ARM64-NEXT: b callee_stack0
Tim Northovere0e3aef2013-01-31 12:12:40 +000036}
37
38define fastcc void @caller_to8_from0() {
Stephen Lind24ab202013-07-14 06:24:09 +000039; CHECK-LABEL: caller_to8_from0:
Tim Northovere0e3aef2013-01-31 12:12:40 +000040; CHECK: sub sp, sp, #32
41
Jiangning Liu09cc5642014-05-15 01:33:17 +000042; CHECK-ARM64-LABEL: caller_to8_from0:
43; CHECK-ARM64: sub sp, sp, #32
44
Tim Northovere0e3aef2013-01-31 12:12:40 +000045; 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
Jiangning Liu09cc5642014-05-15 01:33:17 +000049
Tim Northovere0e3aef2013-01-31 12:12:40 +000050; CHECK: str {{x[0-9]+}}, [sp, #16]
51; CHECK-NEXT: add sp, sp, #16
52; CHECK-NEXT: b callee_stack8
Jiangning Liu09cc5642014-05-15 01:33:17 +000053
54; CHECK-ARM64: str {{x[0-9]+}}, [sp, #16]!
55; CHECK-ARM64-NEXT: b callee_stack8
Tim Northovere0e3aef2013-01-31 12:12:40 +000056}
57
58define fastcc void @caller_to8_from8([8 x i32], i64 %a) {
Stephen Lind24ab202013-07-14 06:24:09 +000059; CHECK-LABEL: caller_to8_from8:
Tim Northovere0e3aef2013-01-31 12:12:40 +000060; CHECK: sub sp, sp, #16
61
Jiangning Liu09cc5642014-05-15 01:33:17 +000062; CHECK-ARM64-LABEL: caller_to8_from8:
63; CHECK-ARM64: sub sp, sp, #16
64
Tim Northovere0e3aef2013-01-31 12:12:40 +000065; 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
Jiangning Liu09cc5642014-05-15 01:33:17 +000068
Tim Northovere0e3aef2013-01-31 12:12:40 +000069; CHECK: str {{x[0-9]+}}, [sp, #16]
70; CHECK-NEXT: add sp, sp, #16
71; CHECK-NEXT: b callee_stack8
Jiangning Liu09cc5642014-05-15 01:33:17 +000072
73; CHECK-ARM64: str {{x[0-9]+}}, [sp, #16]!
74; CHECK-ARM64-NEXT: b callee_stack8
Tim Northovere0e3aef2013-01-31 12:12:40 +000075}
76
77define fastcc void @caller_to16_from8([8 x i32], i64 %a) {
Stephen Lind24ab202013-07-14 06:24:09 +000078; CHECK-LABEL: caller_to16_from8:
Tim Northovere0e3aef2013-01-31 12:12:40 +000079; CHECK: sub sp, sp, #16
80
Jiangning Liu09cc5642014-05-15 01:33:17 +000081; CHECK-ARM64-LABEL: caller_to16_from8:
82; CHECK-ARM64: sub sp, sp, #16
83
Tim Northovere0e3aef2013-01-31 12:12:40 +000084; 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)
Jiangning Liu09cc5642014-05-15 01:33:17 +000088
Tim Northovere0e3aef2013-01-31 12:12:40 +000089; CHECK: str {{x[0-9]+}}, [sp, #24]
90; CHECK: str {{x[0-9]+}}, [sp, #16]
Jiangning Liu09cc5642014-05-15 01:33:17 +000091; 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
Tim Northovere0e3aef2013-01-31 12:12:40 +000097 ret void
98}
99
100
101define fastcc void @caller_to8_from24([8 x i32], i64 %a, i64 %b, i64 %c) {
Stephen Lind24ab202013-07-14 06:24:09 +0000102; CHECK-LABEL: caller_to8_from24:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000103; CHECK: sub sp, sp, #16
104
Jiangning Liu09cc5642014-05-15 01:33:17 +0000105; CHECK-ARM64-LABEL: caller_to8_from24:
106; CHECK-ARM64: sub sp, sp, #16
107
Tim Northovere0e3aef2013-01-31 12:12:40 +0000108; 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
Jiangning Liu09cc5642014-05-15 01:33:17 +0000111
Tim Northovere0e3aef2013-01-31 12:12:40 +0000112; CHECK: str {{x[0-9]+}}, [sp, #32]
113; CHECK-NEXT: add sp, sp, #32
114; CHECK-NEXT: b callee_stack8
Jiangning Liu09cc5642014-05-15 01:33:17 +0000115
116; CHECK-ARM64: str {{x[0-9]+}}, [sp, #32]!
117; CHECK-ARM64-NEXT: b callee_stack8
Tim Northovere0e3aef2013-01-31 12:12:40 +0000118}
119
120
121define fastcc void @caller_to16_from16([8 x i32], i64 %a, i64 %b) {
Stephen Lind24ab202013-07-14 06:24:09 +0000122; CHECK-LABEL: caller_to16_from16:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000123; CHECK: sub sp, sp, #16
124
Jiangning Liu09cc5642014-05-15 01:33:17 +0000125; CHECK-ARM64-LABEL: caller_to16_from16:
126; CHECK-ARM64: sub sp, sp, #16
127
Tim Northovere0e3aef2013-01-31 12:12:40 +0000128; 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
Jiangning Liu09cc5642014-05-15 01:33:17 +0000138; 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
Tim Northovere0e3aef2013-01-31 12:12:40 +0000145}