1 ; RUN: llc -mtriple=aarch64-apple-darwin -verify-machineinstrs < %s | FileCheck %s --check-prefix=CHECK --check-prefix=SDAG
2 ; RUN: llc -mtriple=aarch64-apple-darwin -fast-isel -fast-isel-abort=1 -verify-machineinstrs < %s | FileCheck %s --check-prefix=CHECK --check-prefix=FAST
4 ; Load / Store Base Register only
5 define zeroext i1 @load_breg_i1(i1* %a) {
6 ; CHECK-LABEL: load_breg_i1
7 ; CHECK: ldrb {{w[0-9]+}}, [x0]
12 define zeroext i8 @load_breg_i8(i8* %a) {
13 ; CHECK-LABEL: load_breg_i8
14 ; CHECK: ldrb {{w[0-9]+}}, [x0]
19 define zeroext i16 @load_breg_i16(i16* %a) {
20 ; CHECK-LABEL: load_breg_i16
21 ; CHECK: ldrh {{w[0-9]+}}, [x0]
22 %1 = load i16, i16* %a
26 define i32 @load_breg_i32(i32* %a) {
27 ; CHECK-LABEL: load_breg_i32
28 ; CHECK: ldr {{w[0-9]+}}, [x0]
29 %1 = load i32, i32* %a
33 define i64 @load_breg_i64(i64* %a) {
34 ; CHECK-LABEL: load_breg_i64
35 ; CHECK: ldr {{x[0-9]+}}, [x0]
36 %1 = load i64, i64* %a
40 define float @load_breg_f32(float* %a) {
41 ; CHECK-LABEL: load_breg_f32
42 ; CHECK: ldr {{s[0-9]+}}, [x0]
43 %1 = load float, float* %a
47 define double @load_breg_f64(double* %a) {
48 ; CHECK-LABEL: load_breg_f64
49 ; CHECK: ldr {{d[0-9]+}}, [x0]
50 %1 = load double, double* %a
54 define void @store_breg_i1(i1* %a) {
55 ; CHECK-LABEL: store_breg_i1
56 ; CHECK: strb wzr, [x0]
61 define void @store_breg_i1_2(i1* %a) {
62 ; CHECK-LABEL: store_breg_i1_2
63 ; CHECK: strb {{w[0-9]+}}, [x0]
68 define void @store_breg_i8(i8* %a) {
69 ; CHECK-LABEL: store_breg_i8
70 ; CHECK: strb wzr, [x0]
75 define void @store_breg_i16(i16* %a) {
76 ; CHECK-LABEL: store_breg_i16
77 ; CHECK: strh wzr, [x0]
82 define void @store_breg_i32(i32* %a) {
83 ; CHECK-LABEL: store_breg_i32
84 ; CHECK: str wzr, [x0]
89 define void @store_breg_i64(i64* %a) {
90 ; CHECK-LABEL: store_breg_i64
91 ; CHECK: str xzr, [x0]
96 define void @store_breg_f32(float* %a) {
97 ; CHECK-LABEL: store_breg_f32
98 ; CHECK: str wzr, [x0]
99 store float 0.0, float* %a
103 define void @store_breg_f64(double* %a) {
104 ; CHECK-LABEL: store_breg_f64
105 ; CHECK: str xzr, [x0]
106 store double 0.0, double* %a
111 define i32 @load_immoff_1() {
112 ; CHECK-LABEL: load_immoff_1
113 ; CHECK: mov {{w|x}}[[REG:[0-9]+]], #128
114 ; CHECK: ldr {{w[0-9]+}}, {{\[}}x[[REG]]{{\]}}
115 %1 = inttoptr i64 128 to i32*
116 %2 = load i32, i32* %1
120 ; Load / Store Base Register + Immediate Offset
121 ; Max supported negative offset
122 define i32 @load_breg_immoff_1(i64 %a) {
123 ; CHECK-LABEL: load_breg_immoff_1
124 ; CHECK: ldur {{w[0-9]+}}, [x0, #-256]
125 %1 = add i64 %a, -256
126 %2 = inttoptr i64 %1 to i32*
127 %3 = load i32, i32* %2
131 ; Min not-supported negative offset
132 define i32 @load_breg_immoff_2(i64 %a) {
133 ; CHECK-LABEL: load_breg_immoff_2
134 ; CHECK: sub [[REG:x[0-9]+]], x0, #257
135 ; CHECK-NEXT: ldr {{w[0-9]+}}, {{\[}}[[REG]]{{\]}}
136 %1 = add i64 %a, -257
137 %2 = inttoptr i64 %1 to i32*
138 %3 = load i32, i32* %2
142 ; Max supported unscaled offset
143 define i32 @load_breg_immoff_3(i64 %a) {
144 ; CHECK-LABEL: load_breg_immoff_3
145 ; CHECK: ldur {{w[0-9]+}}, [x0, #255]
147 %2 = inttoptr i64 %1 to i32*
148 %3 = load i32, i32* %2
152 ; Min un-supported unscaled offset
153 define i32 @load_breg_immoff_4(i64 %a) {
154 ; CHECK-LABEL: load_breg_immoff_4
155 ; CHECK: add [[REG:x[0-9]+]], x0, #257
156 ; CHECK-NEXT: ldr {{w[0-9]+}}, {{\[}}[[REG]]{{\]}}
158 %2 = inttoptr i64 %1 to i32*
159 %3 = load i32, i32* %2
163 ; Max supported scaled offset
164 define i32 @load_breg_immoff_5(i64 %a) {
165 ; CHECK-LABEL: load_breg_immoff_5
166 ; CHECK: ldr {{w[0-9]+}}, [x0, #16380]
167 %1 = add i64 %a, 16380
168 %2 = inttoptr i64 %1 to i32*
169 %3 = load i32, i32* %2
173 ; Min un-supported scaled offset
174 define i32 @load_breg_immoff_6(i64 %a) {
175 ; SDAG-LABEL: load_breg_immoff_6
176 ; SDAG: mov w[[NUM:[0-9]+]], #16384
177 ; SDAG-NEXT: ldr {{w[0-9]+}}, [x0, x[[NUM]]]
178 ; FAST-LABEL: load_breg_immoff_6
179 ; FAST: add [[REG:x[0-9]+]], x0, #4, lsl #12
180 ; FAST-NEXT: ldr {{w[0-9]+}}, {{\[}}[[REG]]{{\]}}
181 %1 = add i64 %a, 16384
182 %2 = inttoptr i64 %1 to i32*
183 %3 = load i32, i32* %2
187 ; Max supported negative offset
188 define void @store_breg_immoff_1(i64 %a) {
189 ; CHECK-LABEL: store_breg_immoff_1
190 ; CHECK: stur wzr, [x0, #-256]
191 %1 = add i64 %a, -256
192 %2 = inttoptr i64 %1 to i32*
197 ; Min not-supported negative offset
198 define void @store_breg_immoff_2(i64 %a) {
199 ; CHECK-LABEL: store_breg_immoff_2
200 ; CHECK: sub [[REG:x[0-9]+]], x0, #257
201 ; CHECK-NEXT: str wzr, {{\[}}[[REG]]{{\]}}
202 %1 = add i64 %a, -257
203 %2 = inttoptr i64 %1 to i32*
208 ; Max supported unscaled offset
209 define void @store_breg_immoff_3(i64 %a) {
210 ; CHECK-LABEL: store_breg_immoff_3
211 ; CHECK: stur wzr, [x0, #255]
213 %2 = inttoptr i64 %1 to i32*
218 ; Min un-supported unscaled offset
219 define void @store_breg_immoff_4(i64 %a) {
220 ; CHECK-LABEL: store_breg_immoff_4
221 ; CHECK: add [[REG:x[0-9]+]], x0, #257
222 ; CHECK-NEXT: str wzr, {{\[}}[[REG]]{{\]}}
224 %2 = inttoptr i64 %1 to i32*
229 ; Max supported scaled offset
230 define void @store_breg_immoff_5(i64 %a) {
231 ; CHECK-LABEL: store_breg_immoff_5
232 ; CHECK: str wzr, [x0, #16380]
233 %1 = add i64 %a, 16380
234 %2 = inttoptr i64 %1 to i32*
239 ; Min un-supported scaled offset
240 define void @store_breg_immoff_6(i64 %a) {
241 ; SDAG-LABEL: store_breg_immoff_6
242 ; SDAG: mov w[[NUM:[0-9]+]], #16384
243 ; SDAG-NEXT: str wzr, [x0, x[[NUM]]]
244 ; FAST-LABEL: store_breg_immoff_6
245 ; FAST: add [[REG:x[0-9]+]], x0, #4, lsl #12
246 ; FAST-NEXT: str wzr, {{\[}}[[REG]]{{\]}}
247 %1 = add i64 %a, 16384
248 %2 = inttoptr i64 %1 to i32*
253 define i64 @load_breg_immoff_7(i64 %a) {
254 ; CHECK-LABEL: load_breg_immoff_7
255 ; CHECK: ldr {{x[0-9]+}}, [x0, #48]
257 %2 = inttoptr i64 %1 to i64*
258 %3 = load i64, i64* %2
263 define i64 @load_breg_immoff_8(i64 %a) {
264 ; CHECK-LABEL: load_breg_immoff_8
265 ; CHECK: ldr {{x[0-9]+}}, [x0, #48]
267 %2 = inttoptr i64 %1 to i64*
268 %3 = load i64, i64* %2
272 ; Load Base Register + Register Offset
273 define i64 @load_breg_offreg_1(i64 %a, i64 %b) {
274 ; CHECK-LABEL: load_breg_offreg_1
275 ; CHECK: ldr {{x[0-9]+}}, [x0, x1]
277 %2 = inttoptr i64 %1 to i64*
278 %3 = load i64, i64* %2
283 define i64 @load_breg_offreg_2(i64 %a, i64 %b) {
284 ; CHECK-LABEL: load_breg_offreg_2
285 ; CHECK: ldr {{x[0-9]+}}, [x1, x0]
287 %2 = inttoptr i64 %1 to i64*
288 %3 = load i64, i64* %2
292 ; Load Base Register + Register Offset + Immediate Offset
293 define i64 @load_breg_offreg_immoff_1(i64 %a, i64 %b) {
294 ; CHECK-LABEL: load_breg_offreg_immoff_1
295 ; CHECK: add [[REG:x[0-9]+]], x0, x1
296 ; CHECK-NEXT: ldr x0, {{\[}}[[REG]], #48{{\]}}
299 %3 = inttoptr i64 %2 to i64*
300 %4 = load i64, i64* %3
304 define i64 @load_breg_offreg_immoff_2(i64 %a, i64 %b) {
305 ; SDAG-LABEL: load_breg_offreg_immoff_2
306 ; SDAG: add [[REG1:x[0-9]+]], x0, x1
307 ; SDAG-NEXT: mov w[[NUM:[0-9]+]], #61440
308 ; SDAG-NEXT: ldr x0, {{\[}}[[REG1]], x[[NUM]]]
309 ; FAST-LABEL: load_breg_offreg_immoff_2
310 ; FAST: add [[REG:x[0-9]+]], x0, #15, lsl #12
311 ; FAST-NEXT: ldr x0, {{\[}}[[REG]], x1{{\]}}
313 %2 = add i64 %1, 61440
314 %3 = inttoptr i64 %2 to i64*
315 %4 = load i64, i64* %3
319 ; Load Scaled Register Offset
320 define i32 @load_shift_offreg_1(i64 %a) {
321 ; CHECK-LABEL: load_shift_offreg_1
322 ; CHECK: lsl [[REG:x[0-9]+]], x0, #2
323 ; CHECK: ldr {{w[0-9]+}}, {{\[}}[[REG]]{{\]}}
325 %2 = inttoptr i64 %1 to i32*
326 %3 = load i32, i32* %2
330 define i32 @load_mul_offreg_1(i64 %a) {
331 ; CHECK-LABEL: load_mul_offreg_1
332 ; CHECK: lsl [[REG:x[0-9]+]], x0, #2
333 ; CHECK: ldr {{w[0-9]+}}, {{\[}}[[REG]]{{\]}}
335 %2 = inttoptr i64 %1 to i32*
336 %3 = load i32, i32* %2
340 ; Load Base Register + Scaled Register Offset
341 define i32 @load_breg_shift_offreg_1(i64 %a, i64 %b) {
342 ; CHECK-LABEL: load_breg_shift_offreg_1
343 ; CHECK: ldr {{w[0-9]+}}, [x1, x0, lsl #2]
346 %3 = inttoptr i64 %2 to i32*
347 %4 = load i32, i32* %3
351 define i32 @load_breg_shift_offreg_2(i64 %a, i64 %b) {
352 ; CHECK-LABEL: load_breg_shift_offreg_2
353 ; CHECK: ldr {{w[0-9]+}}, [x1, x0, lsl #2]
356 %3 = inttoptr i64 %2 to i32*
357 %4 = load i32, i32* %3
361 define i32 @load_breg_shift_offreg_3(i64 %a, i64 %b) {
362 ; SDAG-LABEL: load_breg_shift_offreg_3
363 ; SDAG: lsl [[REG:x[0-9]+]], x0, #2
364 ; SDAG-NEXT: ldr {{w[0-9]+}}, {{\[}}[[REG]], x1, lsl #2{{\]}}
365 ; FAST-LABEL: load_breg_shift_offreg_3
366 ; FAST: lsl [[REG:x[0-9]+]], x1, #2
367 ; FAST-NEXT: ldr {{w[0-9]+}}, {{\[}}[[REG]], x0, lsl #2{{\]}}
371 %4 = inttoptr i64 %3 to i32*
372 %5 = load i32, i32* %4
376 define i32 @load_breg_shift_offreg_4(i64 %a, i64 %b) {
377 ; SDAG-LABEL: load_breg_shift_offreg_4
378 ; SDAG: lsl [[REG:x[0-9]+]], x1, #2
379 ; SDAG-NEXT: ldr {{w[0-9]+}}, {{\[}}[[REG]], x0, lsl #2{{\]}}
380 ; FAST-LABEL: load_breg_shift_offreg_4
381 ; FAST: lsl [[REG:x[0-9]+]], x0, #2
382 ; FAST-NEXT: ldr {{w[0-9]+}}, {{\[}}[[REG]], x1, lsl #2{{\]}}
386 %4 = inttoptr i64 %3 to i32*
387 %5 = load i32, i32* %4
391 define i32 @load_breg_shift_offreg_5(i64 %a, i64 %b) {
392 ; SDAG-LABEL: load_breg_shift_offreg_5
393 ; SDAG: lsl [[REG:x[0-9]+]], x1, #3
394 ; SDAG-NEXT: ldr {{w[0-9]+}}, {{\[}}[[REG]], x0, lsl #2{{\]}}
395 ; FAST-LABEL: load_breg_shift_offreg_5
396 ; FAST: lsl [[REG:x[0-9]+]], x1, #3
397 ; FAST-NEXT: ldr {{w[0-9]+}}, {{\[}}[[REG]], x0, lsl #2{{\]}}
401 %4 = inttoptr i64 %3 to i32*
402 %5 = load i32, i32* %4
406 define i32 @load_breg_mul_offreg_1(i64 %a, i64 %b) {
407 ; CHECK-LABEL: load_breg_mul_offreg_1
408 ; CHECK: ldr {{w[0-9]+}}, [x1, x0, lsl #2]
411 %3 = inttoptr i64 %2 to i32*
412 %4 = load i32, i32* %3
416 define zeroext i8 @load_breg_and_offreg_1(i64 %a, i64 %b) {
417 ; CHECK-LABEL: load_breg_and_offreg_1
418 ; CHECK: ldrb {{w[0-9]+}}, [x1, w0, uxtw]
419 %1 = and i64 %a, 4294967295
421 %3 = inttoptr i64 %2 to i8*
426 define zeroext i16 @load_breg_and_offreg_2(i64 %a, i64 %b) {
427 ; CHECK-LABEL: load_breg_and_offreg_2
428 ; CHECK: ldrh {{w[0-9]+}}, [x1, w0, uxtw #1]
429 %1 = and i64 %a, 4294967295
432 %4 = inttoptr i64 %3 to i16*
433 %5 = load i16, i16* %4
437 define i32 @load_breg_and_offreg_3(i64 %a, i64 %b) {
438 ; CHECK-LABEL: load_breg_and_offreg_3
439 ; CHECK: ldr {{w[0-9]+}}, [x1, w0, uxtw #2]
440 %1 = and i64 %a, 4294967295
443 %4 = inttoptr i64 %3 to i32*
444 %5 = load i32, i32* %4
448 define i64 @load_breg_and_offreg_4(i64 %a, i64 %b) {
449 ; CHECK-LABEL: load_breg_and_offreg_4
450 ; CHECK: ldr {{x[0-9]+}}, [x1, w0, uxtw #3]
451 %1 = and i64 %a, 4294967295
454 %4 = inttoptr i64 %3 to i64*
455 %5 = load i64, i64* %4
459 ; Not all 'and' instructions have immediates.
460 define i64 @load_breg_and_offreg_5(i64 %a, i64 %b, i64 %c) {
461 ; CHECK-LABEL: load_breg_and_offreg_5
462 ; CHECK: and [[REG:x[0-9]+]], x0, x2
463 ; CHECK-NEXT: ldr {{x[0-9]+}}, {{\[}}[[REG]], x1{{\]}}
466 %3 = inttoptr i64 %2 to i64*
467 %4 = load i64, i64* %3
471 define i64 @load_breg_and_offreg_6(i64 %a, i64 %b, i64 %c) {
472 ; CHECK-LABEL: load_breg_and_offreg_6
473 ; CHECK: and [[REG:x[0-9]+]], x0, x2
474 ; CHECK-NEXT: ldr {{x[0-9]+}}, {{\[}}x1, [[REG]], lsl #3{{\]}}
478 %4 = inttoptr i64 %3 to i64*
479 %5 = load i64, i64* %4
483 ; Load Base Register + Scaled Register Offset + Sign/Zero extension
484 define i32 @load_breg_zext_shift_offreg_1(i32 %a, i64 %b) {
485 ; CHECK-LABEL: load_breg_zext_shift_offreg_1
486 ; CHECK: ldr {{w[0-9]+}}, [x1, w0, uxtw #2]
487 %1 = zext i32 %a to i64
490 %4 = inttoptr i64 %3 to i32*
491 %5 = load i32, i32* %4
495 define i32 @load_breg_zext_shift_offreg_2(i32 %a, i64 %b) {
496 ; CHECK-LABEL: load_breg_zext_shift_offreg_2
497 ; CHECK: ldr {{w[0-9]+}}, [x1, w0, uxtw #2]
498 %1 = zext i32 %a to i64
501 %4 = inttoptr i64 %3 to i32*
502 %5 = load i32, i32* %4
506 define i32 @load_breg_zext_mul_offreg_1(i32 %a, i64 %b) {
507 ; CHECK-LABEL: load_breg_zext_mul_offreg_1
508 ; CHECK: ldr {{w[0-9]+}}, [x1, w0, uxtw #2]
509 %1 = zext i32 %a to i64
512 %4 = inttoptr i64 %3 to i32*
513 %5 = load i32, i32* %4
517 define i32 @load_breg_sext_shift_offreg_1(i32 %a, i64 %b) {
518 ; CHECK-LABEL: load_breg_sext_shift_offreg_1
519 ; CHECK: ldr {{w[0-9]+}}, [x1, w0, sxtw #2]
520 %1 = sext i32 %a to i64
523 %4 = inttoptr i64 %3 to i32*
524 %5 = load i32, i32* %4
528 define i32 @load_breg_sext_shift_offreg_2(i32 %a, i64 %b) {
529 ; CHECK-LABEL: load_breg_sext_shift_offreg_2
530 ; CHECK: ldr {{w[0-9]+}}, [x1, w0, sxtw #2]
531 %1 = sext i32 %a to i64
534 %4 = inttoptr i64 %3 to i32*
535 %5 = load i32, i32* %4
539 ; Make sure that we don't drop the first 'add' instruction.
540 define i32 @load_breg_sext_shift_offreg_3(i32 %a, i64 %b) {
541 ; CHECK-LABEL: load_breg_sext_shift_offreg_3
542 ; CHECK: add [[REG:w[0-9]+]], w0, #4
543 ; CHECK: ldr {{w[0-9]+}}, {{\[}}x1, [[REG]], sxtw #2{{\]}}
545 %2 = sext i32 %1 to i64
548 %5 = inttoptr i64 %4 to i32*
549 %6 = load i32, i32* %5
554 define i32 @load_breg_sext_mul_offreg_1(i32 %a, i64 %b) {
555 ; CHECK-LABEL: load_breg_sext_mul_offreg_1
556 ; CHECK: ldr {{w[0-9]+}}, [x1, w0, sxtw #2]
557 %1 = sext i32 %a to i64
560 %4 = inttoptr i64 %3 to i32*
561 %5 = load i32, i32* %4
565 ; Load Scaled Register Offset + Immediate Offset + Sign/Zero extension
566 define i64 @load_sext_shift_offreg_imm1(i32 %a) {
567 ; CHECK-LABEL: load_sext_shift_offreg_imm1
568 ; CHECK: sbfiz [[REG:x[0-9]+]], {{x[0-9]+}}, #3, #32
569 ; CHECK-NEXT: ldr {{x[0-9]+}}, {{\[}}[[REG]], #8{{\]}}
570 %1 = sext i32 %a to i64
573 %4 = inttoptr i64 %3 to i64*
574 %5 = load i64, i64* %4
578 ; Load Base Register + Scaled Register Offset + Immediate Offset + Sign/Zero extension
579 define i64 @load_breg_sext_shift_offreg_imm1(i32 %a, i64 %b) {
580 ; CHECK-LABEL: load_breg_sext_shift_offreg_imm1
581 ; CHECK: add [[REG:x[0-9]+]], x1, w0, sxtw #3
582 ; CHECK-NEXT: ldr {{x[0-9]+}}, {{\[}}[[REG]], #8{{\]}}
583 %1 = sext i32 %a to i64
587 %5 = inttoptr i64 %4 to i64*
588 %6 = load i64, i64* %5
592 ; Test that the kill flag is not set - the machine instruction verifier does that for us.
593 define i64 @kill_reg(i64 %a) {
596 %3 = inttoptr i64 %2 to i64*
597 %4 = load i64, i64* %3
602 define void @store_fi(i64 %i) {
603 ; CHECK-LABEL: store_fi
604 ; CHECK: mov [[REG:x[0-9]+]], sp
605 ; CHECK: str {{w[0-9]+}}, {{\[}}[[REG]], x0, lsl #2{{\]}}
606 %1 = alloca [8 x i32]
607 %2 = ptrtoint [8 x i32]* %1 to i64
610 %5 = inttoptr i64 %4 to i32*
611 store i32 47, i32* %5, align 4
615 define i32 @load_fi(i64 %i) {
616 ; CHECK-LABEL: load_fi
617 ; CHECK: mov [[REG:x[0-9]+]], sp
618 ; CHECK: ldr {{w[0-9]+}}, {{\[}}[[REG]], x0, lsl #2{{\]}}
619 %1 = alloca [8 x i32]
620 %2 = ptrtoint [8 x i32]* %1 to i64
623 %5 = inttoptr i64 %4 to i32*
624 %6 = load i32, i32* %5, align 4