1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=aarch64-apple-darwin -aarch64-enable-collect-loh=false -aarch64-enable-sink-fold=true < %s | FileCheck %s --check-prefixes=CHECK,CHECK-SD
3 ; RUN: llc -mtriple=aarch64-apple-darwin -aarch64-enable-collect-loh=false -aarch64-enable-sink-fold=true -global-isel < %s | FileCheck %s --check-prefixes=CHECK,CHECK-GI
5 @board = common global [400 x i8] zeroinitializer, align 1
6 @next_string = common global i32 0, align 4
7 @string_number = common global [400 x i32] zeroinitializer, align 4
9 ; Function Attrs: nounwind ssp
10 define void @new_position(i32 %pos) {
11 ; CHECK-SD-LABEL: new_position:
12 ; CHECK-SD: ; %bb.0: ; %entry
13 ; CHECK-SD-NEXT: adrp x8, _board@GOTPAGE
14 ; CHECK-SD-NEXT: ; kill: def $w0 killed $w0 def $x0
15 ; CHECK-SD-NEXT: ldr x8, [x8, _board@GOTPAGEOFF]
16 ; CHECK-SD-NEXT: ldrb w8, [x8, w0, sxtw]
17 ; CHECK-SD-NEXT: sub w8, w8, #1
18 ; CHECK-SD-NEXT: cmp w8, #1
19 ; CHECK-SD-NEXT: b.hi LBB0_2
20 ; CHECK-SD-NEXT: ; %bb.1: ; %if.then
21 ; CHECK-SD-NEXT: adrp x8, _next_string@GOTPAGE
22 ; CHECK-SD-NEXT: adrp x9, _string_number@GOTPAGE
23 ; CHECK-SD-NEXT: ldr x8, [x8, _next_string@GOTPAGEOFF]
24 ; CHECK-SD-NEXT: ldr x9, [x9, _string_number@GOTPAGEOFF]
25 ; CHECK-SD-NEXT: ldr w8, [x8]
26 ; CHECK-SD-NEXT: str w8, [x9, w0, sxtw #2]
27 ; CHECK-SD-NEXT: LBB0_2: ; %if.end
30 ; CHECK-GI-LABEL: new_position:
31 ; CHECK-GI: ; %bb.0: ; %entry
32 ; CHECK-GI-NEXT: adrp x8, _board@GOTPAGE
33 ; CHECK-GI-NEXT: ldr x8, [x8, _board@GOTPAGEOFF]
34 ; CHECK-GI-NEXT: ldrb w8, [x8, w0, sxtw]
35 ; CHECK-GI-NEXT: sub w8, w8, #1
36 ; CHECK-GI-NEXT: cmp w8, #2
37 ; CHECK-GI-NEXT: b.hs LBB0_2
38 ; CHECK-GI-NEXT: ; %bb.1: ; %if.then
39 ; CHECK-GI-NEXT: adrp x8, _next_string@GOTPAGE
40 ; CHECK-GI-NEXT: adrp x9, _string_number@GOTPAGE
41 ; CHECK-GI-NEXT: ldr x8, [x8, _next_string@GOTPAGEOFF]
42 ; CHECK-GI-NEXT: ldr x9, [x9, _string_number@GOTPAGEOFF]
43 ; CHECK-GI-NEXT: ldr w8, [x8]
44 ; CHECK-GI-NEXT: str w8, [x9, w0, sxtw #2]
45 ; CHECK-GI-NEXT: LBB0_2: ; %if.end
48 %idxprom = sext i32 %pos to i64
49 %arrayidx = getelementptr inbounds [400 x i8], ptr @board, i64 0, i64 %idxprom
50 %tmp = load i8, ptr %arrayidx, align 1
51 %.off = add i8 %tmp, -1
52 %switch = icmp ult i8 %.off, 2
53 br i1 %switch, label %if.then, label %if.end
55 if.then: ; preds = %entry
56 %tmp1 = load i32, ptr @next_string, align 4
57 %arrayidx8 = getelementptr inbounds [400 x i32], ptr @string_number, i64 0, i64 %idxprom
58 store i32 %tmp1, ptr %arrayidx8, align 4
61 if.end: ; preds = %if.then, %entry
65 define zeroext i1 @test8_0(i8 zeroext %x) align 2 {
66 ; CHECK-LABEL: test8_0:
67 ; CHECK: ; %bb.0: ; %entry
68 ; CHECK-NEXT: add w8, w0, #74
69 ; CHECK-NEXT: and w8, w8, #0xff
70 ; CHECK-NEXT: cmp w8, #236
71 ; CHECK-NEXT: cset w0, lo
75 %1 = icmp ult i8 %0, -20
76 br i1 %1, label %ret_true, label %ret_false
83 define zeroext i1 @test8_1(i8 zeroext %x) align 2 {
84 ; CHECK-SD-LABEL: test8_1:
85 ; CHECK-SD: ; %bb.0: ; %entry
86 ; CHECK-SD-NEXT: sub w8, w0, #10
87 ; CHECK-SD-NEXT: cmp w8, #89
88 ; CHECK-SD-NEXT: cset w0, hi
91 ; CHECK-GI-LABEL: test8_1:
92 ; CHECK-GI: ; %bb.0: ; %entry
93 ; CHECK-GI-NEXT: sub w8, w0, #10
94 ; CHECK-GI-NEXT: cmp w8, #90
95 ; CHECK-GI-NEXT: cset w0, hs
99 %1 = icmp uge i8 %0, 90
100 br i1 %1, label %ret_true, label %ret_false
107 define zeroext i1 @test8_2(i8 zeroext %x) align 2 {
108 ; CHECK-SD-LABEL: test8_2:
109 ; CHECK-SD: ; %bb.0: ; %entry
110 ; CHECK-SD-NEXT: cmp w0, #208
111 ; CHECK-SD-NEXT: cset w0, ne
114 ; CHECK-GI-LABEL: test8_2:
115 ; CHECK-GI: ; %bb.0: ; %entry
116 ; CHECK-GI-NEXT: sub w8, w0, #29
117 ; CHECK-GI-NEXT: and w8, w8, #0xff
118 ; CHECK-GI-NEXT: cmp w8, #179
119 ; CHECK-GI-NEXT: cset w0, ne
123 %1 = icmp ne i8 %0, 179
124 br i1 %1, label %ret_true, label %ret_false
131 define zeroext i1 @test8_3(i8 zeroext %x) align 2 {
132 ; CHECK-SD-LABEL: test8_3:
133 ; CHECK-SD: ; %bb.0: ; %entry
134 ; CHECK-SD-NEXT: cmp w0, #209
135 ; CHECK-SD-NEXT: cset w0, eq
138 ; CHECK-GI-LABEL: test8_3:
139 ; CHECK-GI: ; %bb.0: ; %entry
140 ; CHECK-GI-NEXT: sub w8, w0, #55
141 ; CHECK-GI-NEXT: and w8, w8, #0xff
142 ; CHECK-GI-NEXT: cmp w8, #154
143 ; CHECK-GI-NEXT: cset w0, eq
147 %1 = icmp eq i8 %0, 154
148 br i1 %1, label %ret_true, label %ret_false
155 define zeroext i1 @test8_4(i8 zeroext %x) align 2 {
156 ; CHECK-SD-LABEL: test8_4:
157 ; CHECK-SD: ; %bb.0: ; %entry
158 ; CHECK-SD-NEXT: cmp w0, #39
159 ; CHECK-SD-NEXT: cset w0, ne
162 ; CHECK-GI-LABEL: test8_4:
163 ; CHECK-GI: ; %bb.0: ; %entry
164 ; CHECK-GI-NEXT: sub w8, w0, #79
165 ; CHECK-GI-NEXT: and w8, w8, #0xff
166 ; CHECK-GI-NEXT: cmp w8, #216
167 ; CHECK-GI-NEXT: cset w0, ne
171 %1 = icmp ne i8 %0, -40
172 br i1 %1, label %ret_true, label %ret_false
179 define zeroext i1 @test8_5(i8 zeroext %x) align 2 {
180 ; CHECK-SD-LABEL: test8_5:
181 ; CHECK-SD: ; %bb.0: ; %entry
182 ; CHECK-SD-NEXT: sub w8, w0, #123
183 ; CHECK-SD-NEXT: cmn w8, #106
184 ; CHECK-SD-NEXT: cset w0, hi
187 ; CHECK-GI-LABEL: test8_5:
188 ; CHECK-GI: ; %bb.0: ; %entry
189 ; CHECK-GI-NEXT: sub w8, w0, #123
190 ; CHECK-GI-NEXT: cmn w8, #105
191 ; CHECK-GI-NEXT: cset w0, hs
195 %1 = icmp uge i8 %0, -105
196 br i1 %1, label %ret_true, label %ret_false
203 define zeroext i1 @test8_6(i8 zeroext %x) align 2 {
204 ; CHECK-SD-LABEL: test8_6:
205 ; CHECK-SD: ; %bb.0: ; %entry
206 ; CHECK-SD-NEXT: sub w8, w0, #58
207 ; CHECK-SD-NEXT: cmp w8, #154
208 ; CHECK-SD-NEXT: cset w0, hi
211 ; CHECK-GI-LABEL: test8_6:
212 ; CHECK-GI: ; %bb.0: ; %entry
213 ; CHECK-GI-NEXT: sub w8, w0, #58
214 ; CHECK-GI-NEXT: cmp w8, #155
215 ; CHECK-GI-NEXT: cset w0, hs
219 %1 = icmp uge i8 %0, 155
220 br i1 %1, label %ret_true, label %ret_false
227 define zeroext i1 @test8_7(i8 zeroext %x) align 2 {
228 ; CHECK-LABEL: test8_7:
229 ; CHECK: ; %bb.0: ; %entry
230 ; CHECK-NEXT: sub w8, w0, #31
231 ; CHECK-NEXT: cmp w8, #124
232 ; CHECK-NEXT: cset w0, lo
236 %1 = icmp ult i8 %0, 124
237 br i1 %1, label %ret_true, label %ret_false
246 define zeroext i1 @test8_8(i8 zeroext %x) align 2 {
247 ; CHECK-SD-LABEL: test8_8:
248 ; CHECK-SD: ; %bb.0: ; %entry
249 ; CHECK-SD-NEXT: cmp w0, #66
250 ; CHECK-SD-NEXT: cset w0, ne
253 ; CHECK-GI-LABEL: test8_8:
254 ; CHECK-GI: ; %bb.0: ; %entry
255 ; CHECK-GI-NEXT: sub w8, w0, #66
256 ; CHECK-GI-NEXT: cmp w8, #1
257 ; CHECK-GI-NEXT: cset w0, hs
261 %1 = icmp uge i8 %0, 1
262 br i1 %1, label %ret_true, label %ret_false
269 define zeroext i1 @test16_0(i16 zeroext %x) align 2 {
270 ; CHECK-SD-LABEL: test16_0:
271 ; CHECK-SD: ; %bb.0: ; %entry
272 ; CHECK-SD-NEXT: mov w8, #5086 ; =0x13de
273 ; CHECK-SD-NEXT: cmp w0, w8
274 ; CHECK-SD-NEXT: cset w0, ne
277 ; CHECK-GI-LABEL: test16_0:
278 ; CHECK-GI: ; %bb.0: ; %entry
279 ; CHECK-GI-NEXT: mov w8, #18547 ; =0x4873
280 ; CHECK-GI-NEXT: mov w9, #23633 ; =0x5c51
281 ; CHECK-GI-NEXT: add w8, w0, w8
282 ; CHECK-GI-NEXT: cmp w9, w8, uxth
283 ; CHECK-GI-NEXT: cset w0, ne
286 %0 = add i16 %x, -46989
287 %1 = icmp ne i16 %0, -41903
288 br i1 %1, label %ret_true, label %ret_false
295 define zeroext i1 @test16_2(i16 zeroext %x) align 2 {
296 ; CHECK-SD-LABEL: test16_2:
297 ; CHECK-SD: ; %bb.0: ; %entry
298 ; CHECK-SD-NEXT: mov w8, #16882 ; =0x41f2
299 ; CHECK-SD-NEXT: mov w9, #40700 ; =0x9efc
300 ; CHECK-SD-NEXT: add w8, w0, w8
301 ; CHECK-SD-NEXT: cmp w9, w8, uxth
302 ; CHECK-SD-NEXT: cset w0, hi
305 ; CHECK-GI-LABEL: test16_2:
306 ; CHECK-GI: ; %bb.0: ; %entry
307 ; CHECK-GI-NEXT: mov w8, #16882 ; =0x41f2
308 ; CHECK-GI-NEXT: mov w9, #40699 ; =0x9efb
309 ; CHECK-GI-NEXT: add w8, w0, w8
310 ; CHECK-GI-NEXT: cmp w9, w8, uxth
311 ; CHECK-GI-NEXT: cset w0, hs
314 %0 = add i16 %x, 16882
315 %1 = icmp ule i16 %0, -24837
316 br i1 %1, label %ret_true, label %ret_false
323 define zeroext i1 @test16_3(i16 zeroext %x) align 2 {
324 ; CHECK-SD-LABEL: test16_3:
325 ; CHECK-SD: ; %bb.0: ; %entry
326 ; CHECK-SD-NEXT: mov w8, #53200 ; =0xcfd0
327 ; CHECK-SD-NEXT: cmp w0, w8
328 ; CHECK-SD-NEXT: cset w0, ne
331 ; CHECK-GI-LABEL: test16_3:
332 ; CHECK-GI: ; %bb.0: ; %entry
333 ; CHECK-GI-NEXT: mov w8, #29283 ; =0x7263
334 ; CHECK-GI-NEXT: mov w9, #16947 ; =0x4233
335 ; CHECK-GI-NEXT: add w8, w0, w8
336 ; CHECK-GI-NEXT: cmp w9, w8, uxth
337 ; CHECK-GI-NEXT: cset w0, ne
340 %0 = add i16 %x, 29283
341 %1 = icmp ne i16 %0, 16947
342 br i1 %1, label %ret_true, label %ret_false
349 define zeroext i1 @test16_4(i16 zeroext %x) align 2 {
350 ; CHECK-SD-LABEL: test16_4:
351 ; CHECK-SD: ; %bb.0: ; %entry
352 ; CHECK-SD-NEXT: mov w8, #29985 ; =0x7521
353 ; CHECK-SD-NEXT: mov w9, #15676 ; =0x3d3c
354 ; CHECK-SD-NEXT: add w8, w0, w8
355 ; CHECK-SD-NEXT: cmp w9, w8, uxth
356 ; CHECK-SD-NEXT: cset w0, lo
359 ; CHECK-GI-LABEL: test16_4:
360 ; CHECK-GI: ; %bb.0: ; %entry
361 ; CHECK-GI-NEXT: mov w8, #29985 ; =0x7521
362 ; CHECK-GI-NEXT: mov w9, #15677 ; =0x3d3d
363 ; CHECK-GI-NEXT: add w8, w0, w8
364 ; CHECK-GI-NEXT: cmp w9, w8, uxth
365 ; CHECK-GI-NEXT: cset w0, ls
368 %0 = add i16 %x, -35551
369 %1 = icmp uge i16 %0, 15677
370 br i1 %1, label %ret_true, label %ret_false
377 define zeroext i1 @test16_5(i16 zeroext %x) align 2 {
378 ; CHECK-SD-LABEL: test16_5:
379 ; CHECK-SD: ; %bb.0: ; %entry
380 ; CHECK-SD-NEXT: mov w8, #23282 ; =0x5af2
381 ; CHECK-SD-NEXT: cmp w0, w8
382 ; CHECK-SD-NEXT: cset w0, ne
385 ; CHECK-GI-LABEL: test16_5:
386 ; CHECK-GI: ; %bb.0: ; %entry
387 ; CHECK-GI-NEXT: mov w8, #-25214 ; =0xffff9d82
388 ; CHECK-GI-NEXT: mov w9, #63604 ; =0xf874
389 ; CHECK-GI-NEXT: add w8, w0, w8
390 ; CHECK-GI-NEXT: cmp w9, w8, uxth
391 ; CHECK-GI-NEXT: cset w0, ne
394 %0 = add i16 %x, -25214
395 %1 = icmp ne i16 %0, -1932
396 br i1 %1, label %ret_true, label %ret_false
403 define zeroext i1 @test16_6(i16 zeroext %x) align 2 {
404 ; CHECK-SD-LABEL: test16_6:
405 ; CHECK-SD: ; %bb.0: ; %entry
406 ; CHECK-SD-NEXT: mov w8, #-32194 ; =0xffff823e
407 ; CHECK-SD-NEXT: mov w9, #24320 ; =0x5f00
408 ; CHECK-SD-NEXT: add w8, w0, w8
409 ; CHECK-SD-NEXT: cmp w8, w9
410 ; CHECK-SD-NEXT: cset w0, hi
413 ; CHECK-GI-LABEL: test16_6:
414 ; CHECK-GI: ; %bb.0: ; %entry
415 ; CHECK-GI-NEXT: mov w8, #-32194 ; =0xffff823e
416 ; CHECK-GI-NEXT: mov w9, #24321 ; =0x5f01
417 ; CHECK-GI-NEXT: add w8, w0, w8
418 ; CHECK-GI-NEXT: cmp w8, w9
419 ; CHECK-GI-NEXT: cset w0, hs
422 %0 = add i16 %x, -32194
423 %1 = icmp uge i16 %0, -41215
424 br i1 %1, label %ret_true, label %ret_false
431 define zeroext i1 @test16_7(i16 zeroext %x) align 2 {
432 ; CHECK-SD-LABEL: test16_7:
433 ; CHECK-SD: ; %bb.0: ; %entry
434 ; CHECK-SD-NEXT: mov w8, #9272 ; =0x2438
435 ; CHECK-SD-NEXT: mov w9, #22619 ; =0x585b
436 ; CHECK-SD-NEXT: add w8, w0, w8
437 ; CHECK-SD-NEXT: cmp w9, w8, uxth
438 ; CHECK-SD-NEXT: cset w0, lo
441 ; CHECK-GI-LABEL: test16_7:
442 ; CHECK-GI: ; %bb.0: ; %entry
443 ; CHECK-GI-NEXT: mov w8, #9272 ; =0x2438
444 ; CHECK-GI-NEXT: mov w9, #22620 ; =0x585c
445 ; CHECK-GI-NEXT: add w8, w0, w8
446 ; CHECK-GI-NEXT: cmp w9, w8, uxth
447 ; CHECK-GI-NEXT: cset w0, ls
450 %0 = add i16 %x, 9272
451 %1 = icmp uge i16 %0, -42916
452 br i1 %1, label %ret_true, label %ret_false
459 define zeroext i1 @test16_8(i16 zeroext %x) align 2 {
460 ; CHECK-SD-LABEL: test16_8:
461 ; CHECK-SD: ; %bb.0: ; %entry
462 ; CHECK-SD-NEXT: mov w8, #4919 ; =0x1337
463 ; CHECK-SD-NEXT: cmp w0, w8
464 ; CHECK-SD-NEXT: cset w0, ne
467 ; CHECK-GI-LABEL: test16_8:
468 ; CHECK-GI: ; %bb.0: ; %entry
469 ; CHECK-GI-NEXT: mov w8, #6706 ; =0x1a32
470 ; CHECK-GI-NEXT: add w9, w0, #1787
471 ; CHECK-GI-NEXT: cmp w8, w9, uxth
472 ; CHECK-GI-NEXT: cset w0, ne
475 %0 = add i16 %x, -63749
476 %1 = icmp ne i16 %0, 6706
477 br i1 %1, label %ret_true, label %ret_false
484 define i64 @pr58109(i8 signext %0) {
485 ; CHECK-SD-LABEL: pr58109:
487 ; CHECK-SD-NEXT: add w8, w0, #1
488 ; CHECK-SD-NEXT: and w8, w8, #0xff
489 ; CHECK-SD-NEXT: subs w8, w8, #1
490 ; CHECK-SD-NEXT: csel w0, wzr, w8, lo
493 ; CHECK-GI-LABEL: pr58109:
495 ; CHECK-GI-NEXT: add w8, w0, #1
496 ; CHECK-GI-NEXT: and w8, w8, #0xff
497 ; CHECK-GI-NEXT: sub w8, w8, #1
498 ; CHECK-GI-NEXT: cmp w8, w8, uxtb
499 ; CHECK-GI-NEXT: csel w8, wzr, w8, ne
500 ; CHECK-GI-NEXT: and x0, x8, #0xff
503 %3 = call i8 @llvm.usub.sat.i8(i8 %2, i8 1)
504 %4 = zext i8 %3 to i64
508 define i64 @pr58109b(i8 signext %0, i64 %a, i64 %b) {
509 ; CHECK-SD-LABEL: pr58109b:
511 ; CHECK-SD-NEXT: add w8, w0, #1
512 ; CHECK-SD-NEXT: tst w8, #0xfe
513 ; CHECK-SD-NEXT: csel x0, x1, x2, eq
516 ; CHECK-GI-LABEL: pr58109b:
518 ; CHECK-GI-NEXT: add w8, w0, #1
519 ; CHECK-GI-NEXT: and w8, w8, #0xff
520 ; CHECK-GI-NEXT: cmp w8, #2
521 ; CHECK-GI-NEXT: csel x0, x1, x2, lo
524 %3 = icmp ult i8 %2, 2
525 %4 = select i1 %3, i64 %a, i64 %b
529 declare i8 @llvm.usub.sat.i8(i8, i8) #0