1 ; RUN: llc < %s -march=mips -mcpu=mips2 -relocation-model=pic | FileCheck %s \
2 ; RUN: --check-prefixes=ALL,GP32
3 ; RUN: llc < %s -march=mips -mcpu=mips32 -relocation-model=pic | FileCheck %s \
4 ; RUN: --check-prefixes=ALL,GP32
5 ; RUN: llc < %s -march=mips -mcpu=mips32r6 -relocation-model=pic | FileCheck %s \
6 ; RUN: --check-prefixes=ALL,GP32
7 ; RUN: llc < %s -march=mips64 -mcpu=mips3 -relocation-model=pic | FileCheck %s \
8 ; RUN: --check-prefixes=ALL,GP64,N64
9 ; RUN: llc < %s -march=mips64 -mcpu=mips64 -relocation-model=pic | FileCheck %s \
10 ; RUN: --check-prefixes=ALL,GP64,N64
11 ; RUN: llc < %s -march=mips64 -mcpu=mips64r6 -relocation-model=pic | FileCheck %s \
12 ; RUN: --check-prefixes=ALL,GP64,N64
13 ; RUN: llc < %s -march=mips64 -mcpu=mips3 -target-abi n32 -relocation-model=pic | FileCheck %s \
14 ; RUN: --check-prefixes=ALL,GP64,N32
15 ; RUN: llc < %s -march=mips64 -mcpu=mips64 -target-abi n32 -relocation-model=pic | FileCheck %s \
16 ; RUN: --check-prefixes=ALL,GP64,N32
17 ; RUN: llc < %s -march=mips64 -mcpu=mips64r6 -target-abi n32 -relocation-model=pic | FileCheck %s \
18 ; RUN: --check-prefixes=ALL,GP64,N32
20 ; Check dynamic stack realignment in functions without variable-sized objects.
22 declare void @helper_01(i32, i32, i32, i32, i32*)
25 define void @func_01() {
27 ; GP32-LABEL: func_01:
30 ; FIXME: We are currently over-allocating stack space. This particular case
31 ; needs a frame of up to between 16 and 512-bytes but currently
32 ; allocates between 1024 and 1536 bytes
33 ; GP32: addiu $sp, $sp, -1024
34 ; GP32: sw $ra, 1020($sp)
35 ; GP32: sw $fp, 1016($sp)
38 ; GP32: addiu $[[T0:[0-9]+|ra|gp]], $zero, -512
39 ; GP32-NEXT: and $sp, $sp, $[[T0]]
42 ; GP32: addiu $[[T1:[0-9]+]], $sp, 512
43 ; GP32: sw $[[T1]], 16($sp)
47 ; GP32: lw $fp, 1016($sp)
48 ; GP32: lw $ra, 1020($sp)
49 ; GP32: addiu $sp, $sp, 1024
51 %a = alloca i32, align 512
52 call void @helper_01(i32 0, i32 0, i32 0, i32 0, i32* %a)
56 declare void @helper_02(i32, i32, i32, i32,
57 i32, i32, i32, i32, i32*)
60 define void @func_02() {
62 ; GP64-LABEL: func_02:
65 ; FIXME: We are currently over-allocating stack space. This particular case
66 ; needs a frame of up to between 16 and 512-bytes but currently
67 ; allocates between 1024 and 1536 bytes
68 ; N32: addiu $sp, $sp, -1024
69 ; N64: daddiu $sp, $sp, -1024
70 ; GP64: sd $ra, 1016($sp)
71 ; GP64: sd $fp, 1008($sp)
72 ; N32: sd $gp, 1000($sp)
75 ; N32: addiu $[[T0:[0-9]+|ra]], $zero, -512
76 ; N64: daddiu $[[T0:[0-9]+|ra]], $zero, -512
77 ; GP64-NEXT: and $sp, $sp, $[[T0]]
80 ; N32: addiu $[[T1:[0-9]+]], $sp, 512
81 ; N64: daddiu $[[T1:[0-9]+]], $sp, 512
82 ; GP64: sd $[[T1]], 0($sp)
86 ; N32: ld $gp, 1000($sp)
87 ; GP64: ld $fp, 1008($sp)
88 ; GP64: ld $ra, 1016($sp)
89 ; N32: addiu $sp, $sp, 1024
90 ; N64: daddiu $sp, $sp, 1024
92 %a = alloca i32, align 512
93 call void @helper_02(i32 0, i32 0, i32 0, i32 0,
94 i32 0, i32 0, i32 0, i32 0, i32* %a)
98 ; Verify that we use $fp for referencing incoming arguments.
100 declare void @helper_03(i32, i32, i32, i32, i32*, i32*)
103 define void @func_03(i32 %p0, i32 %p1, i32 %p2, i32 %p3, i32* %b) {
105 ; GP32-LABEL: func_03:
108 ; FIXME: We are currently over-allocating stack space.
109 ; GP32-DAG: addiu $[[T0:[0-9]+]], $sp, 512
110 ; GP32-DAG: sw $[[T0]], 16($sp)
111 ; GP32-DAG: lw $[[T1:[0-9]+]], 1040($fp)
112 ; GP32-DAG: sw $[[T1]], 20($sp)
114 %a = alloca i32, align 512
115 call void @helper_03(i32 0, i32 0, i32 0, i32 0, i32* %a, i32* %b)
119 declare void @helper_04(i32, i32, i32, i32,
120 i32, i32, i32, i32, i32*, i32*)
123 define void @func_04(i32 %p0, i32 %p1, i32 %p2, i32 %p3,
124 i32 %p4, i32 %p5, i32 %p6, i32 %p7,
127 ; GP64-LABEL: func_04:
130 ; FIXME: We are currently over-allocating stack space.
131 ; N32-DAG: addiu $[[T0:[0-9]+]], $sp, 512
132 ; N64-DAG: daddiu $[[T0:[0-9]+]], $sp, 512
133 ; GP64-DAG: sd $[[T0]], 0($sp)
134 ; GP64-DAG: ld $[[T1:[0-9]+]], 1024($fp)
135 ; GP64-DAG: sd $[[T1]], 8($sp)
137 %a = alloca i32, align 512
138 call void @helper_04(i32 0, i32 0, i32 0, i32 0,
139 i32 0, i32 0, i32 0, i32 0, i32* %a, i32* %b)
143 ; Check dynamic stack realignment in functions with variable-sized objects.
146 define void @func_05(i32 %sz) {
148 ; GP32-LABEL: func_05:
151 ; FIXME: We are currently over-allocating stack space.
152 ; GP32: addiu $sp, $sp, -1024
153 ; GP32: sw $fp, 1020($sp)
154 ; GP32: sw $23, 1016($sp)
156 ; GP32: move $fp, $sp
157 ; GP32: addiu $[[T0:[0-9]+|gp]], $zero, -512
158 ; GP32-NEXT: and $sp, $sp, $[[T0]]
159 ; GP32-NEXT: move $23, $sp
162 ; GP32: addiu $[[T1:[0-9]+]], $zero, 222
163 ; GP32: sw $[[T1]], 508($23)
166 ; GP32: move $sp, $fp
167 ; GP32: lw $23, 1016($sp)
168 ; GP32: lw $fp, 1020($sp)
169 ; GP32: addiu $sp, $sp, 1024
171 %a0 = alloca i32, i32 %sz, align 512
172 %a1 = alloca i32, align 4
174 store volatile i32 111, i32* %a0, align 512
175 store volatile i32 222, i32* %a1, align 4
181 define void @func_06(i32 %sz) {
183 ; GP64-LABEL: func_06:
186 ; FIXME: We are currently over-allocating stack space.
187 ; N32: addiu $sp, $sp, -1024
188 ; N64: daddiu $sp, $sp, -1024
189 ; GP64: sd $fp, 1016($sp)
190 ; GP64: sd $23, 1008($sp)
192 ; GP64: move $fp, $sp
193 ; GP64: addiu $[[T0:[0-9]+|gp]], $zero, -512
194 ; GP64-NEXT: and $sp, $sp, $[[T0]]
195 ; GP64-NEXT: move $23, $sp
198 ; GP64: addiu $[[T1:[0-9]+]], $zero, 222
199 ; GP64: sw $[[T1]], 508($23)
202 ; GP64: move $sp, $fp
203 ; GP64: ld $23, 1008($sp)
204 ; GP64: ld $fp, 1016($sp)
205 ; N32: addiu $sp, $sp, 1024
206 ; N64: daddiu $sp, $sp, 1024
208 %a0 = alloca i32, i32 %sz, align 512
209 %a1 = alloca i32, align 4
211 store volatile i32 111, i32* %a0, align 512
212 store volatile i32 222, i32* %a1, align 4
217 ; Verify that we use $fp for referencing incoming arguments and $sp for
218 ; building outbound arguments for nested function calls.
221 define void @func_07(i32 %p0, i32 %p1, i32 %p2, i32 %p3, i32 %sz) {
223 ; GP32-LABEL: func_07:
226 ; FIXME: We are currently over-allocating stack space.
227 ; GP32-DAG: lw $[[T0:[0-9]+]], 1040($fp)
229 ; GP32-DAG: addiu $[[T1:[0-9]+]], $zero, 222
230 ; GP32-DAG: sw $[[T1]], 508($23)
232 ; GP32-DAG: sw $[[T2:[0-9]+]], 16($sp)
234 %a0 = alloca i32, i32 %sz, align 512
235 %a1 = alloca i32, align 4
237 store volatile i32 111, i32* %a0, align 512
238 store volatile i32 222, i32* %a1, align 4
240 call void @helper_01(i32 0, i32 0, i32 0, i32 0, i32* %a1)
246 define void @func_08(i32 %p0, i32 %p1, i32 %p2, i32 %p3,
247 i32 %p4, i32 %p5, i32 %p6, i32 %p7,
250 ; GP64-LABEL: func_08:
253 ; FIXME: We are currently over-allocating stack space.
254 ; N32-DAG: lw $[[T0:[0-9]+]], 1028($fp)
255 ; N64-DAG: lwu $[[T0:[0-9]+]], 1028($fp)
257 ; GP64-DAG: addiu $[[T1:[0-9]+]], $zero, 222
258 ; GP64-DAG: sw $[[T1]], 508($23)
260 ; GP64-DAG: sd $[[T2:[0-9]+]], 0($sp)
262 %a0 = alloca i32, i32 %sz, align 512
263 %a1 = alloca i32, align 4
265 store volatile i32 111, i32* %a0, align 512
266 store volatile i32 222, i32* %a1, align 4
268 call void @helper_02(i32 0, i32 0, i32 0, i32 0,
269 i32 0, i32 0, i32 0, i32 0, i32* %a1)
273 ; Check that we do not perform dynamic stack realignment in the presence of
274 ; the "no-realign-stack" function attribute.
275 define void @func_09() "no-realign-stack" {
277 ; ALL-LABEL: func_09:
279 ; ALL-NOT: and $sp, $sp, $[[T0:[0-9]+|ra|gp]]
281 %a = alloca i32, align 512
282 call void @helper_01(i32 0, i32 0, i32 0, i32 0, i32* %a)
286 define void @func_10(i32 %sz) "no-realign-stack" {
288 ; ALL-LABEL: func_10:
290 ; ALL-NOT: and $sp, $sp, $[[T0:[0-9]+|ra|gp]]
292 %a0 = alloca i32, i32 %sz, align 512
293 %a1 = alloca i32, align 4
295 store volatile i32 111, i32* %a0, align 512
296 store volatile i32 222, i32* %a1, align 4