1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mattr=avr6,sram -mtriple=avr < %s | FileCheck %s --check-prefix=AVR
3 ; RUN: llc -mcpu=attiny10 -mtriple=avr < %s | FileCheck %s --check-prefix=TINY
5 ;TODO: test returning byval structs
6 ; TODO: test naked functions
8 define void @return_void() {
9 ; AVR-LABEL: return_void:
13 ; TINY-LABEL: return_void:
19 define i8 @return8_imm() {
20 ; AVR-LABEL: return8_imm:
22 ; AVR-NEXT: ldi r24, 5
25 ; TINY-LABEL: return8_imm:
27 ; TINY-NEXT: ldi r24, 5
32 define i8 @return8_arg(i8 %x) {
33 ; AVR-LABEL: return8_arg:
37 ; TINY-LABEL: return8_arg:
43 define i8 @return8_arg2(i8 %x, i8 %y, i8 %z) {
44 ; AVR-LABEL: return8_arg2:
46 ; AVR-NEXT: mov r24, r20
49 ; TINY-LABEL: return8_arg2:
51 ; TINY-NEXT: mov r24, r20
56 define i16 @return16_imm() {
57 ; AVR-LABEL: return16_imm:
59 ; AVR-NEXT: ldi r24, 57
60 ; AVR-NEXT: ldi r25, 48
63 ; TINY-LABEL: return16_imm:
65 ; TINY-NEXT: ldi r24, 57
66 ; TINY-NEXT: ldi r25, 48
71 define i16 @return16_arg(i16 %x) {
72 ; AVR-LABEL: return16_arg:
76 ; TINY-LABEL: return16_arg:
82 define i16 @return16_arg2(i16 %x, i16 %y, i16 %z) {
83 ; AVR-LABEL: return16_arg2:
85 ; AVR-NEXT: movw r24, r20
88 ; TINY-LABEL: return16_arg2:
90 ; TINY-NEXT: mov r24, r20
91 ; TINY-NEXT: mov r25, r21
96 define i32 @return32_imm() {
97 ; AVR-LABEL: return32_imm:
99 ; AVR-NEXT: ldi r22, 21
100 ; AVR-NEXT: ldi r23, 205
101 ; AVR-NEXT: ldi r24, 91
102 ; AVR-NEXT: ldi r25, 7
105 ; TINY-LABEL: return32_imm:
107 ; TINY-NEXT: ldi r22, 21
108 ; TINY-NEXT: ldi r23, 205
109 ; TINY-NEXT: ldi r24, 91
110 ; TINY-NEXT: ldi r25, 7
115 define i32 @return32_arg(i32 %x) {
116 ; AVR-LABEL: return32_arg:
120 ; TINY-LABEL: return32_arg:
126 define i32 @return32_arg2(i32 %x, i32 %y, i32 %z) {
127 ; AVR-LABEL: return32_arg2:
129 ; AVR-NEXT: movw r22, r14
130 ; AVR-NEXT: movw r24, r16
133 ; TINY-LABEL: return32_arg2:
135 ; TINY-NEXT: push r28
136 ; TINY-NEXT: push r29
137 ; TINY-NEXT: in r28, 61
138 ; TINY-NEXT: in r29, 62
139 ; TINY-NEXT: in r16, 63
140 ; TINY-NEXT: subi r28, 247
141 ; TINY-NEXT: sbci r29, 255
142 ; TINY-NEXT: ld r22, Y+
143 ; TINY-NEXT: ld r23, Y+
144 ; TINY-NEXT: subi r28, 2
145 ; TINY-NEXT: sbci r29, 0
146 ; TINY-NEXT: subi r28, 9
147 ; TINY-NEXT: sbci r29, 0
148 ; TINY-NEXT: out 63, r16
149 ; TINY-NEXT: in r16, 63
150 ; TINY-NEXT: subi r28, 245
151 ; TINY-NEXT: sbci r29, 255
152 ; TINY-NEXT: ld r24, Y+
153 ; TINY-NEXT: ld r25, Y+
154 ; TINY-NEXT: subi r28, 2
155 ; TINY-NEXT: sbci r29, 0
156 ; TINY-NEXT: subi r28, 11
157 ; TINY-NEXT: sbci r29, 0
158 ; TINY-NEXT: out 63, r16
165 define i64 @return64_imm() {
166 ; AVR-LABEL: return64_imm:
168 ; AVR-NEXT: ldi r18, 204
169 ; AVR-NEXT: ldi r19, 204
170 ; AVR-NEXT: ldi r20, 104
171 ; AVR-NEXT: ldi r21, 37
172 ; AVR-NEXT: ldi r22, 25
173 ; AVR-NEXT: ldi r23, 22
174 ; AVR-NEXT: ldi r24, 236
175 ; AVR-NEXT: ldi r25, 190
178 ; TINY-LABEL: return64_imm:
180 ; TINY-NEXT: ldi r20, 236
181 ; TINY-NEXT: ldi r21, 190
182 ; TINY-NEXT: mov r30, r24
183 ; TINY-NEXT: mov r31, r25
184 ; TINY-NEXT: subi r30, 250
185 ; TINY-NEXT: sbci r31, 255
186 ; TINY-NEXT: st Z+, r20
187 ; TINY-NEXT: st Z+, r21
188 ; TINY-NEXT: subi r30, 8
189 ; TINY-NEXT: sbci r31, 0
190 ; TINY-NEXT: ldi r24, 25
191 ; TINY-NEXT: ldi r25, 22
192 ; TINY-NEXT: subi r30, 252
193 ; TINY-NEXT: sbci r31, 255
194 ; TINY-NEXT: st Z+, r24
195 ; TINY-NEXT: st Z+, r25
196 ; TINY-NEXT: subi r30, 6
197 ; TINY-NEXT: sbci r31, 0
198 ; TINY-NEXT: ldi r24, 104
199 ; TINY-NEXT: ldi r25, 37
200 ; TINY-NEXT: subi r30, 254
201 ; TINY-NEXT: sbci r31, 255
202 ; TINY-NEXT: st Z+, r24
203 ; TINY-NEXT: st Z+, r25
204 ; TINY-NEXT: subi r30, 4
205 ; TINY-NEXT: sbci r31, 0
206 ; TINY-NEXT: ldi r24, 204
207 ; TINY-NEXT: ldi r25, 204
208 ; TINY-NEXT: st Z+, r24
209 ; TINY-NEXT: st Z+, r25
211 ret i64 13757395258967641292
214 define i64 @return64_arg(i64 %x) {
215 ; AVR-LABEL: return64_arg:
219 ; TINY-LABEL: return64_arg:
221 ; TINY-NEXT: push r28
222 ; TINY-NEXT: push r29
223 ; TINY-NEXT: in r28, 61
224 ; TINY-NEXT: in r29, 62
225 ; TINY-NEXT: in r16, 63
226 ; TINY-NEXT: subi r28, 245
227 ; TINY-NEXT: sbci r29, 255
228 ; TINY-NEXT: ld r20, Y+
229 ; TINY-NEXT: ld r21, Y+
230 ; TINY-NEXT: subi r28, 2
231 ; TINY-NEXT: sbci r29, 0
232 ; TINY-NEXT: subi r28, 11
233 ; TINY-NEXT: sbci r29, 0
234 ; TINY-NEXT: out 63, r16
235 ; TINY-NEXT: mov r30, r24
236 ; TINY-NEXT: mov r31, r25
237 ; TINY-NEXT: subi r30, 250
238 ; TINY-NEXT: sbci r31, 255
239 ; TINY-NEXT: st Z+, r20
240 ; TINY-NEXT: st Z+, r21
241 ; TINY-NEXT: subi r30, 8
242 ; TINY-NEXT: sbci r31, 0
243 ; TINY-NEXT: in r16, 63
244 ; TINY-NEXT: subi r28, 247
245 ; TINY-NEXT: sbci r29, 255
246 ; TINY-NEXT: ld r24, Y+
247 ; TINY-NEXT: ld r25, Y+
248 ; TINY-NEXT: subi r28, 2
249 ; TINY-NEXT: sbci r29, 0
250 ; TINY-NEXT: subi r28, 9
251 ; TINY-NEXT: sbci r29, 0
252 ; TINY-NEXT: out 63, r16
253 ; TINY-NEXT: subi r30, 252
254 ; TINY-NEXT: sbci r31, 255
255 ; TINY-NEXT: st Z+, r24
256 ; TINY-NEXT: st Z+, r25
257 ; TINY-NEXT: subi r30, 6
258 ; TINY-NEXT: sbci r31, 0
259 ; TINY-NEXT: in r16, 63
260 ; TINY-NEXT: subi r28, 249
261 ; TINY-NEXT: sbci r29, 255
262 ; TINY-NEXT: ld r24, Y+
263 ; TINY-NEXT: ld r25, Y+
264 ; TINY-NEXT: subi r28, 2
265 ; TINY-NEXT: sbci r29, 0
266 ; TINY-NEXT: subi r28, 7
267 ; TINY-NEXT: sbci r29, 0
268 ; TINY-NEXT: out 63, r16
269 ; TINY-NEXT: subi r30, 254
270 ; TINY-NEXT: sbci r31, 255
271 ; TINY-NEXT: st Z+, r24
272 ; TINY-NEXT: st Z+, r25
273 ; TINY-NEXT: subi r30, 4
274 ; TINY-NEXT: sbci r31, 0
275 ; TINY-NEXT: in r16, 63
276 ; TINY-NEXT: subi r28, 251
277 ; TINY-NEXT: sbci r29, 255
278 ; TINY-NEXT: ld r24, Y+
279 ; TINY-NEXT: ld r25, Y+
280 ; TINY-NEXT: subi r28, 2
281 ; TINY-NEXT: sbci r29, 0
282 ; TINY-NEXT: subi r28, 5
283 ; TINY-NEXT: sbci r29, 0
284 ; TINY-NEXT: out 63, r16
285 ; TINY-NEXT: st Z+, r24
286 ; TINY-NEXT: st Z+, r25
293 define i64 @return64_arg2(i64 %x, i64 %y, i64 %z) {
294 ; AVR-LABEL: return64_arg2:
298 ; AVR-NEXT: in r28, 61
299 ; AVR-NEXT: in r29, 62
300 ; AVR-NEXT: ldd r18, Y+5
301 ; AVR-NEXT: ldd r19, Y+6
302 ; AVR-NEXT: ldd r20, Y+7
303 ; AVR-NEXT: ldd r21, Y+8
304 ; AVR-NEXT: ldd r22, Y+9
305 ; AVR-NEXT: ldd r23, Y+10
306 ; AVR-NEXT: ldd r24, Y+11
307 ; AVR-NEXT: ldd r25, Y+12
312 ; TINY-LABEL: return64_arg2:
314 ; TINY-NEXT: push r28
315 ; TINY-NEXT: push r29
316 ; TINY-NEXT: in r28, 61
317 ; TINY-NEXT: in r29, 62
318 ; TINY-NEXT: in r16, 63
319 ; TINY-NEXT: subi r28, 229
320 ; TINY-NEXT: sbci r29, 255
321 ; TINY-NEXT: ld r20, Y+
322 ; TINY-NEXT: ld r21, Y+
323 ; TINY-NEXT: subi r28, 2
324 ; TINY-NEXT: sbci r29, 0
325 ; TINY-NEXT: subi r28, 27
326 ; TINY-NEXT: sbci r29, 0
327 ; TINY-NEXT: out 63, r16
328 ; TINY-NEXT: mov r30, r24
329 ; TINY-NEXT: mov r31, r25
330 ; TINY-NEXT: subi r30, 250
331 ; TINY-NEXT: sbci r31, 255
332 ; TINY-NEXT: st Z+, r20
333 ; TINY-NEXT: st Z+, r21
334 ; TINY-NEXT: subi r30, 8
335 ; TINY-NEXT: sbci r31, 0
336 ; TINY-NEXT: in r16, 63
337 ; TINY-NEXT: subi r28, 231
338 ; TINY-NEXT: sbci r29, 255
339 ; TINY-NEXT: ld r24, Y+
340 ; TINY-NEXT: ld r25, Y+
341 ; TINY-NEXT: subi r28, 2
342 ; TINY-NEXT: sbci r29, 0
343 ; TINY-NEXT: subi r28, 25
344 ; TINY-NEXT: sbci r29, 0
345 ; TINY-NEXT: out 63, r16
346 ; TINY-NEXT: subi r30, 252
347 ; TINY-NEXT: sbci r31, 255
348 ; TINY-NEXT: st Z+, r24
349 ; TINY-NEXT: st Z+, r25
350 ; TINY-NEXT: subi r30, 6
351 ; TINY-NEXT: sbci r31, 0
352 ; TINY-NEXT: in r16, 63
353 ; TINY-NEXT: subi r28, 233
354 ; TINY-NEXT: sbci r29, 255
355 ; TINY-NEXT: ld r24, Y+
356 ; TINY-NEXT: ld r25, Y+
357 ; TINY-NEXT: subi r28, 2
358 ; TINY-NEXT: sbci r29, 0
359 ; TINY-NEXT: subi r28, 23
360 ; TINY-NEXT: sbci r29, 0
361 ; TINY-NEXT: out 63, r16
362 ; TINY-NEXT: subi r30, 254
363 ; TINY-NEXT: sbci r31, 255
364 ; TINY-NEXT: st Z+, r24
365 ; TINY-NEXT: st Z+, r25
366 ; TINY-NEXT: subi r30, 4
367 ; TINY-NEXT: sbci r31, 0
368 ; TINY-NEXT: in r16, 63
369 ; TINY-NEXT: subi r28, 235
370 ; TINY-NEXT: sbci r29, 255
371 ; TINY-NEXT: ld r24, Y+
372 ; TINY-NEXT: ld r25, Y+
373 ; TINY-NEXT: subi r28, 2
374 ; TINY-NEXT: sbci r29, 0
375 ; TINY-NEXT: subi r28, 21
376 ; TINY-NEXT: sbci r29, 0
377 ; TINY-NEXT: out 63, r16
378 ; TINY-NEXT: st Z+, r24
379 ; TINY-NEXT: st Z+, r25
386 define i32 @return64_trunc(i32 %a, i32 %b, i32 %c, i64 %d) {
387 ; AVR-LABEL: return64_trunc:
391 ; AVR-NEXT: in r28, 61
392 ; AVR-NEXT: in r29, 62
393 ; AVR-NEXT: ldd r22, Y+5
394 ; AVR-NEXT: ldd r23, Y+6
395 ; AVR-NEXT: ldd r24, Y+7
396 ; AVR-NEXT: ldd r25, Y+8
401 ; TINY-LABEL: return64_trunc:
403 ; TINY-NEXT: push r28
404 ; TINY-NEXT: push r29
405 ; TINY-NEXT: in r28, 61
406 ; TINY-NEXT: in r29, 62
407 ; TINY-NEXT: in r16, 63
408 ; TINY-NEXT: subi r28, 243
409 ; TINY-NEXT: sbci r29, 255
410 ; TINY-NEXT: ld r22, Y+
411 ; TINY-NEXT: ld r23, Y+
412 ; TINY-NEXT: subi r28, 2
413 ; TINY-NEXT: sbci r29, 0
414 ; TINY-NEXT: subi r28, 13
415 ; TINY-NEXT: sbci r29, 0
416 ; TINY-NEXT: out 63, r16
417 ; TINY-NEXT: in r16, 63
418 ; TINY-NEXT: subi r28, 241
419 ; TINY-NEXT: sbci r29, 255
420 ; TINY-NEXT: ld r24, Y+
421 ; TINY-NEXT: ld r25, Y+
422 ; TINY-NEXT: subi r28, 2
423 ; TINY-NEXT: sbci r29, 0
424 ; TINY-NEXT: subi r28, 15
425 ; TINY-NEXT: sbci r29, 0
426 ; TINY-NEXT: out 63, r16
430 %result = trunc i64 %d to i32
434 define avr_intrcc void @interrupt_handler() {
435 ; AVR-LABEL: interrupt_handler:
439 ; AVR-NEXT: in r0, 63
442 ; AVR-NEXT: out 63, r0
446 ; TINY-LABEL: interrupt_handler:
449 ; TINY-NEXT: push r16
450 ; TINY-NEXT: in r16, 63
451 ; TINY-NEXT: push r16
453 ; TINY-NEXT: out 63, r16
459 define avr_signalcc void @signal_handler() {
460 ; AVR-LABEL: signal_handler:
463 ; AVR-NEXT: in r0, 63
466 ; AVR-NEXT: out 63, r0
470 ; TINY-LABEL: signal_handler:
472 ; TINY-NEXT: push r16
473 ; TINY-NEXT: in r16, 63
474 ; TINY-NEXT: push r16
476 ; TINY-NEXT: out 63, r16