1 ; RUN: llc -march=mipsel -pre-RA-sched=source < %s | FileCheck %s
3 ; All test functions do the same thing - they return the first variable
6 ; All CHECK's do the same thing - they check whether variable arguments from
7 ; registers are placed on correct stack locations, and whether the first
8 ; variable argument is returned from the correct stack location.
11 declare void @llvm.va_start(ptr) nounwind
12 declare void @llvm.va_end(ptr) nounwind
15 define i32 @va1(i32 %a, ...) nounwind {
17 %a.addr = alloca i32, align 4
18 %ap = alloca ptr, align 4
19 %b = alloca i32, align 4
20 store i32 %a, ptr %a.addr, align 4
21 call void @llvm.va_start(ptr %ap)
22 %0 = va_arg ptr %ap, i32
23 store i32 %0, ptr %b, align 4
24 call void @llvm.va_end(ptr %ap)
25 %tmp = load i32, ptr %b, align 4
29 ; CHECK: addiu $sp, $sp, -16
30 ; CHECK: sw $7, 28($sp)
31 ; CHECK: sw $6, 24($sp)
32 ; CHECK: sw $5, 20($sp)
36 ; check whether the variable double argument will be accessed from the 8-byte
37 ; aligned location (i.e. whether the address is computed by adding 7 and
38 ; clearing lower 3 bits)
39 define double @va2(i32 %a, ...) nounwind {
41 %a.addr = alloca i32, align 4
42 %ap = alloca ptr, align 4
43 %b = alloca double, align 8
44 store i32 %a, ptr %a.addr, align 4
45 call void @llvm.va_start(ptr %ap)
46 %0 = va_arg ptr %ap, double
47 store double %0, ptr %b, align 8
48 call void @llvm.va_end(ptr %ap)
49 %tmp = load double, ptr %b, align 8
53 ; CHECK: addiu $sp, $sp, -16
54 ; CHECK: sw $7, 28($sp)
55 ; CHECK: sw $6, 24($sp)
56 ; CHECK: sw $5, 20($sp)
57 ; CHECK: addiu $[[R0:[0-9]+]], $sp, 20
58 ; CHECK: addiu $[[R1:[0-9]+]], $[[R0]], 7
59 ; CHECK: addiu $[[R2:[0-9]+]], $zero, -8
60 ; CHECK: and $[[R3:[0-9]+]], $[[R1]], $[[R2]]
61 ; CHECK: ldc1 $f0, 0($[[R3]])
65 define i32 @va3(double %a, ...) nounwind {
67 %a.addr = alloca double, align 8
68 %ap = alloca ptr, align 4
69 %b = alloca i32, align 4
70 store double %a, ptr %a.addr, align 8
71 call void @llvm.va_start(ptr %ap)
72 %0 = va_arg ptr %ap, i32
73 store i32 %0, ptr %b, align 4
74 call void @llvm.va_end(ptr %ap)
75 %tmp = load i32, ptr %b, align 4
79 ; CHECK: addiu $sp, $sp, -16
80 ; CHECK: sw $7, 28($sp)
81 ; CHECK: sw $6, 24($sp)
86 define double @va4(double %a, ...) nounwind {
88 %a.addr = alloca double, align 8
89 %ap = alloca ptr, align 4
90 %b = alloca double, align 8
91 store double %a, ptr %a.addr, align 8
92 call void @llvm.va_start(ptr %ap)
93 %0 = va_arg ptr %ap, double
94 store double %0, ptr %b, align 8
95 call void @llvm.va_end(ptr %ap)
96 %tmp = load double, ptr %b, align 8
100 ; CHECK: addiu $sp, $sp, -24
101 ; CHECK: sw $7, 36($sp)
102 ; CHECK: sw $6, 32($sp)
103 ; CHECK: addiu ${{[0-9]+}}, $sp, 32
104 ; CHECK: ldc1 $f0, 32($sp)
108 define i32 @va5(i32 %a, i32 %b, i32 %c, ...) nounwind {
110 %a.addr = alloca i32, align 4
111 %b.addr = alloca i32, align 4
112 %c.addr = alloca i32, align 4
113 %ap = alloca ptr, align 4
114 %d = alloca i32, align 4
115 store i32 %a, ptr %a.addr, align 4
116 store i32 %b, ptr %b.addr, align 4
117 store i32 %c, ptr %c.addr, align 4
118 call void @llvm.va_start(ptr %ap)
119 %0 = va_arg ptr %ap, i32
120 store i32 %0, ptr %d, align 4
121 call void @llvm.va_end(ptr %ap)
122 %tmp = load i32, ptr %d, align 4
126 ; CHECK: addiu $sp, $sp, -24
127 ; CHECK: sw $7, 36($sp)
132 define double @va6(i32 %a, i32 %b, i32 %c, ...) nounwind {
134 %a.addr = alloca i32, align 4
135 %b.addr = alloca i32, align 4
136 %c.addr = alloca i32, align 4
137 %ap = alloca ptr, align 4
138 %d = alloca double, align 8
139 store i32 %a, ptr %a.addr, align 4
140 store i32 %b, ptr %b.addr, align 4
141 store i32 %c, ptr %c.addr, align 4
142 call void @llvm.va_start(ptr %ap)
143 %0 = va_arg ptr %ap, double
144 store double %0, ptr %d, align 8
145 call void @llvm.va_end(ptr %ap)
146 %tmp = load double, ptr %d, align 8
150 ; CHECK: addiu $sp, $sp, -24
151 ; CHECK: sw $7, 36($sp)
152 ; CHECK: addiu $[[R0:[0-9]+]], $sp, 36
153 ; CHECK: addiu $[[R1:[0-9]+]], $[[R0]], 7
154 ; CHECK: addiu $[[R2:[0-9]+]], $zero, -8
155 ; CHECK: and $[[R3:[0-9]+]], $[[R1]], $[[R2]]
156 ; CHECK: ldc1 $f0, 0($[[R3]])
160 define i32 @va7(i32 %a, double %b, ...) nounwind {
162 %a.addr = alloca i32, align 4
163 %b.addr = alloca double, align 8
164 %ap = alloca ptr, align 4
165 %c = alloca i32, align 4
166 store i32 %a, ptr %a.addr, align 4
167 store double %b, ptr %b.addr, align 8
168 call void @llvm.va_start(ptr %ap)
169 %0 = va_arg ptr %ap, i32
170 store i32 %0, ptr %c, align 4
171 call void @llvm.va_end(ptr %ap)
172 %tmp = load i32, ptr %c, align 4
176 ; CHECK: addiu $sp, $sp, -24
177 ; CHECK: lw $2, 40($sp)
181 define double @va8(i32 %a, double %b, ...) nounwind {
183 %a.addr = alloca i32, align 4
184 %b.addr = alloca double, align 8
185 %ap = alloca ptr, align 4
186 %c = alloca double, align 8
187 store i32 %a, ptr %a.addr, align 4
188 store double %b, ptr %b.addr, align 8
189 call void @llvm.va_start(ptr %ap)
190 %0 = va_arg ptr %ap, double
191 store double %0, ptr %c, align 8
192 call void @llvm.va_end(ptr %ap)
193 %tmp = load double, ptr %c, align 8
197 ; CHECK: addiu $sp, $sp, -32
198 ; CHECK: addiu ${{[0-9]+}}, $sp, 48
199 ; CHECK: ldc1 $f0, 48($sp)
203 define i32 @va9(double %a, double %b, i32 %c, ...) nounwind {
205 %a.addr = alloca double, align 8
206 %b.addr = alloca double, align 8
207 %c.addr = alloca i32, align 4
208 %ap = alloca ptr, align 4
209 %d = alloca i32, align 4
210 store double %a, ptr %a.addr, align 8
211 store double %b, ptr %b.addr, align 8
212 store i32 %c, ptr %c.addr, align 4
213 call void @llvm.va_start(ptr %ap)
214 %0 = va_arg ptr %ap, i32
215 store i32 %0, ptr %d, align 4
216 call void @llvm.va_end(ptr %ap)
217 %tmp = load i32, ptr %d, align 4
221 ; CHECK: addiu $sp, $sp, -24
222 ; CHECK: lw $2, 44($sp)
226 define double @va10(double %a, double %b, i32 %c, ...) nounwind {
228 %a.addr = alloca double, align 8
229 %b.addr = alloca double, align 8
230 %c.addr = alloca i32, align 4
231 %ap = alloca ptr, align 4
232 %d = alloca double, align 8
233 store double %a, ptr %a.addr, align 8
234 store double %b, ptr %b.addr, align 8
235 store i32 %c, ptr %c.addr, align 4
236 call void @llvm.va_start(ptr %ap)
237 %0 = va_arg ptr %ap, double
238 store double %0, ptr %d, align 8
239 call void @llvm.va_end(ptr %ap)
240 %tmp = load double, ptr %d, align 8
244 ; CHECK: addiu $sp, $sp, -32
245 ; CHECK: addiu $[[R0:[0-9]+]], $sp, 52
246 ; CHECK: addiu $[[R1:[0-9]+]], $[[R0]], 7
247 ; CHECK: addiu $[[R2:[0-9]+]], $zero, -8
248 ; CHECK: and $[[R3:[0-9]+]], $[[R1]], $[[R2]]
249 ; CHECK: ldc1 $f0, 0($[[R3]])