1 ; RUN: llc < %s -stack-symbol-ordering=0 -mcpu=generic -mattr=+avx -mtriple=x86_64-apple-darwin10 | FileCheck %s
4 ; no VLAs or dynamic alignment
5 define i32 @t1() nounwind uwtable ssp {
7 %a = alloca i32, align 4
8 call void @t1_helper(i32* %a) nounwind
9 %0 = load i32, i32* %a, align 4
10 %add = add nsw i32 %0, 13
14 ; CHECK-NOT: andq $-{{[0-9]+}}, %rsp
15 ; CHECK: leaq [[OFFSET:[0-9]*]](%rsp), %rdi
16 ; CHECK: callq _t1_helper
17 ; CHECK: movl [[OFFSET]](%rsp), %eax
18 ; CHECK: addl $13, %eax
21 declare void @t1_helper(i32*)
24 define i32 @t2() nounwind uwtable ssp {
26 %a = alloca i32, align 4
27 %v = alloca <8 x float>, align 32
28 call void @t2_helper(i32* %a, <8 x float>* %v) nounwind
29 %0 = load i32, i32* %a, align 4
30 %add = add nsw i32 %0, 13
35 ; CHECK: movq %rsp, %rbp
36 ; CHECK: andq $-32, %rsp
37 ; CHECK: subq ${{[0-9]+}}, %rsp
39 ; CHECK: leaq {{[0-9]*}}(%rsp), %rdi
40 ; CHECK: movq %rsp, %rsi
41 ; CHECK: callq _t2_helper
43 ; CHECK: movq %rbp, %rsp
47 declare void @t2_helper(i32*, <8 x float>*)
50 define i32 @t3(i64 %sz) nounwind uwtable ssp {
52 %a = alloca i32, align 4
53 %vla = alloca i32, i64 %sz, align 16
54 call void @t3_helper(i32* %a, i32* %vla) nounwind
55 %0 = load i32, i32* %a, align 4
56 %add = add nsw i32 %0, 13
61 ; CHECK: movq %rsp, %rbp
62 ; CHECK-NOT: andq $-{{[0-9]+}}, %rsp
63 ; CHECK: subq ${{[0-9]+}}, %rsp
65 ; CHECK: movq %rbp, %rsp
69 declare void @t3_helper(i32*, i32*)
71 ; VLAs + Dynamic realignment
72 define i32 @t4(i64 %sz) nounwind uwtable ssp {
74 %a = alloca i32, align 4
75 %v = alloca <8 x float>, align 32
76 %vla = alloca i32, i64 %sz, align 16
77 call void @t4_helper(i32* %a, i32* %vla, <8 x float>* %v) nounwind
78 %0 = load i32, i32* %a, align 4
79 %add = add nsw i32 %0, 13
84 ; CHECK: movq %rsp, %rbp
86 ; CHECK: andq $-32, %rsp
87 ; CHECK: subq ${{[0-9]+}}, %rsp
88 ; CHECK: movq %rsp, %rbx
90 ; CHECK: leaq {{[0-9]*}}(%rbx), %rdi
91 ; CHECK: movq %rbx, %rdx
92 ; CHECK: callq _t4_helper
94 ; CHECK: leaq -{{[0-9]+}}(%rbp), %rsp
99 declare void @t4_helper(i32*, i32*, <8 x float>*)
101 ; Spilling an AVX register shouldn't cause dynamic realignment
102 define i32 @t5(float* nocapture %f) nounwind uwtable ssp {
104 %a = alloca i32, align 4
105 %0 = bitcast float* %f to <8 x float>*
106 %1 = load <8 x float>, <8 x float>* %0, align 32
107 call void @t5_helper1(i32* %a) nounwind
108 call void @t5_helper2(<8 x float> %1) nounwind
109 %2 = load i32, i32* %a, align 4
110 %add = add nsw i32 %2, 13
114 ; CHECK: subq ${{[0-9]+}}, %rsp
116 ; CHECK: vmovaps (%rdi), [[AVXREG:%ymm[0-9]+]]
117 ; CHECK: vmovups [[AVXREG]], (%rsp)
118 ; CHECK: leaq {{[0-9]+}}(%rsp), %rdi
119 ; CHECK: callq _t5_helper1
120 ; CHECK: vmovups (%rsp), %ymm0
121 ; CHECK: callq _t5_helper2
122 ; CHECK: movl {{[0-9]+}}(%rsp), %eax
125 declare void @t5_helper1(i32*)
127 declare void @t5_helper2(<8 x float>)
129 ; VLAs + Dynamic realignment + Spill
130 ; FIXME: RA has already reserved RBX, so we can't do dynamic realignment.
131 define i32 @t6(i64 %sz, float* nocapture %f) nounwind uwtable ssp {
134 %a = alloca i32, align 4
135 %0 = bitcast float* %f to <8 x float>*
136 %1 = load <8 x float>, <8 x float>* %0, align 32
137 %vla = alloca i32, i64 %sz, align 16
138 call void @t6_helper1(i32* %a, i32* %vla) nounwind
139 call void @t6_helper2(<8 x float> %1) nounwind
140 %2 = load i32, i32* %a, align 4
141 %add = add nsw i32 %2, 13
145 declare void @t6_helper1(i32*, i32*)
147 declare void @t6_helper2(<8 x float>)
149 ; VLAs + Dynamic realignment + byval
150 ; The byval adjust the sp after the prolog, but if we're restoring the sp from
151 ; the base pointer we use the original adjustment.
152 %struct.struct_t = type { [5 x i32] }
154 define void @t7(i32 %size, %struct.struct_t* byval(%struct.struct_t) align 8 %arg1) nounwind uwtable {
156 %x = alloca i32, align 32
157 store i32 0, i32* %x, align 32
158 %0 = zext i32 %size to i64
159 %vla = alloca i32, i64 %0, align 16
160 %1 = load i32, i32* %x, align 32
161 call void @bar(i32 %1, i32* %vla, %struct.struct_t* byval(%struct.struct_t) align 8 %arg1)
166 ; CHECK: movq %rsp, %rbp
168 ; CHECK: andq $-32, %rsp
169 ; CHECK: subq ${{[0-9]+}}, %rsp
170 ; CHECK: movq %rsp, %rbx
172 ; Stack adjustment for byval
173 ; CHECK: subq {{.*}}, %rsp
175 ; CHECK-NOT: addq {{.*}}, %rsp
176 ; CHECK: leaq -8(%rbp), %rsp
181 declare i8* @llvm.stacksave() nounwind
183 declare void @bar(i32, i32*, %struct.struct_t* byval(%struct.struct_t) align 8)
185 declare void @llvm.stackrestore(i8*) nounwind