1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-linux-gnu -verify-machineinstrs | FileCheck %s
4 ; Note that this should be refactored (for efficiency if nothing else)
5 ; when the PCS is implemented so we don't have to worry about the
8 @var_i32 = global i32 42
9 @var2_i32 = global i32 43
10 @var_i64 = global i64 0
12 ; Add pure 12-bit immediates:
13 define void @add_small() {
14 ; CHECK-LABEL: add_small:
16 ; CHECK-NEXT: adrp x8, :got:var_i32
17 ; CHECK-NEXT: adrp x9, :got:var_i64
18 ; CHECK-NEXT: ldr x8, [x8, :got_lo12:var_i32]
19 ; CHECK-NEXT: ldr x9, [x9, :got_lo12:var_i64]
20 ; CHECK-NEXT: ldr w10, [x8]
21 ; CHECK-NEXT: ldr x11, [x9]
22 ; CHECK-NEXT: add w10, w10, #4095
23 ; CHECK-NEXT: add x11, x11, #52
24 ; CHECK-NEXT: str w10, [x8]
25 ; CHECK-NEXT: str x11, [x9]
28 %val32 = load i32, ptr @var_i32
29 %newval32 = add i32 %val32, 4095
30 store i32 %newval32, ptr @var_i32
32 %val64 = load i64, ptr @var_i64
33 %newval64 = add i64 %val64, 52
34 store i64 %newval64, ptr @var_i64
39 ; Make sure we grab the imm variant when the register operand
40 ; can be implicitly zero-extend.
41 ; We used to generate something horrible like this:
44 ; xC = add xB, wA, uxtb
45 ; whereas this can be achieved with:
47 ; xC = add xA, #12 ; <- xA implicitly zero extend wA.
48 define void @add_small_imm(ptr %p, ptr %q, i32 %b, ptr %addr) {
49 ; CHECK-LABEL: add_small_imm:
50 ; CHECK: // %bb.0: // %entry
51 ; CHECK-NEXT: ldrb w8, [x0]
52 ; CHECK-NEXT: add w9, w8, w2
53 ; CHECK-NEXT: add x8, x8, #12
54 ; CHECK-NEXT: str w9, [x3]
55 ; CHECK-NEXT: str x8, [x1]
60 %promoted = zext i8 %t to i64
61 %zextt = zext i8 %t to i32
62 %add = add nuw i32 %zextt, %b
64 %add2 = add nuw i64 %promoted, 12
65 store i32 %add, ptr %addr
67 store i64 %add2, ptr %q
71 ; Add 12-bit immediates, shifted left by 12 bits
72 define void @add_med() {
73 ; CHECK-LABEL: add_med:
75 ; CHECK-NEXT: adrp x8, :got:var_i32
76 ; CHECK-NEXT: adrp x9, :got:var_i64
77 ; CHECK-NEXT: ldr x8, [x8, :got_lo12:var_i32]
78 ; CHECK-NEXT: ldr x9, [x9, :got_lo12:var_i64]
79 ; CHECK-NEXT: ldr w10, [x8]
80 ; CHECK-NEXT: ldr x11, [x9]
81 ; CHECK-NEXT: add w10, w10, #3567, lsl #12 // =14610432
82 ; CHECK-NEXT: add x11, x11, #4095, lsl #12 // =16773120
83 ; CHECK-NEXT: str w10, [x8]
84 ; CHECK-NEXT: str x11, [x9]
87 %val32 = load i32, ptr @var_i32
88 %newval32 = add i32 %val32, 14610432 ; =0xdef000
89 store i32 %newval32, ptr @var_i32
91 %val64 = load i64, ptr @var_i64
92 %newval64 = add i64 %val64, 16773120 ; =0xfff000
93 store i64 %newval64, ptr @var_i64
98 ; Subtract 12-bit immediates
99 define void @sub_small() {
100 ; CHECK-LABEL: sub_small:
102 ; CHECK-NEXT: adrp x8, :got:var_i32
103 ; CHECK-NEXT: adrp x9, :got:var_i64
104 ; CHECK-NEXT: ldr x8, [x8, :got_lo12:var_i32]
105 ; CHECK-NEXT: ldr x9, [x9, :got_lo12:var_i64]
106 ; CHECK-NEXT: ldr w10, [x8]
107 ; CHECK-NEXT: ldr x11, [x9]
108 ; CHECK-NEXT: sub w10, w10, #4095
109 ; CHECK-NEXT: sub x11, x11, #52
110 ; CHECK-NEXT: str w10, [x8]
111 ; CHECK-NEXT: str x11, [x9]
114 %val32 = load i32, ptr @var_i32
115 %newval32 = sub i32 %val32, 4095
116 store i32 %newval32, ptr @var_i32
118 %val64 = load i64, ptr @var_i64
119 %newval64 = sub i64 %val64, 52
120 store i64 %newval64, ptr @var_i64
125 ; Subtract 12-bit immediates, shifted left by 12 bits
126 define void @sub_med() {
127 ; CHECK-LABEL: sub_med:
129 ; CHECK-NEXT: adrp x8, :got:var_i32
130 ; CHECK-NEXT: adrp x9, :got:var_i64
131 ; CHECK-NEXT: ldr x8, [x8, :got_lo12:var_i32]
132 ; CHECK-NEXT: ldr x9, [x9, :got_lo12:var_i64]
133 ; CHECK-NEXT: ldr w10, [x8]
134 ; CHECK-NEXT: ldr x11, [x9]
135 ; CHECK-NEXT: sub w10, w10, #3567, lsl #12 // =14610432
136 ; CHECK-NEXT: sub x11, x11, #4095, lsl #12 // =16773120
137 ; CHECK-NEXT: str w10, [x8]
138 ; CHECK-NEXT: str x11, [x9]
141 %val32 = load i32, ptr @var_i32
142 %newval32 = sub i32 %val32, 14610432 ; =0xdef000
143 store i32 %newval32, ptr @var_i32
145 %val64 = load i64, ptr @var_i64
146 %newval64 = sub i64 %val64, 16773120 ; =0xfff000
147 store i64 %newval64, ptr @var_i64
152 define i64 @add_two_parts_imm_i64(i64 %a) {
153 ; CHECK-LABEL: add_two_parts_imm_i64:
155 ; CHECK-NEXT: add x8, x0, #2730, lsl #12 // =11182080
156 ; CHECK-NEXT: add x0, x8, #1365
158 %b = add i64 %a, 11183445
162 define i32 @add_two_parts_imm_i32(i32 %a) {
163 ; CHECK-LABEL: add_two_parts_imm_i32:
165 ; CHECK-NEXT: add w8, w0, #2730, lsl #12 // =11182080
166 ; CHECK-NEXT: add w0, w8, #1365
168 %b = add i32 %a, 11183445
172 define i64 @add_two_parts_imm_i64_neg(i64 %a) {
173 ; CHECK-LABEL: add_two_parts_imm_i64_neg:
175 ; CHECK-NEXT: sub x8, x0, #2730, lsl #12 // =11182080
176 ; CHECK-NEXT: sub x0, x8, #1365
178 %b = add i64 %a, -11183445
182 define i32 @add_two_parts_imm_i32_neg(i32 %a) {
183 ; CHECK-LABEL: add_two_parts_imm_i32_neg:
185 ; CHECK-NEXT: sub w8, w0, #2730, lsl #12 // =11182080
186 ; CHECK-NEXT: sub w0, w8, #1365
188 %b = add i32 %a, -11183445
192 define i64 @sub_two_parts_imm_i64(i64 %a) {
193 ; CHECK-LABEL: sub_two_parts_imm_i64:
195 ; CHECK-NEXT: sub x8, x0, #2730, lsl #12 // =11182080
196 ; CHECK-NEXT: sub x0, x8, #1365
198 %b = sub i64 %a, 11183445
202 define i32 @sub_two_parts_imm_i32(i32 %a) {
203 ; CHECK-LABEL: sub_two_parts_imm_i32:
205 ; CHECK-NEXT: sub w8, w0, #2730, lsl #12 // =11182080
206 ; CHECK-NEXT: sub w0, w8, #1365
208 %b = sub i32 %a, 11183445
212 define i64 @sub_two_parts_imm_i64_neg(i64 %a) {
213 ; CHECK-LABEL: sub_two_parts_imm_i64_neg:
215 ; CHECK-NEXT: add x8, x0, #2730, lsl #12 // =11182080
216 ; CHECK-NEXT: add x0, x8, #1365
218 %b = sub i64 %a, -11183445
222 define i32 @sub_two_parts_imm_i32_neg(i32 %a) {
223 ; CHECK-LABEL: sub_two_parts_imm_i32_neg:
225 ; CHECK-NEXT: add w8, w0, #2730, lsl #12 // =11182080
226 ; CHECK-NEXT: add w0, w8, #1365
228 %b = sub i32 %a, -11183445
232 define i32 @add_27962026(i32 %a) {
233 ; CHECK-LABEL: add_27962026:
235 ; CHECK-NEXT: mov w8, #43690 // =0xaaaa
236 ; CHECK-NEXT: movk w8, #426, lsl #16
237 ; CHECK-NEXT: add w0, w0, w8
239 %b = add i32 %a, 27962026
243 define i32 @add_65534(i32 %a) {
244 ; CHECK-LABEL: add_65534:
246 ; CHECK-NEXT: mov w8, #65534 // =0xfffe
247 ; CHECK-NEXT: add w0, w0, w8
249 %b = add i32 %a, 65534
253 declare i32 @foox(i32)
255 define void @add_in_loop(i32 %0) {
256 ; CHECK-LABEL: add_in_loop:
258 ; CHECK-NEXT: stp x30, x19, [sp, #-16]! // 16-byte Folded Spill
259 ; CHECK-NEXT: .cfi_def_cfa_offset 16
260 ; CHECK-NEXT: .cfi_offset w19, -8
261 ; CHECK-NEXT: .cfi_offset w30, -16
262 ; CHECK-NEXT: mov w19, #43690 // =0xaaaa
263 ; CHECK-NEXT: movk w19, #170, lsl #16
264 ; CHECK-NEXT: .LBB15_1: // =>This Inner Loop Header: Depth=1
265 ; CHECK-NEXT: add w0, w0, w19
266 ; CHECK-NEXT: bl foox
267 ; CHECK-NEXT: b .LBB15_1
270 %3 = phi i32 [ %0, %1 ], [ %5, %2 ]
271 %4 = add nsw i32 %3, 11184810
272 %5 = tail call i32 @foox(i32 %4) #2
276 define void @testing() {
277 ; CHECK-LABEL: testing:
279 ; CHECK-NEXT: adrp x8, :got:var_i32
280 ; CHECK-NEXT: ldr x8, [x8, :got_lo12:var_i32]
281 ; CHECK-NEXT: ldr w9, [x8]
282 ; CHECK-NEXT: cmp w9, #4095
283 ; CHECK-NEXT: b.ne .LBB16_6
284 ; CHECK-NEXT: // %bb.1: // %test2
285 ; CHECK-NEXT: adrp x10, :got:var2_i32
286 ; CHECK-NEXT: add w11, w9, #1
287 ; CHECK-NEXT: ldr x10, [x10, :got_lo12:var2_i32]
288 ; CHECK-NEXT: str w11, [x8]
289 ; CHECK-NEXT: ldr w10, [x10]
290 ; CHECK-NEXT: cmp w10, #3567, lsl #12 // =14610432
291 ; CHECK-NEXT: b.lo .LBB16_6
292 ; CHECK-NEXT: // %bb.2: // %test3
293 ; CHECK-NEXT: add w11, w9, #2
294 ; CHECK-NEXT: cmp w9, #123
295 ; CHECK-NEXT: str w11, [x8]
296 ; CHECK-NEXT: b.lt .LBB16_6
297 ; CHECK-NEXT: // %bb.3: // %test4
298 ; CHECK-NEXT: add w11, w9, #3
299 ; CHECK-NEXT: cmp w10, #321
300 ; CHECK-NEXT: str w11, [x8]
301 ; CHECK-NEXT: b.gt .LBB16_6
302 ; CHECK-NEXT: // %bb.4: // %test5
303 ; CHECK-NEXT: add w11, w9, #4
304 ; CHECK-NEXT: cmn w10, #443
305 ; CHECK-NEXT: str w11, [x8]
306 ; CHECK-NEXT: b.ge .LBB16_6
307 ; CHECK-NEXT: // %bb.5: // %test6
308 ; CHECK-NEXT: add w9, w9, #5
309 ; CHECK-NEXT: str w9, [x8]
310 ; CHECK-NEXT: .LBB16_6: // %common.ret
312 %val = load i32, ptr @var_i32
313 %val2 = load i32, ptr @var2_i32
315 %cmp_pos_small = icmp ne i32 %val, 4095
316 br i1 %cmp_pos_small, label %ret, label %test2
319 %newval2 = add i32 %val, 1
320 store i32 %newval2, ptr @var_i32
321 %cmp_pos_big = icmp ult i32 %val2, 14610432
322 br i1 %cmp_pos_big, label %ret, label %test3
325 %newval3 = add i32 %val, 2
326 store i32 %newval3, ptr @var_i32
327 %cmp_pos_slt = icmp slt i32 %val, 123
328 br i1 %cmp_pos_slt, label %ret, label %test4
331 %newval4 = add i32 %val, 3
332 store i32 %newval4, ptr @var_i32
333 %cmp_pos_sgt = icmp sgt i32 %val2, 321
334 br i1 %cmp_pos_sgt, label %ret, label %test5
337 %newval5 = add i32 %val, 4
338 store i32 %newval5, ptr @var_i32
339 %cmp_neg_uge = icmp sgt i32 %val2, -444
340 br i1 %cmp_neg_uge, label %ret, label %test6
343 %newval6 = add i32 %val, 5
344 store i32 %newval6, ptr @var_i32
351 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
353 define i1 @sadd_add(i32 %a, i32 %b, ptr %p) {
354 ; CHECK-LABEL: sadd_add:
356 ; CHECK-NEXT: mvn w8, w0
357 ; CHECK-NEXT: adds w8, w8, w1
358 ; CHECK-NEXT: cset w0, vs
359 ; CHECK-NEXT: add w8, w8, #1
360 ; CHECK-NEXT: str w8, [x2]
362 %nota = xor i32 %a, -1
363 %a0 = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %nota, i32 %b)
364 %e0 = extractvalue {i32, i1} %a0, 0
365 %e1 = extractvalue {i32, i1} %a0, 1
366 %res = add i32 %e0, 1
367 store i32 %res, ptr %p
371 declare {i8, i1} @llvm.uadd.with.overflow.i8(i8 %a, i8 %b)
373 define i1 @uadd_add(i8 %a, i8 %b, ptr %p) {
374 ; CHECK-LABEL: uadd_add:
376 ; CHECK-NEXT: mov w8, #255 // =0xff
377 ; CHECK-NEXT: bic w8, w8, w0
378 ; CHECK-NEXT: add w8, w8, w1, uxtb
379 ; CHECK-NEXT: lsr w0, w8, #8
380 ; CHECK-NEXT: add w8, w8, #1
381 ; CHECK-NEXT: strb w8, [x2]
383 %nota = xor i8 %a, -1
384 %a0 = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %nota, i8 %b)
385 %e0 = extractvalue {i8, i1} %a0, 0
386 %e1 = extractvalue {i8, i1} %a0, 1
388 store i8 %res, ptr %p
392 ; This is a unique edge case that will generate the following MIR
394 ; SUBREG_TO_REG 0, killed %1, %subreg.sub_32
395 ; When using a 64-bit unsigned for the "-1000000" immediate, the code
396 ; must make sure to zero out the top 32 bits since SUBREG_TO_REG is
397 ; zero extending the value
398 define i64 @addl_0x80000000(i64 %a) {
399 ; CHECK-LABEL: addl_0x80000000:
401 ; CHECK-NEXT: mov w8, #48576 // =0xbdc0
402 ; CHECK-NEXT: movk w8, #65520, lsl #16
403 ; CHECK-NEXT: add x0, x0, x8
405 %b = add i64 %a, 4293967296
409 ; ADDS and SUBS Optimizations
410 ; Checks with all types first, then checks that only EQ and NE optimize
411 define i1 @eq_i(i32 %0) {
414 ; CHECK-NEXT: sub w8, w0, #273, lsl #12 // =1118208
415 ; CHECK-NEXT: cmp w8, #273
416 ; CHECK-NEXT: cset w0, eq
418 %2 = icmp eq i32 %0, 1118481
422 define i1 @eq_l(i64 %0) {
425 ; CHECK-NEXT: sub x8, x0, #273, lsl #12 // =1118208
426 ; CHECK-NEXT: cmp x8, #273
427 ; CHECK-NEXT: cset w0, eq
429 %2 = icmp eq i64 %0, 1118481
433 define i1 @ne_i(i32 %0) {
436 ; CHECK-NEXT: sub w8, w0, #273, lsl #12 // =1118208
437 ; CHECK-NEXT: cmp w8, #273
438 ; CHECK-NEXT: cset w0, ne
440 %2 = icmp ne i32 %0, 1118481
444 define i1 @ne_l(i64 %0) {
447 ; CHECK-NEXT: sub x8, x0, #273, lsl #12 // =1118208
448 ; CHECK-NEXT: cmp x8, #273
449 ; CHECK-NEXT: cset w0, ne
451 %2 = icmp ne i64 %0, 1118481
455 define i1 @eq_in(i32 %0) {
456 ; CHECK-LABEL: eq_in:
458 ; CHECK-NEXT: add w8, w0, #273, lsl #12 // =1118208
459 ; CHECK-NEXT: cmn w8, #273
460 ; CHECK-NEXT: cset w0, eq
462 %2 = icmp eq i32 %0, -1118481
466 define i1 @eq_ln(i64 %0) {
467 ; CHECK-LABEL: eq_ln:
469 ; CHECK-NEXT: add x8, x0, #273, lsl #12 // =1118208
470 ; CHECK-NEXT: cmn x8, #273
471 ; CHECK-NEXT: cset w0, eq
473 %2 = icmp eq i64 %0, -1118481
477 define i1 @ne_in(i32 %0) {
478 ; CHECK-LABEL: ne_in:
480 ; CHECK-NEXT: add w8, w0, #273, lsl #12 // =1118208
481 ; CHECK-NEXT: cmn w8, #273
482 ; CHECK-NEXT: cset w0, ne
484 %2 = icmp ne i32 %0, -1118481
488 define i1 @ne_ln(i64 %0) {
489 ; CHECK-LABEL: ne_ln:
491 ; CHECK-NEXT: add x8, x0, #273, lsl #12 // =1118208
492 ; CHECK-NEXT: cmn x8, #273
493 ; CHECK-NEXT: cset w0, ne
495 %2 = icmp ne i64 %0, -1118481
499 define i1 @reject_eq(i32 %0) {
500 ; CHECK-LABEL: reject_eq:
502 ; CHECK-NEXT: mov w8, #51712 // =0xca00
503 ; CHECK-NEXT: movk w8, #15258, lsl #16
504 ; CHECK-NEXT: cmp w0, w8
505 ; CHECK-NEXT: cset w0, eq
507 %2 = icmp eq i32 %0, 1000000000
511 define i1 @reject_non_eqne_csinc(i32 %0) {
512 ; CHECK-LABEL: reject_non_eqne_csinc:
514 ; CHECK-NEXT: mov w8, #4369 // =0x1111
515 ; CHECK-NEXT: movk w8, #17, lsl #16
516 ; CHECK-NEXT: cmp w0, w8
517 ; CHECK-NEXT: cset w0, lo
519 %2 = icmp ult i32 %0, 1118481
523 define i32 @accept_csel(i32 %0) {
524 ; CHECK-LABEL: accept_csel:
526 ; CHECK-NEXT: sub w9, w0, #273, lsl #12 // =1118208
527 ; CHECK-NEXT: mov w8, #17 // =0x11
528 ; CHECK-NEXT: cmp w9, #273
529 ; CHECK-NEXT: mov w9, #11 // =0xb
530 ; CHECK-NEXT: csel w0, w9, w8, eq
532 %2 = icmp eq i32 %0, 1118481
533 %3 = select i1 %2, i32 11, i32 17
537 define i32 @reject_non_eqne_csel(i32 %0) {
538 ; CHECK-LABEL: reject_non_eqne_csel:
540 ; CHECK-NEXT: mov w8, #4369 // =0x1111
541 ; CHECK-NEXT: mov w9, #11 // =0xb
542 ; CHECK-NEXT: movk w8, #17, lsl #16
543 ; CHECK-NEXT: cmp w0, w8
544 ; CHECK-NEXT: mov w8, #17 // =0x11
545 ; CHECK-NEXT: csel w0, w9, w8, lo
547 %2 = icmp ult i32 %0, 1118481
548 %3 = select i1 %2, i32 11, i32 17
554 define void @accept_branch(i32 %0) {
555 ; CHECK-LABEL: accept_branch:
557 ; CHECK-NEXT: sub w8, w0, #291, lsl #12 // =1191936
558 ; CHECK-NEXT: cmp w8, #1110
559 ; CHECK-NEXT: b.eq .LBB32_2
560 ; CHECK-NEXT: // %bb.1:
562 ; CHECK-NEXT: .LBB32_2:
564 %2 = icmp ne i32 %0, 1193046
565 br i1 %2, label %4, label %3
567 tail call void @fooy()
573 define void @reject_non_eqne_branch(i32 %0) {
574 ; CHECK-LABEL: reject_non_eqne_branch:
576 ; CHECK-NEXT: mov w8, #13398 // =0x3456
577 ; CHECK-NEXT: movk w8, #18, lsl #16
578 ; CHECK-NEXT: cmp w0, w8
579 ; CHECK-NEXT: b.le .LBB33_2
580 ; CHECK-NEXT: // %bb.1:
582 ; CHECK-NEXT: .LBB33_2:
584 %2 = icmp sgt i32 %0, 1193046
585 br i1 %2, label %4, label %3
587 tail call void @fooy()
593 define i32 @reject_multiple_usages(i32 %0) {
594 ; CHECK-LABEL: reject_multiple_usages:
596 ; CHECK-NEXT: mov w8, #4369 // =0x1111
597 ; CHECK-NEXT: mov w9, #3 // =0x3
598 ; CHECK-NEXT: mov w10, #17 // =0x11
599 ; CHECK-NEXT: movk w8, #17, lsl #16
600 ; CHECK-NEXT: mov w11, #12 // =0xc
601 ; CHECK-NEXT: cmp w0, w8
602 ; CHECK-NEXT: mov w8, #9 // =0x9
603 ; CHECK-NEXT: csel w8, w8, w9, eq
604 ; CHECK-NEXT: csel w9, w11, w10, hi
605 ; CHECK-NEXT: mov w10, #53312 // =0xd040
606 ; CHECK-NEXT: movk w10, #2, lsl #16
607 ; CHECK-NEXT: add w8, w8, w9
608 ; CHECK-NEXT: mov w9, #26304 // =0x66c0
609 ; CHECK-NEXT: cmp w0, w10
610 ; CHECK-NEXT: movk w9, #1433, lsl #16
611 ; CHECK-NEXT: csel w0, w8, w9, hi
613 %2 = icmp eq i32 %0, 1118481
614 %3 = icmp ugt i32 %0, 1118481
615 %4 = select i1 %2, i32 9, i32 3
616 %5 = select i1 %3, i32 12, i32 17
618 %7 = icmp ugt i32 %0, 184384
619 %8 = select i1 %7, i32 %6, i32 93939392
623 ; Unique case found in ClangBuiltLinux where the DstReg is not Virtual and
624 ; caused an assertion failure
625 define dso_local i32 @neigh_periodic_work_tbl_1() {
626 ; CHECK-LABEL: neigh_periodic_work_tbl_1:
627 ; CHECK: // %bb.0: // %entry
628 ; CHECK-NEXT: adrp x8, neigh_periodic_work_tbl_1
629 ; CHECK-NEXT: add x8, x8, :lo12:neigh_periodic_work_tbl_1
630 ; CHECK-NEXT: add x8, x8, #18, lsl #12 // =73728
631 ; CHECK-NEXT: cmn x8, #1272
632 ; CHECK-NEXT: b.pl .LBB35_2
633 ; CHECK-NEXT: .LBB35_1: // %for.cond
634 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
635 ; CHECK-NEXT: b .LBB35_1
636 ; CHECK-NEXT: .LBB35_2: // %if.end
639 br i1 icmp slt (i64 add (i64 ptrtoint (ptr @neigh_periodic_work_tbl_1 to i64), i64 75000), i64 0), label %for.cond, label %if.end
640 for.cond: ; preds = %entry, %for.cond
642 if.end: ; preds = %entry
646 @jiffies = dso_local local_unnamed_addr global i32 0, align 4
647 @primary_crng = dso_local local_unnamed_addr global i32 0, align 4
648 @input_pool = dso_local global i32 0, align 4
649 declare dso_local i32 @crng_reseed(...) local_unnamed_addr
650 ; Function Attrs: nounwind uwtable
651 define dso_local i32 @_extract_crng_crng() {
652 ; CHECK-LABEL: _extract_crng_crng:
653 ; CHECK: // %bb.0: // %entry
654 ; CHECK-NEXT: adrp x8, _extract_crng_crng
655 ; CHECK-NEXT: add x8, x8, :lo12:_extract_crng_crng
656 ; CHECK-NEXT: tbnz x8, #63, .LBB36_2
657 ; CHECK-NEXT: // %bb.1: // %lor.lhs.false
658 ; CHECK-NEXT: adrp x9, jiffies
659 ; CHECK-NEXT: ldrsw x9, [x9, :lo12:jiffies]
660 ; CHECK-NEXT: sub x8, x8, x9
661 ; CHECK-NEXT: add x8, x8, #18, lsl #12 // =73728
662 ; CHECK-NEXT: cmn x8, #1272
663 ; CHECK-NEXT: b.pl .LBB36_3
664 ; CHECK-NEXT: .LBB36_2: // %if.then
665 ; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
666 ; CHECK-NEXT: .cfi_def_cfa_offset 16
667 ; CHECK-NEXT: .cfi_offset w30, -16
668 ; CHECK-NEXT: adrp x8, primary_crng
669 ; CHECK-NEXT: ldr w8, [x8, :lo12:primary_crng]
670 ; CHECK-NEXT: cmp w8, #0
671 ; CHECK-NEXT: adrp x8, input_pool
672 ; CHECK-NEXT: add x8, x8, :lo12:input_pool
673 ; CHECK-NEXT: csel x0, xzr, x8, eq
674 ; CHECK-NEXT: bl crng_reseed
675 ; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
676 ; CHECK-NEXT: .LBB36_3: // %if.end
679 br i1 icmp slt (ptr @_extract_crng_crng, ptr null), label %if.then, label %lor.lhs.false
680 lor.lhs.false: ; preds = %entry
681 %0 = load i32, ptr @jiffies, align 4
682 %idx.ext = sext i32 %0 to i64
683 %idx.neg = sub nsw i64 0, %idx.ext
684 %add.ptr = getelementptr i8, ptr getelementptr (i8, ptr @_extract_crng_crng, i64 75000), i64 %idx.neg
685 %cmp = icmp slt ptr %add.ptr, null
686 br i1 %cmp, label %if.then, label %if.end
687 if.then: ; preds = %lor.lhs.false, %entry
688 %1 = load i32, ptr @primary_crng, align 4
689 %tobool.not = icmp eq i32 %1, 0
690 %cond = select i1 %tobool.not, ptr null, ptr @input_pool
691 %call = tail call i32 @crng_reseed(ptr noundef %cond)
693 if.end: ; preds = %if.then, %lor.lhs.false
697 ; ((X << C) - Y) + Z --> (Z - Y) + (X << C)
698 define i32 @commute_subop0(i32 %x, i32 %y, i32 %z) {
699 ; CHECK-LABEL: commute_subop0:
701 ; CHECK-NEXT: sub w8, w2, w1
702 ; CHECK-NEXT: add w0, w8, w0, lsl #3
705 %sub = sub i32 %shl, %y
706 %add = add i32 %sub, %z
710 ; ((X >> C) - Y) + Z --> (Z - Y) + (X >> C)
711 define i32 @commute_subop0_lshr(i32 %x, i32 %y, i32 %z) {
712 ; CHECK-LABEL: commute_subop0_lshr:
714 ; CHECK-NEXT: sub w8, w2, w1
715 ; CHECK-NEXT: add w0, w8, w0, lsr #3
717 %lshr = lshr i32 %x, 3
718 %sub = sub i32 %lshr, %y
719 %add = add i32 %sub, %z
723 ; ((X >> C) - Y) + Z --> (Z - Y) + (X >> C)
724 define i32 @commute_subop0_ashr(i32 %x, i32 %y, i32 %z) {
725 ; CHECK-LABEL: commute_subop0_ashr:
727 ; CHECK-NEXT: sub w8, w2, w1
728 ; CHECK-NEXT: add w0, w8, w0, asr #3
730 %ashr = ashr i32 %x, 3
731 %sub = sub i32 %ashr, %y
732 %add = add i32 %sub, %z
736 ; ((sext X) - Y) + Z --> (Z - Y) + (sext X)
737 define i64 @commute_subop0_sext(i32 %x, i64 %y, i64 %z) {
738 ; CHECK-LABEL: commute_subop0_sext:
740 ; CHECK-NEXT: sub x8, x2, x1
741 ; CHECK-NEXT: add x0, x8, w0, sxtw
743 %sext = sext i32 %x to i64
744 %sub = sub i64 %sext, %y
745 %add = add i64 %sub, %z
749 ; ((sext_inreg X) - Y) + Z --> (Z - Y) + (sext_inreg X)
750 define i64 @commute_subop0_sext_inreg(i64 %x, i64 %y, i64 %z) {
751 ; CHECK-LABEL: commute_subop0_sext_inreg:
753 ; CHECK-NEXT: sub x8, x2, x1
754 ; CHECK-NEXT: add x0, x8, w0, sxth
756 %shl = shl i64 %x, 48
757 %ashr = ashr i64 %shl, 48
758 %sub = sub i64 %ashr, %y
759 %add = add i64 %sub, %z
763 ; ((zext X) - Y) + Z --> (Z - Y) + (zext X)
764 define i32 @commute_subop0_zext(i16 %x, i32 %y, i32 %z) {
765 ; CHECK-LABEL: commute_subop0_zext:
767 ; CHECK-NEXT: sub w8, w2, w1
768 ; CHECK-NEXT: add w0, w8, w0, uxth
770 %zext = zext i16 %x to i32
771 %sub = sub i32 %zext, %y
772 %add = add i32 %sub, %z
777 ; ((anyext X) - Y) + Z --> (Z - Y) + (anyext X)
778 define i8 @commute_subop0_anyext(i16 %a, i16 %b, i32 %c) {
779 ; CHECK-LABEL: commute_subop0_anyext:
781 ; CHECK-NEXT: mov w8, #111 // =0x6f
782 ; CHECK-NEXT: sub w9, w2, w1
783 ; CHECK-NEXT: madd w8, w0, w8, w9
784 ; CHECK-NEXT: lsl w8, w8, #3
785 ; CHECK-NEXT: sub w0, w8, #1776
787 %aa = mul i16 %a, 111
788 %bb = add i16 %b, 222
789 %a_32 = zext i16 %aa to i32
790 %b_32 = zext i16 %bb to i32
791 %sub = sub i32 %a_32, %b_32
792 %add = add i32 %sub, %c
793 %trunc = trunc i32 %add to i8
794 %r = shl i8 %trunc, 3
798 ; ((X and C) - Y) + Z --> (Z - Y) + (X and C)
799 define i32 @commute_subop0_and(i32 %x, i32 %y, i32 %z) {
800 ; CHECK-LABEL: commute_subop0_and:
802 ; CHECK-NEXT: sub w8, w2, w1
803 ; CHECK-NEXT: add w0, w8, w0, uxtb
805 %and = and i32 %x, 255
806 %sub = sub i32 %and, %y
807 %add = add i32 %sub, %z
811 ; Z + ((X << C) - Y) --> (Z - Y) + (X << C)
812 define i32 @commute_subop0_cadd(i32 %x, i32 %y, i32 %z) {
813 ; CHECK-LABEL: commute_subop0_cadd:
815 ; CHECK-NEXT: sub w8, w2, w1
816 ; CHECK-NEXT: add w0, w8, w0, lsl #3
819 %sub = sub i32 %shl, %y
820 %add = add i32 %z, %sub
824 ; Y + ((X << C) - X) --> (Y - X) + (X << C)
825 define i32 @commute_subop0_mul(i32 %x, i32 %y) {
826 ; CHECK-LABEL: commute_subop0_mul:
828 ; CHECK-NEXT: sub w8, w1, w0
829 ; CHECK-NEXT: add w0, w8, w0, lsl #3
832 %add = add i32 %mul, %y
836 ; negative case for ((X << C) - Y) + Z --> (Z - Y) + (X << C)
837 ; Y can't be constant to avoid dead loop
838 define i32 @commute_subop0_zconst(i32 %x, i32 %y) {
839 ; CHECK-LABEL: commute_subop0_zconst:
841 ; CHECK-NEXT: lsl w8, w0, #3
842 ; CHECK-NEXT: sub w8, w8, w1
843 ; CHECK-NEXT: add w0, w8, #1
846 %sub = sub i32 %shl, %y
847 %add = add i32 %sub, 1
851 ; negative case for ((X << C) - Y) + Z --> (Z - Y) + (X << C)
852 ; Y can't be shift C also to avoid dead loop
853 define i32 @commute_subop0_zshiftc_oneuse(i32 %x, i32 %y, i32 %z) {
854 ; CHECK-LABEL: commute_subop0_zshiftc_oneuse:
856 ; CHECK-NEXT: lsl w8, w0, #3
857 ; CHECK-NEXT: sub w8, w8, w1
858 ; CHECK-NEXT: add w0, w8, w2, lsl #2
860 %xshl = shl i32 %x, 3
861 %sub = sub i32 %xshl, %y
862 %zshl = shl i32 %z, 2
863 %add = add i32 %sub, %zshl
867 define i32 @commute_subop0_zshiftc(i32 %x, i32 %y, i32 %z) {
868 ; CHECK-LABEL: commute_subop0_zshiftc:
870 ; CHECK-NEXT: lsl w8, w2, #2
871 ; CHECK-NEXT: sub w9, w8, w1
872 ; CHECK-NEXT: add w9, w9, w0, lsl #3
873 ; CHECK-NEXT: eor w0, w8, w9
875 %xshl = shl i32 %x, 3
876 %sub = sub i32 %xshl, %y
877 %zshl = shl i32 %z, 2
878 %add = add i32 %sub, %zshl
879 %r = xor i32 %zshl, %add