AArch64/ARM64: enable more AArch64 tests.
[oota-llvm.git] / test / CodeGen / AArch64 / sibling-call.ll
1 ; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu | FileCheck %s
2 ; RUN: llc -verify-machineinstrs < %s -mtriple=arm64-none-linux-gnu -arm64-load-store-opt=0 | FileCheck %s
3
4 declare void @callee_stack0()
5 declare void @callee_stack8([8 x i32], i64)
6 declare void @callee_stack16([8 x i32], i64, i64)
7
8 define void @caller_to0_from0() nounwind {
9 ; CHECK-LABEL: caller_to0_from0:
10 ; CHECK-NEXT: // BB
11   tail call void @callee_stack0()
12   ret void
13 ; CHECK-NEXT: b callee_stack0
14 }
15
16 define void @caller_to0_from8([8 x i32], i64) nounwind{
17 ; CHECK-LABEL: caller_to0_from8:
18 ; CHECK-NEXT: // BB
19
20   tail call void @callee_stack0()
21   ret void
22 ; CHECK-NEXT: b callee_stack0
23 }
24
25 define void @caller_to8_from0() {
26 ; CHECK-LABEL: caller_to8_from0:
27
28 ; Caller isn't going to clean up any extra stack we allocate, so it
29 ; can't be a tail call.
30   tail call void @callee_stack8([8 x i32] undef, i64 42)
31   ret void
32 ; CHECK: bl callee_stack8
33 }
34
35 define void @caller_to8_from8([8 x i32], i64 %a) {
36 ; CHECK-LABEL: caller_to8_from8:
37 ; CHECK-NOT: sub sp, sp,
38
39 ; This should reuse our stack area for the 42
40   tail call void @callee_stack8([8 x i32] undef, i64 42)
41   ret void
42 ; CHECK: str {{x[0-9]+}}, [sp]
43 ; CHECK-NEXT: b callee_stack8
44 }
45
46 define void @caller_to16_from8([8 x i32], i64 %a) {
47 ; CHECK-LABEL: caller_to16_from8:
48
49 ; Shouldn't be a tail call: we can't use SP+8 because our caller might
50 ; have something there. This may sound obvious but implementation does
51 ; some funky aligning.
52   tail call void @callee_stack16([8 x i32] undef, i64 undef, i64 undef)
53 ; CHECK: bl callee_stack16
54   ret void
55 }
56
57 define void @caller_to8_from24([8 x i32], i64 %a, i64 %b, i64 %c) {
58 ; CHECK-LABEL: caller_to8_from24:
59 ; CHECK-NOT: sub sp, sp
60
61 ; Reuse our area, putting "42" at incoming sp
62   tail call void @callee_stack8([8 x i32] undef, i64 42)
63   ret void
64 ; CHECK: str {{x[0-9]+}}, [sp]
65 ; CHECK-NEXT: b callee_stack8
66 }
67
68 define void @caller_to16_from16([8 x i32], i64 %a, i64 %b) {
69 ; CHECK-LABEL: caller_to16_from16:
70 ; CHECK-NOT: sub sp, sp,
71
72 ; Here we want to make sure that both loads happen before the stores:
73 ; otherwise either %a or %b will be wrongly clobbered.
74   tail call void @callee_stack16([8 x i32] undef, i64 %b, i64 %a)
75   ret void
76
77 ; CHECK: ldr [[VAL0:x[0-9]+]],
78 ; CHECK: ldr [[VAL1:x[0-9]+]],
79 ; CHECK: str [[VAL1]],
80 ; CHECK: str [[VAL0]],
81
82 ; CHECK-NOT: add sp, sp,
83 ; CHECK: b callee_stack16
84 }
85
86 @func = global void(i32)* null
87
88 define void @indirect_tail() {
89 ; CHECK-LABEL: indirect_tail:
90 ; CHECK-NOT: sub sp, sp
91
92   %fptr = load void(i32)** @func
93   tail call void %fptr(i32 42)
94   ret void
95 ; CHECK: ldr [[FPTR:x[1-9]+]], [{{x[0-9]+}}, {{#?}}:lo12:func]
96 ; CHECK: movz w0, #{{42|0x2a}}
97 ; CHECK: br [[FPTR]]
98 }