[ARM64] Support aggressive fastcc/tailcallopt breaking ABI by popping out argument...
[oota-llvm.git] / test / CodeGen / AArch64 / fastcc-reserved.ll
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 %s --check-prefix=CHECK-ARM64
3
4 ; This test is designed to be run in the situation where the
5 ; call-frame is not reserved (hence disable-fp-elim), but where
6 ; callee-pop can occur (hence tailcallopt).
7
8 declare fastcc void @will_pop([8 x i32], i32 %val)
9
10 define fastcc void @foo(i32 %in) {
11 ; CHECK-LABEL: foo:
12
13   %addr = alloca i8, i32 %in
14
15 ; Normal frame setup stuff:
16 ; CHECK: sub sp, sp,
17 ; CHECK: stp x29, x30
18 ; CHECK-ARM64: stp     x29, x30, [sp, #-16]!
19 ; CHECK-ARM64: mov     x29, sp
20
21 ; Reserve space for call-frame:
22 ; CHECK: sub sp, sp, #16
23 ; CHECK-ARM64: sub sp, sp, #16
24
25   call fastcc void @will_pop([8 x i32] undef, i32 42)
26 ; CHECK: bl will_pop
27 ; CHECK-ARM64: bl will_pop
28
29 ; Since @will_pop is fastcc with tailcallopt, it will put the stack
30 ; back where it needs to be, we shouldn't duplicate that
31 ; CHECK-NOT: sub sp, sp, #16
32 ; CHECK-NOT: add sp, sp,
33 ; CHECK-ARM64-NOT: sub sp, sp, #16
34 ; CHECK-ARM64-NOT: add sp, sp,
35
36 ; CHECK: ldp x29, x30
37 ; CHECK: add sp, sp,
38 ; CHECK-ARM64: mov     sp, x29
39 ; CHECK-ARM64: ldp     x29, x30, [sp], #16
40   ret void
41 }
42
43 declare void @wont_pop([8 x i32], i32 %val)
44
45 define void @foo1(i32 %in) {
46 ; CHECK-LABEL: foo1:
47
48   %addr = alloca i8, i32 %in
49 ; Normal frame setup again
50 ; CHECK: sub sp, sp,
51 ; CHECK: stp x29, x30
52 ; CHECK-ARM64: stp     x29, x30, [sp, #-16]!
53 ; CHECK-ARM64: mov     x29, sp
54
55 ; Reserve space for call-frame
56 ; CHECK: sub sp, sp, #16
57 ; CHECK-ARM64: sub sp, sp, #16
58
59   call void @wont_pop([8 x i32] undef, i32 42)
60 ; CHECK: bl wont_pop
61 ; CHECK-ARM64: bl wont_pop
62
63 ; This time we *do* need to unreserve the call-frame
64 ; CHECK: add sp, sp, #16
65 ; CHECK-ARM64: add sp, sp, #16
66
67 ; Check for epilogue (primarily to make sure sp spotted above wasn't
68 ; part of it).
69 ; CHECK: ldp x29, x30
70 ; CHECK: add sp, sp,
71 ; CHECK-ARM64: mov     sp, x29
72 ; CHECK-ARM64: ldp     x29, x30, [sp], #16
73   ret void
74 }