blob: 8aab842152600b97ffd2f97850ee42f207137242 [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu -tailcallopt | FileCheck %s
Tim Northovere0e3aef2013-01-31 12:12:40 +00002
3declare fastcc void @callee_stack0()
4declare fastcc void @callee_stack8([8 x i32], i64)
5declare fastcc void @callee_stack16([8 x i32], i64, i64)
6
7define fastcc void @caller_to0_from0() nounwind {
Stephen Lind24ab202013-07-14 06:24:09 +00008; CHECK-LABEL: caller_to0_from0:
Tim Northovere0e3aef2013-01-31 12:12:40 +00009; CHECK-NEXT: // BB
Jiangning Liu09cc5642014-05-15 01:33:17 +000010
Tim Northovere0e3aef2013-01-31 12:12:40 +000011 tail call fastcc void @callee_stack0()
12 ret void
Jiangning Liu09cc5642014-05-15 01:33:17 +000013
Tim Northovere0e3aef2013-01-31 12:12:40 +000014; CHECK-NEXT: b callee_stack0
15}
16
17define fastcc void @caller_to0_from8([8 x i32], i64) {
Stephen Lind24ab202013-07-14 06:24:09 +000018; CHECK-LABEL: caller_to0_from8:
Tim Northovere0e3aef2013-01-31 12:12:40 +000019
20 tail call fastcc void @callee_stack0()
21 ret void
Jiangning Liu09cc5642014-05-15 01:33:17 +000022
Tim Northovere0e3aef2013-01-31 12:12:40 +000023; CHECK: add sp, sp, #16
24; CHECK-NEXT: b callee_stack0
25}
26
27define fastcc void @caller_to8_from0() {
Stephen Lind24ab202013-07-14 06:24:09 +000028; CHECK-LABEL: caller_to8_from0:
Tim Northovere0e3aef2013-01-31 12:12:40 +000029; CHECK: sub sp, sp, #32
30
31; Key point is that the "42" should go #16 below incoming stack
32; pointer (we didn't have arg space to reuse).
33 tail call fastcc void @callee_stack8([8 x i32] undef, i64 42)
34 ret void
Jiangning Liu09cc5642014-05-15 01:33:17 +000035
Tim Northover3b0846e2014-05-24 12:50:23 +000036; CHECK: str {{x[0-9]+}}, [sp, #16]!
Tim Northovere0e3aef2013-01-31 12:12:40 +000037; CHECK-NEXT: b callee_stack8
38}
39
40define fastcc void @caller_to8_from8([8 x i32], i64 %a) {
Stephen Lind24ab202013-07-14 06:24:09 +000041; CHECK-LABEL: caller_to8_from8:
Tim Northovere0e3aef2013-01-31 12:12:40 +000042; CHECK: sub sp, sp, #16
43
44; Key point is that the "%a" should go where at SP on entry.
45 tail call fastcc void @callee_stack8([8 x i32] undef, i64 42)
46 ret void
Jiangning Liu09cc5642014-05-15 01:33:17 +000047
Tim Northover3b0846e2014-05-24 12:50:23 +000048; CHECK: str {{x[0-9]+}}, [sp, #16]!
Tim Northovere0e3aef2013-01-31 12:12:40 +000049; CHECK-NEXT: b callee_stack8
50}
51
52define fastcc void @caller_to16_from8([8 x i32], i64 %a) {
Stephen Lind24ab202013-07-14 06:24:09 +000053; CHECK-LABEL: caller_to16_from8:
Tim Northovere0e3aef2013-01-31 12:12:40 +000054; CHECK: sub sp, sp, #16
55
56; Important point is that the call reuses the "dead" argument space
57; above %a on the stack. If it tries to go below incoming-SP then the
58; callee will not deallocate the space, even in fastcc.
59 tail call fastcc void @callee_stack16([8 x i32] undef, i64 42, i64 2)
Jiangning Liu09cc5642014-05-15 01:33:17 +000060
Tim Northover3b0846e2014-05-24 12:50:23 +000061; CHECK: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #16]
Jiangning Liu09cc5642014-05-15 01:33:17 +000062; CHECK-NEXT: add sp, sp, #16
63; CHECK-NEXT: b callee_stack16
Tim Northovere0e3aef2013-01-31 12:12:40 +000064 ret void
65}
66
67
68define fastcc void @caller_to8_from24([8 x i32], i64 %a, i64 %b, i64 %c) {
Stephen Lind24ab202013-07-14 06:24:09 +000069; CHECK-LABEL: caller_to8_from24:
Tim Northovere0e3aef2013-01-31 12:12:40 +000070; CHECK: sub sp, sp, #16
71
72; Key point is that the "%a" should go where at #16 above SP on entry.
73 tail call fastcc void @callee_stack8([8 x i32] undef, i64 42)
74 ret void
Jiangning Liu09cc5642014-05-15 01:33:17 +000075
Tim Northover3b0846e2014-05-24 12:50:23 +000076; CHECK: str {{x[0-9]+}}, [sp, #32]!
Tim Northovere0e3aef2013-01-31 12:12:40 +000077; CHECK-NEXT: b callee_stack8
78}
79
80
81define fastcc void @caller_to16_from16([8 x i32], i64 %a, i64 %b) {
Stephen Lind24ab202013-07-14 06:24:09 +000082; CHECK-LABEL: caller_to16_from16:
Tim Northovere0e3aef2013-01-31 12:12:40 +000083; CHECK: sub sp, sp, #16
84
85; Here we want to make sure that both loads happen before the stores:
86; otherwise either %a or %b will be wrongly clobbered.
87 tail call fastcc void @callee_stack16([8 x i32] undef, i64 %b, i64 %a)
88 ret void
89
Tim Northover3b0846e2014-05-24 12:50:23 +000090; CHECK: ldp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #16]
91; CHECK: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #16]
Jiangning Liu09cc5642014-05-15 01:33:17 +000092; CHECK-NEXT: add sp, sp, #16
93; CHECK-NEXT: b callee_stack16
Tim Northovere0e3aef2013-01-31 12:12:40 +000094}