1 ; Disable shrink-wrapping on the first test otherwise we wouldn't
2 ; exerce the path for PR18136.
3 ; RUN: llc -mtriple=thumbv7-apple-none-macho < %s -enable-shrink-wrap=false -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK-FNSTART,CHECK
4 ; RUN: llc -mtriple=thumbv6m-apple-none-macho -frame-pointer=all < %s -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK-FNSTART,CHECK-T1
5 ; RUN: llc -mtriple=thumbv6m-apple-none-macho < %s -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK-FNSTART,CHECK-T1-NOFP
6 ; RUN: llc -mtriple=thumbv7-apple-darwin-ios -frame-pointer=all < %s -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK-FNSTART,CHECK-IOS
7 ; RUN: llc -mtriple=thumbv7--linux-gnueabi -frame-pointer=all < %s -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK-FNSTART,CHECK-LINUX
11 %bigVec = type [2 x double]
13 @var = global %bigVec zeroinitializer
15 define void @check_simple() minsize {
16 ; CHECK-FNSTART-LABEL: check_simple:
17 ; CHECK: push {r3, r4, r5, r6, r7, lr}
18 ; CHECK-NOT: sub sp, sp,
20 ; CHECK-NOT: add sp, sp,
21 ; CHECK: pop {r0, r1, r2, r3, r7, pc}
23 ; CHECK-T1: push {r3, r4, r5, r6, r7, lr}
24 ; CHECK-T1: add r7, sp, #16
25 ; CHECK-T1-NOT: sub sp, sp,
27 ; CHECK-T1-NOT: add sp, sp,
28 ; CHECK-T1: pop {r0, r1, r2, r3, r7, pc}
30 ; iOS always has a frame pointer and messing with the push affects
31 ; how it's set in the prologue. Make sure we get that right.
32 ; CHECK-IOS: push {r3, r4, r5, r6, r7, lr}
34 ; CHECK-IOS: add r7, sp, #16
38 ; CHEC: pop {r3, r4, r5, r6, r7, pc}
40 %var = alloca i8, i32 16
41 call void @bar(i8* %var)
45 define void @check_simple_too_big() minsize {
46 ; CHECK-FNSTART-LABEL: check_simple_too_big:
47 ; CHECK: push {r7, lr}
52 %var = alloca i8, i32 64
53 call void @bar(i8* %var)
57 define void @check_vfp_fold() minsize {
58 ; CHECK-FNSTART-LABEL: check_vfp_fold:
59 ; CHECK: push {r[[GLOBREG:[0-9]+]], lr}
60 ; CHECK: vpush {d6, d7, d8, d9}
64 ; CHECK: vpop {d6, d7, d8, d9}
65 ; CHECK: pop {r[[GLOBREG]], pc}
67 ; iOS uses aligned NEON stores here, which is convenient since we
68 ; want to make sure that works too.
69 ; CHECK-IOS: push {r4, r7, lr}
70 ; CHECK-IOS: sub.w r4, sp, #16
71 ; CHECK-IOS: bfc r4, #0, #4
72 ; CHECK-IOS: mov sp, r4
73 ; CHECK-IOS: vst1.64 {d8, d9}, [r4:128]
74 ; CHECK-IOS: sub sp, #16
76 ; CHECK-IOS: add r4, sp, #16
77 ; CHECK-IOS: vld1.64 {d8, d9}, [r4:128]
78 ; CHECK-IOS: mov sp, r4
79 ; CHECK-IOS: pop {r4, r7, pc}
81 %var = alloca i8, i32 16
83 call void asm "", "r,~{d8},~{d9}"(i8* %var)
84 call void @bar(i8* %var)
89 ; This function should use just enough space that the "add sp, sp, ..." could be
90 ; folded in except that doing so would clobber the value being returned.
91 define i64 @check_no_return_clobber() minsize {
92 ; CHECK-FNSTART-LABEL: check_no_return_clobber:
93 ; CHECK: push {r1, r2, r3, r4, r5, r6, r7, lr}
99 %var = alloca i8, i32 20
100 call void @bar(i8* %var)
104 define arm_aapcs_vfpcc double @check_vfp_no_return_clobber() minsize {
105 ; CHECK-FNSTART-LABEL: check_vfp_no_return_clobber:
106 ; CHECK: push {r[[GLOBREG:[0-9]+]], lr}
107 ; CHECK: vpush {d0, d1, d2, d3, d4, d5, d6, d7, d8, d9}
111 ; CHECK: vpop {d8, d9}
112 ; CHECK: pop {r[[GLOBREG]], pc}
114 %var = alloca i8, i32 64
116 %tmp = load %bigVec, %bigVec* @var
117 call void @bar(i8* %var)
118 store %bigVec %tmp, %bigVec* @var
123 @dbl = global double 0.0
125 ; PR18136: there was a bug determining where the first eligible pop in a
126 ; basic-block was when the entire block was epilogue code.
127 define void @test_fold_point(i1 %tst) minsize {
128 ; CHECK-FNSTART-LABEL: test_fold_point:
130 ; Important to check for beginning of basic block, because if it gets
131 ; if-converted the test is probably no longer checking what it should.
133 ; CHECK-NEXT: vpop {d7, d8}
134 ; CHECK-NEXT: pop {r4, pc}
136 ; With a guaranteed frame-pointer, we want to make sure that its offset in the
137 ; push block is correct, even if a few registers have been tacked onto a later
139 ; CHECK-IOS: push {r4, r7, lr}
140 ; CHECK-IOS-NEXT: add r7, sp, #4
141 ; CHECK-IOS-NEXT: vpush {d7, d8}
143 ; We want some memory so there's a stack adjustment to fold...
144 %var = alloca i8, i32 8
146 ; We want a long-lived floating register so that a callee-saved dN is used and
147 ; there's both a vpop and a pop.
148 %live_val = load double, double* @dbl
149 br i1 %tst, label %true, label %end
151 call void @bar(i8* %var)
152 store double %live_val, double* @dbl
155 ; We want the epilogue to be the only thing in a basic block so that we hit
156 ; the correct edge-case (first inst in block is correct one to adjust).
160 define void @test_varsize(...) minsize {
161 ; CHECK-FNSTART-LABEL: test_varsize:
162 ; CHECK-T1: sub sp, #16
163 ; CHECK-T1: push {r5, r6, r7, lr}
165 ; CHECK-T1: pop {r2, r3, r7}
166 ; CHECK-T1: pop {[[POP_REG:r[0-3]]]}
167 ; CHECK-T1: add sp, #16
168 ; CHECK-T1: bx [[POP_REG]]
171 ; CHECK: push {r5, r6, r7, lr}
173 ; CHECK: pop.w {r2, r3, r7, lr}
177 %var = alloca i8, i32 8
178 call void @llvm.va_start(i8* %var)
179 call void @bar(i8* %var)
183 %"MyClass" = type { i8*, i32, i32, float, float, float, [2 x i8], i32, i32* }
189 declare %"MyClass"* @bar2(%"MyClass"* returned, i16*, i32, float, float, i32, i32, i1 zeroext, i1 zeroext, i32)
191 define fastcc float @check_vfp_no_return_clobber2(i16* %r, i16* %chars, i32 %length, i1 zeroext %flag) minsize {
193 ; CHECK-FNSTART-LABEL: check_vfp_no_return_clobber2
194 ; CHECK-LINUX: vpush {d0, d1, d2, d3, d4, d5, d6, d7, d8}
197 ; CHECK-LINUX: add sp
198 ; CHECK-LINUX: vpop {d8}
199 %run = alloca %"MyClass", align 4
200 %call = call %"MyClass"* @bar2(%"MyClass"* %run, i16* %chars, i32 %length, float 0.000000e+00, float 0.000000e+00, i32 1, i32 1, i1 zeroext false, i1 zeroext true, i32 3)
201 %call1 = call float @foo()
202 %cmp = icmp eq %"MyClass"* %run, null
203 br i1 %cmp, label %exit, label %if.then
205 if.then: ; preds = %entry
209 exit: ; preds = %if.then, %entry
213 declare void @use_arr(i32*)
214 define void @test_fold_reuse() minsize {
215 ; CHECK-FNSTART-LABEL: test_fold_reuse:
216 ; CHECK: push.w {r4, r7, r8, lr}
220 ; CHECK: pop.w {r4, r7, r8, pc}
221 %arr = alloca i8, i32 24
222 call void asm sideeffect "", "~{r8},~{r4}"()
223 call void @bar(i8* %arr)
227 ; It doesn't matter what registers this pushes and pops; just make sure
228 ; it doesn't try to push/pop an illegal register on Thumb1.
229 define void @test_long_fn() minsize nounwind optsize {
230 ; CHECK-FNSTART-LABEL: test_long_fn:
231 ; CHECK-T1-NOFP: push {r7, lr}
232 ; CHECK-T1-NOFP: pop {r3, pc}
234 %z = alloca i32, align 4
235 call void asm sideeffect ".space 3000", "r"(i32* nonnull %z)
239 declare void @llvm.va_start(i8*) nounwind