1 ; RUN: llc -mtriple=aarch64-linux-gnu -disable-post-ra -verify-machineinstrs -o - %s | FileCheck %s
2 ; RUN: llc -mtriple=arm64-apple-ios -disable-post-ra -verify-machineinstrs -o - %s | FileCheck %s --check-prefix=CHECK-MACHO
3 ; RUN: llc -mtriple=aarch64-none-linux-gnu -disable-post-ra -mattr=-fp-armv8 -verify-machineinstrs < %s | FileCheck --check-prefix=CHECK-NOFP-ARM64 %s
5 declare void @use_addr(i8*)
7 define void @test_simple_alloca(i64 %n) {
8 ; CHECK-LABEL: test_simple_alloca:
10 %buf = alloca i8, i64 %n
11 ; Make sure we align the stack change to 16 bytes:
12 ; CHECK: {{mov|add}} x29
13 ; CHECK: mov [[TMP:x[0-9]+]], sp
14 ; CHECK: add [[SPDELTA_TMP:x[0-9]+]], x0, #15
15 ; CHECK: and [[SPDELTA:x[0-9]+]], [[SPDELTA_TMP]], #0xfffffffffffffff0
17 ; Make sure we change SP. It would be surprising if anything but x0 were used
18 ; for the final sp, but it could be if it was then moved into x0.
19 ; CHECK: sub [[NEWSP:x[0-9]+]], [[TMP]], [[SPDELTA]]
20 ; CHECK: mov sp, [[NEWSP]]
22 call void @use_addr(i8* %buf)
26 ; Make sure epilogue restores sp from fp
27 ; CHECK: {{sub|mov}} sp, x29
31 declare void @use_addr_loc(i8*, i64*)
33 define i64 @test_alloca_with_local(i64 %n) {
34 ; CHECK-LABEL: test_alloca_with_local:
35 ; CHECK-DAG: sub sp, sp, [[LOCAL_STACK:#[0-9]+]]
36 ; CHECK-DAG: {{mov|add}} x29, sp
39 %buf = alloca i8, i64 %n
40 ; Make sure we align the stack change to 16 bytes:
41 ; CHECK: mov [[TMP:x[0-9]+]], sp
42 ; CHECK: add [[SPDELTA_TMP:x[0-9]+]], x0, #15
43 ; CHECK: and [[SPDELTA:x[0-9]+]], [[SPDELTA_TMP]], #0xfffffffffffffff0
45 ; Make sure we change SP. It would be surprising if anything but x0 were used
46 ; for the final sp, but it could be if it was then moved into x0.
47 ; CHECK: sub [[NEWSP:x[0-9]+]], [[TMP]], [[SPDELTA]]
48 ; CHECK: mov sp, [[NEWSP]]
50 ; CHECK: sub {{x[0-9]+}}, x29, #[[LOC_FROM_FP:[0-9]+]]
52 call void @use_addr_loc(i8* %buf, i64* %loc)
55 %val = load i64, i64* %loc
57 ; CHECK: ldur x0, [x29, #-[[LOC_FROM_FP]]]
60 ; Make sure epilogue restores sp from fp
61 ; CHECK: {{sub|mov}} sp, x29
65 define void @test_variadic_alloca(i64 %n, ...) {
66 ; CHECK-LABEL: test_variadic_alloca:
71 ; CHECK-NOFP-AARCH64: sub sp, sp, #80
72 ; CHECK-NOFP-AARCH64: stp x29, x30, [sp, #64]
73 ; CHECK-NOFP-AARCH64: add x29, sp, #64
74 ; CHECK-NOFP-AARCH64: sub [[TMP:x[0-9]+]], x29, #64
75 ; CHECK-NOFP-AARCH64: add x8, [[TMP]], #0
78 ; CHECK: stp x29, x30, [sp, #-16]!
80 ; CHECK: sub sp, sp, #192
81 ; CHECK-DAG: stp q6, q7, [x29, #-96]
83 ; CHECK-DAG: stp q0, q1, [x29, #-192]
85 ; CHECK-DAG: stp x5, x6, [x29, #-24]
87 ; CHECK-DAG: stp x1, x2, [x29, #-56]
89 ; CHECK-NOFP-ARM64: stp x29, x30, [sp, #-16]!
90 ; CHECK-NOFP-ARM64: mov x29, sp
91 ; CHECK-NOFP-ARM64: sub sp, sp, #64
92 ; CHECK-NOFP-ARM64-DAG: stp x5, x6, [x29, #-24]
94 ; CHECK-NOFP-ARM64-DAG: stp x3, x4, [x29, #-40]
96 ; CHECK-NOFP-ARM64-DAG: stp x1, x2, [x29, #-56]
98 ; CHECK-NOFP-ARM64: mov x8, sp
100 %addr = alloca i8, i64 %n
102 call void @use_addr(i8* %addr)
107 ; CHECK-NOFP-AARCH64: sub sp, x29, #64
108 ; CHECK-NOFP-AARCH64: ldp x29, x30, [sp, #64]
109 ; CHECK-NOFP-AARCH64: add sp, sp, #80
111 ; CHECK-NOFP-ARM64: mov sp, x29
112 ; CHECK-NOFP-ARM64: ldp x29, x30, [sp], #16
115 define void @test_alloca_large_frame(i64 %n) {
116 ; CHECK-LABEL: test_alloca_large_frame:
117 ; CHECK-MACHO-LABEL: test_alloca_large_frame:
120 ; CHECK: stp x28, x19, [sp, #-32]!
121 ; CHECK: stp x29, x30, [sp, #16]
122 ; CHECK: add x29, sp, #16
123 ; CHECK: sub sp, sp, #1953, lsl #12
124 ; CHECK: sub sp, sp, #512
126 ; CHECK-MACHO: stp x20, x19, [sp, #-32]!
127 ; CHECK-MACHO: stp x29, x30, [sp, #16]
128 ; CHECK-MACHO: add x29, sp, #16
129 ; CHECK-MACHO: sub sp, sp, #1953, lsl #12
130 ; CHECK-MACHO: sub sp, sp, #512
132 %addr1 = alloca i8, i64 %n
133 %addr2 = alloca i64, i64 1000000
135 call void @use_addr_loc(i8* %addr1, i64* %addr2)
139 ; CHECK: sub sp, x29, #16
140 ; CHECK: ldp x29, x30, [sp, #16]
141 ; CHECK: ldp x28, x19, [sp], #32
143 ; CHECK-MACHO: sub sp, x29, #16
144 ; CHECK-MACHO: ldp x29, x30, [sp, #16]
145 ; CHECK-MACHO: ldp x20, x19, [sp], #32
148 declare i8* @llvm.stacksave()
149 declare void @llvm.stackrestore(i8*)
151 define void @test_scoped_alloca(i64 %n) {
152 ; CHECK-LABEL: test_scoped_alloca:
154 %sp = call i8* @llvm.stacksave()
155 ; CHECK: mov [[SAVED_SP:x[0-9]+]], sp
156 ; CHECK: mov [[OLDSP:x[0-9]+]], sp
158 %addr = alloca i8, i64 %n
159 ; CHECK: and [[SPDELTA:x[0-9]+]], {{x[0-9]+}}, #0xfffffffffffffff0
160 ; CHECK-DAG: sub [[NEWSP:x[0-9]+]], [[OLDSP]], [[SPDELTA]]
161 ; CHECK: mov sp, [[NEWSP]]
163 call void @use_addr(i8* %addr)
166 call void @llvm.stackrestore(i8* %sp)
167 ; CHECK: mov sp, [[SAVED_SP]]