• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc -mtriple=aarch64-linux-gnu -disable-post-ra -verify-machineinstrs -o - %s | FileCheck %s --check-prefix=CHECK
2; RUN: llc -mtriple=aarch64-none-linux-gnu -disable-post-ra -mattr=-fp-armv8 -verify-machineinstrs < %s | FileCheck --check-prefix=CHECK-NOFP-ARM64 %s
3
4declare void @use_addr(i8*)
5
6define void @test_simple_alloca(i64 %n) {
7; CHECK-LABEL: test_simple_alloca:
8
9  %buf = alloca i8, i64 %n
10  ; Make sure we align the stack change to 16 bytes:
11; CHECK: {{mov|add}} x29
12; CHECK: mov [[TMP:x[0-9]+]], sp
13; CHECK: add [[SPDELTA_TMP:x[0-9]+]], x0, #15
14; CHECK: and [[SPDELTA:x[0-9]+]], [[SPDELTA_TMP]], #0xfffffffffffffff0
15
16  ; Make sure we change SP. It would be surprising if anything but x0 were used
17  ; for the final sp, but it could be if it was then moved into x0.
18; CHECK: sub [[NEWSP:x[0-9]+]], [[TMP]], [[SPDELTA]]
19; CHECK: mov sp, [[NEWSP]]
20
21  call void @use_addr(i8* %buf)
22; CHECK: bl use_addr
23
24  ret void
25  ; Make sure epilogue restores sp from fp
26; CHECK: {{sub|mov}} sp, x29
27; CHECK: ret
28}
29
30declare void @use_addr_loc(i8*, i64*)
31
32define i64 @test_alloca_with_local(i64 %n) {
33; CHECK-LABEL: test_alloca_with_local:
34; CHECK-DAG: sub sp, sp, [[LOCAL_STACK:#[0-9]+]]
35; CHECK-DAG: {{mov|add}} x29, sp
36
37  %loc = alloca i64
38  %buf = alloca i8, i64 %n
39  ; Make sure we align the stack change to 16 bytes:
40; CHECK: mov [[TMP:x[0-9]+]], sp
41; CHECK: add [[SPDELTA_TMP:x[0-9]+]], x0, #15
42; CHECK: and [[SPDELTA:x[0-9]+]], [[SPDELTA_TMP]], #0xfffffffffffffff0
43
44  ; Make sure we change SP. It would be surprising if anything but x0 were used
45  ; for the final sp, but it could be if it was then moved into x0.
46; CHECK: sub [[NEWSP:x[0-9]+]], [[TMP]], [[SPDELTA]]
47; CHECK: mov sp, [[NEWSP]]
48
49; CHECK: sub {{x[0-9]+}}, x29, #[[LOC_FROM_FP:[0-9]+]]
50
51  call void @use_addr_loc(i8* %buf, i64* %loc)
52; CHECK: bl use_addr
53
54  %val = load i64, i64* %loc
55
56; CHECK: ldur x0, [x29, #-[[LOC_FROM_FP]]]
57
58  ret i64 %val
59  ; Make sure epilogue restores sp from fp
60; CHECK: {{sub|mov}} sp, x29
61; CHECK: ret
62}
63
64define void @test_variadic_alloca(i64 %n, ...) {
65; CHECK-LABEL: test_variadic_alloca:
66
67; [...]
68
69
70; CHECK-NOFP-AARCH64: sub     sp, sp, #80
71; CHECK-NOFP-AARCH64: stp     x29, x30, [sp, #64]
72; CHECK-NOFP-AARCH64: add     x29, sp, #64
73; CHECK-NOFP-AARCH64: sub     [[TMP:x[0-9]+]], x29, #64
74; CHECK-NOFP-AARCH64: add     x8, [[TMP]], #0
75
76
77; CHECK: stp     x29, x30, [sp, #-16]!
78; CHECK: mov     x29, sp
79; CHECK: sub     sp, sp, #192
80; CHECK: stp     q6, q7, [x29, #-96]
81; [...]
82; CHECK: stp     q0, q1, [x29, #-192]
83
84; CHECK: stp     x6, x7, [x29, #-16]
85; [...]
86; CHECK: stp     x2, x3, [x29, #-48]
87
88; CHECK-NOFP-ARM64: stp     x29, x30, [sp, #-16]!
89; CHECK-NOFP-ARM64: mov     x29, sp
90; CHECK-NOFP-ARM64: sub     sp, sp, #64
91; CHECK-NOFP-ARM64: stp     x6, x7, [x29, #-16]
92; [...]
93; CHECK-NOFP-ARM64: stp     x4, x5, [x29, #-32]
94; [...]
95; CHECK-NOFP-ARM64: stp     x2, x3, [x29, #-48]
96; [...]
97; CHECK-NOFP-ARM64: mov     x8, sp
98
99  %addr = alloca i8, i64 %n
100
101  call void @use_addr(i8* %addr)
102; CHECK: bl use_addr
103
104  ret void
105
106; CHECK-NOFP-AARCH64: sub sp, x29, #64
107; CHECK-NOFP-AARCH64: ldp x29, x30, [sp, #64]
108; CHECK-NOFP-AARCH64: add sp, sp, #80
109
110; CHECK-NOFP-ARM64: mov sp, x29
111; CHECK-NOFP-ARM64: ldp x29, x30, [sp], #16
112}
113
114define void @test_alloca_large_frame(i64 %n) {
115; CHECK-LABEL: test_alloca_large_frame:
116
117
118; CHECK: stp     x20, x19, [sp, #-32]!
119; CHECK: stp     x29, x30, [sp, #16]
120; CHECK: add     x29, sp, #16
121; CHECK: sub     sp, sp, #1953, lsl #12
122; CHECK: sub     sp, sp, #512
123
124  %addr1 = alloca i8, i64 %n
125  %addr2 = alloca i64, i64 1000000
126
127  call void @use_addr_loc(i8* %addr1, i64* %addr2)
128
129  ret void
130
131; CHECK: sub     sp, x29, #16
132; CHECK: ldp     x29, x30, [sp, #16]
133; CHECK: ldp     x20, x19, [sp], #32
134}
135
136declare i8* @llvm.stacksave()
137declare void @llvm.stackrestore(i8*)
138
139define void @test_scoped_alloca(i64 %n) {
140; CHECK-LABEL: test_scoped_alloca:
141
142  %sp = call i8* @llvm.stacksave()
143; CHECK: mov [[SAVED_SP:x[0-9]+]], sp
144; CHECK: mov [[OLDSP:x[0-9]+]], sp
145
146  %addr = alloca i8, i64 %n
147; CHECK: and [[SPDELTA:x[0-9]+]], {{x[0-9]+}}, #0xfffffffffffffff0
148; CHECK-DAG: sub [[NEWSP:x[0-9]+]], [[OLDSP]], [[SPDELTA]]
149; CHECK: mov sp, [[NEWSP]]
150
151  call void @use_addr(i8* %addr)
152; CHECK: bl use_addr
153
154  call void @llvm.stackrestore(i8* %sp)
155; CHECK: mov sp, [[SAVED_SP]]
156
157  ret void
158}
159