summaryrefslogtreecommitdiff
path: root/llvm/test/CodeGen/X86/optimize-compare.mir
blob: 042d9a5d438430999c424c9238fd813a598de2f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -o - %s -mtriple=x86_64-- -run-pass peephole-opt | FileCheck %s

---
name: opt_zerocmp_0
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_zerocmp_0
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
    ; CHECK-NEXT: [[XOR32ri:%[0-9]+]]:gr32 = XOR32ri [[COPY]], i32 1234, implicit-def $eflags
    ; CHECK-NEXT: $al = SETCCr 5, implicit $eflags
    %0:gr32 = COPY $esi
    %1:gr32 = XOR32ri %0, i32 1234, implicit-def $eflags
    ; TEST should be removed.
    TEST32rr %1, %1, implicit-def $eflags
    $al = SETCCr 5, implicit $eflags
...
---
name: opt_zerocmp_1
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_zerocmp_1
    ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
    ; CHECK-NEXT: [[DEC64r:%[0-9]+]]:gr64 = DEC64r [[COPY]], implicit-def $eflags
    ; CHECK-NEXT: [[LEA64r:%[0-9]+]]:gr64 = LEA64r [[DEC64r]], 5, $noreg, 12, $noreg
    ; CHECK-NEXT: $al = SETCCr 4, implicit $eflags
    %0:gr64 = COPY $rsi
    %1:gr64 = DEC64r %0, implicit-def $eflags
    ; CMP should be removed.
    CMP64ri8 %1, 0, implicit-def $eflags
    %2:gr64 = LEA64r %1, 5, $noreg, 12, $noreg
    $al = SETCCr 4, implicit $eflags
...
---
name: opt_multiple_blocks
tracksRegLiveness: true
body: |
  ; CHECK-LABEL: name: opt_multiple_blocks
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gr64 = COPY undef $rsi
  ; CHECK-NEXT:   [[INC64r:%[0-9]+]]:gr64 = INC64r [[COPY]], implicit-def $eflags
  ; CHECK-NEXT:   PUSH64r undef $rcx, implicit-def $rsp, implicit $rsp
  ; CHECK-NEXT:   $rcx = POP64r implicit-def $rsp, implicit $rsp
  ; CHECK-NEXT:   JMP_1 %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   liveins: $eflags
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[LEA64r:%[0-9]+]]:gr64 = LEA64r [[INC64r]], 5, $noreg, 12, $noreg
  ; CHECK-NEXT:   $al = SETCCr 4, implicit $eflags
  bb.0:
    %0:gr64 = COPY undef $rsi
    %1:gr64 = INC64r %0, implicit-def $eflags
    PUSH64r undef $rcx, implicit-def $rsp, implicit $rsp
    $rcx = POP64r implicit-def $rsp, implicit $rsp
    JMP_1 %bb.1

  bb.1:
    ; TEST should be removed.
    TEST64rr %1, %1, implicit-def $eflags
    %2:gr64 = LEA64r %1, 5, $noreg, 12, $noreg
    $al = SETCCr 4, implicit $eflags
...
---
name: opt_multiple_blocks_noopt_0
body: |
  ; CHECK-LABEL: name: opt_multiple_blocks_noopt_0
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gr64 = COPY undef $rsi
  ; CHECK-NEXT:   [[INC64r:%[0-9]+]]:gr64 = INC64r [[COPY]], implicit-def $eflags
  ; CHECK-NEXT:   JMP_1 %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   TEST64rr [[INC64r]], [[INC64r]], implicit-def $eflags
  ; CHECK-NEXT:   [[LEA64r:%[0-9]+]]:gr64 = LEA64r [[INC64r]], 5, $noreg, 12, $noreg
  ; CHECK-NEXT:   $al = SETCCr 4, implicit $eflags
  ; CHECK-NEXT:   JCC_1 %bb.1, 2, implicit $eflags
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  bb.0:
    %0:gr64 = COPY undef $rsi
    %1:gr64 = INC64r %0, implicit-def $eflags
    JMP_1 %bb.1

  bb.1:
    ; The TEST64rr should not be removed, since there are multiple preds.
    TEST64rr %1, %1, implicit-def $eflags
    %2:gr64 = LEA64r %1, 5, $noreg, 12, $noreg
    $al = SETCCr 4, implicit $eflags
    JCC_1 %bb.1, 2, implicit $eflags

  bb.2:
...
---
name: opt_multiple_blocks_noopt_1
body: |
  ; CHECK-LABEL: name: opt_multiple_blocks_noopt_1
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   JMP_1 %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gr64 = COPY undef $rsi
  ; CHECK-NEXT:   TEST64rr [[COPY]], [[COPY]], implicit-def $eflags
  ; CHECK-NEXT:   JCC_1 %bb.1, 2, implicit $eflags
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   [[MOV32r0_:%[0-9]+]]:gr32 = MOV32r0 implicit-def $eflags
  ; CHECK-NEXT:   TEST64rr [[COPY]], [[COPY]], implicit-def $eflags
  ; CHECK-NEXT:   $al = SETCCr 4, implicit $eflags
  bb.0:
    JMP_1 %bb.1

  bb.1:
    %0:gr64 = COPY undef $rsi
    TEST64rr %0, %0, implicit-def $eflags
    JCC_1 %bb.1, 2, implicit $eflags

  bb.2:
    ; We should not move MOV32r0 up into the loop (that would be correct but
    ; slow).
    %1:gr32 = MOV32r0 implicit-def $eflags
    ; TEST should not be removed because of MOV32r0.
    TEST64rr %0, %0, implicit-def $eflags
    $al = SETCCr 4, implicit $eflags
...
---
name: opt_zerocmp_user_0
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_zerocmp_user_0
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
    ; CHECK-NEXT: [[NEG32r:%[0-9]+]]:gr32 = NEG32r [[COPY]], implicit-def $eflags
    ; CHECK-NEXT: $al = SETCCr 3, implicit $eflags
    %0:gr32 = COPY $esi
    %1:gr32 = NEG32r %0, implicit-def dead $eflags
    ; TEST should be removed.
    TEST32rr %0, %0, implicit-def $eflags
    $al = SETCCr 4, implicit $eflags
...
---
name: opt_redundant_flags_0
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_0
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[SUB32rr:%[0-9]+]]:gr32 = SUB32rr [[COPY]], [[COPY1]], implicit-def $eflags
    ; CHECK-NEXT: $eax = COPY [[SUB32rr]]
    ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
    %0:gr32 = COPY $esi
    %1:gr32 = COPY $edi
    %2:gr32 = SUB32rr %0, %1, implicit-def dead $eflags
    $eax = COPY %2
    ; CMP should be removed.
    CMP32rr %0, %1, implicit-def $eflags
    $bl = SETCCr 2, implicit $eflags
...
---
name: opt_redundant_flags_1
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_1
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[SUB32rr:%[0-9]+]]:gr32 = SUB32rr [[COPY]], [[COPY1]], implicit-def $eflags
    ; CHECK-NEXT: $eax = COPY [[SUB32rr]]
    ; CHECK-NEXT: $bl = SETCCr 6, implicit $eflags
    %0:gr32 = COPY $esi
    %1:gr32 = COPY $edi
    %2:gr32 = SUB32rr %0, %1, implicit-def dead $eflags
    $eax = COPY %2
    ; CMP should be removed.
    CMP32rr %1, %0, implicit-def $eflags
    $bl = SETCCr 3, implicit $eflags
...
---
name: opt_redundant_flags_2
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_2
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[SUB32rr:%[0-9]+]]:gr32 = SUB32rr [[COPY]], [[COPY1]], implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
    ; CHECK-NEXT: $eax = COPY [[SUB32rr]]
    ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
    %0:gr32 = COPY $esi
    %1:gr32 = COPY $edi
    %2:gr32 = SUB32rr %0, %1, implicit-def $eflags
    ; an extra eflags reader shouldn't stop optimization.
    $cl = SETCCr 2, implicit $eflags
    $eax = COPY %2
    CMP32rr %0, %1, implicit-def $eflags
    $bl = SETCCr 2, implicit $eflags
...
---
name: opt_redundant_flags_cmp_cmp
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_cmp_cmp
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: CMP32rr [[COPY]], [[COPY1]], implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 7, implicit $eflags
    %0:gr32 = COPY $esi
    %1:gr32 = COPY $edi
    CMP32rr %0, %1, implicit-def $eflags
    $cl = SETCCr 2, implicit $eflags
    ; 2nd CMP should be removed.
    CMP32rr %1, %0, implicit-def $eflags
    $bl = SETCCr 2, implicit $eflags
...
---
name: opt_redundant_flags_cmp_cmp_2
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_cmp_cmp_2
    ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr64 = COPY $rdi
    ; CHECK-NEXT: CMP64ri8 [[COPY]], 15, implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
    %0:gr64 = COPY $rsi
    %1:gr64 = COPY $rdi
    CMP64ri8 %0, 15, implicit-def $eflags
    $cl = SETCCr 2, implicit $eflags
    ; 2nd CMP should be removed.
    CMP64ri8 %0, 15, implicit-def $eflags
    $bl = SETCCr 2, implicit $eflags
...
---
name: opt_redundant_flags_test_test
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_test_test
    ; CHECK: [[COPY:%[0-9]+]]:gr16 = COPY $ax
    ; CHECK-NEXT: TEST16rr [[COPY]], [[COPY]], implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
    %0:gr16 = COPY $ax
    TEST16rr %0, %0, implicit-def $eflags
    $cl = SETCCr 2, implicit $eflags
    ; 2nd CMP should be removed.
    TEST16rr %0, %0, implicit-def $eflags
    $bl = SETCCr 2, implicit $eflags
...
---
name: opt_redundant_flags_cmp_sub
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_cmp_sub
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: CMP32rr [[COPY]], [[COPY1]], implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 7, implicit $eflags
    %0:gr32 = COPY $esi
    %1:gr32 = COPY $edi
    CMP32rr %0, %1, implicit-def $eflags
    $cl = SETCCr 2, implicit $eflags
    ; SUB should be removed.
    dead %2:gr32 = SUB32rr %1, %0, implicit-def $eflags
    $bl = SETCCr 2, implicit $eflags
...
---
name: opt_redundant_flags_cmp_sub_2
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_cmp_sub_2
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
    ; CHECK-NEXT: CMP32ri [[COPY]], -12345, implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
    %0:gr32 = COPY $esi
    CMP32ri %0, -12345, implicit-def $eflags
    $cl = SETCCr 2, implicit $eflags
    ; SUB should be removed
    dead %2:gr32 = SUB32ri %0, -12345, implicit-def $eflags
    $bl = SETCCr 2, implicit $eflags
...
---
name: opt_redundant_flags_cmp_sub_noopt
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_cmp_sub_noopt
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: CMP32rr [[COPY]], [[COPY1]], implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
    ; CHECK-NEXT: [[SUB32rr:%[0-9]+]]:gr32 = SUB32rr [[COPY]], [[COPY1]], implicit-def $eflags
    ; CHECK-NEXT: $rdx = COPY [[SUB32rr]]
    ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
    %0:gr32 = COPY $esi
    %1:gr32 = COPY $edi
    CMP32rr %0, %1, implicit-def $eflags
    $cl = SETCCr 2, implicit $eflags
    ; cannot optimize the SUB because the result value is used.
    %2:gr32 = SUB32rr %0, %1, implicit-def $eflags
    $rdx = COPY %2
    $bl = SETCCr 2, implicit $eflags
...
---
name: opt_redundant_flags_cmp_test
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_cmp_test
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
    ; CHECK-NEXT: CMP32ri8 [[COPY]], 0, implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
    %0:gr32 = COPY $esi
    CMP32ri8 %0, 0, implicit-def $eflags
    $cl = SETCCr 2, implicit $eflags
    ; TEST should be removed
    TEST32rr %0, %0, implicit-def $eflags
    $bl = SETCCr 2, implicit $eflags
...
---
name: opt_redundant_flags_test_cmp
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_test_cmp
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
    ; CHECK-NEXT: TEST32rr [[COPY]], [[COPY]], implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
    %0:gr32 = COPY $esi
    TEST32rr %0, %0, implicit-def $eflags
    $cl = SETCCr 2, implicit $eflags
    ; TEST should be removed
    CMP32ri8 %0, 0, implicit-def $eflags
    $bl = SETCCr 2, implicit $eflags
...
---
name: opt_redundant_flags_cmp_addr
stack:
  - { id: 0, size: 4, alignment: 4 }
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_cmp_addr
    ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
    ; CHECK-NEXT: CMP64ri32 [[COPY]], @opt_redundant_flags_cmp_addr + 4, implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 7, implicit $eflags
    ; CHECK-NEXT: $cl = SETCCr 3, implicit $eflags
    %0:gr64 = COPY $rsi
    CMP64ri32 %0, @opt_redundant_flags_cmp_addr + 4, implicit-def $eflags
    $cl = SETCCr 7, implicit $eflags
    ; CMP should be removed
    CMP64ri32 %0, @opt_redundant_flags_cmp_addr + 4, implicit-def $eflags
    $cl = SETCCr 3, implicit $eflags
...
---
name: opt_redundant_flags_cmp_addr_noopt
stack:
  - { id: 0, size: 4, alignment: 4 }
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_cmp_addr_noopt
    ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
    ; CHECK-NEXT: CMP64ri32 [[COPY]], @opt_redundant_flags_cmp_addr_noopt + 24, implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 7, implicit $eflags
    ; CHECK-NEXT: CMP64ri32 [[COPY]], 24, implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 3, implicit $eflags
    %0:gr64 = COPY $rsi
    CMP64ri32 %0, @opt_redundant_flags_cmp_addr_noopt + 24, implicit-def $eflags
    $cl = SETCCr 7, implicit $eflags
    ; CMP should not be removed
    CMP64ri32 %0, 24, implicit-def $eflags
    $cl = SETCCr 3, implicit $eflags
...
---
name: opt_redundant_flags_adjusted_imm_0
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_0
    ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
    ; CHECK-NEXT: CMP64ri8 [[COPY]], 1, implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 4, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 15, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 7, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 14, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 6, implicit $eflags
    %0:gr64 = COPY $rsi
    ; CMP+SETCC   %0 == 1
    CMP64ri8 %0, 1, implicit-def $eflags
    $cl = SETCCr 4, implicit $eflags
    ; CMP+SETCC   %0 >= 2; CMP can be removed.
    CMP64ri8 %0, 2, implicit-def $eflags
    ; %0 >=s 2  -->  %0 >s 1
    $bl = SETCCr 13, implicit $eflags
    ; %0 >=u 2  -->  %0 >u 1
    $bl = SETCCr 3, implicit $eflags
    ; %0 <s 2  -->  %0 <=s 1
    $bl = SETCCr 12, implicit $eflags
    ; %0 <u 2  -->  %0 <=u 1
    $bl = SETCCr 2, implicit $eflags
...
---
name: opt_redundant_flags_adjusted_imm_1
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_1
    ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
    ; CHECK-NEXT: CMP64ri8 [[COPY]], 42, implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 5, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 13, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 3, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 12, implicit $eflags
    ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
    %0:gr64 = COPY $rsi
    ; CMP+SETCC   %0 != 42
    CMP64ri8 %0, 42, implicit-def $eflags
    $cl = SETCCr 5, implicit $eflags
    ; CMP+SETCC   %0 >= 2; CMP can be removed.
    CMP64ri8 %0, 41, implicit-def $eflags
    ; %0 >s 41  -->  %0 >=s 42
    $bl = SETCCr 15, implicit $eflags
    ; %0 >u 41  -->  %0 >=u 42
    $bl = SETCCr 7, implicit $eflags
    ; %0 <=s 41  -->  %0 <s 42
    $bl = SETCCr 14, implicit $eflags
    ; %0 <=u 41  -->  %0 <u 42
    $bl = SETCCr 6, implicit $eflags
...
---
name: opt_redundant_flags_adjusted_imm_test_cmp
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_test_cmp
    ; CHECK: [[COPY:%[0-9]+]]:gr8 = COPY $bl
    ; CHECK-NEXT: TEST8rr [[COPY]], [[COPY]], implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 14, implicit $eflags
    ; CHECK-NEXT: $cl = SETCCr 7, implicit $eflags
    ; CHECK-NEXT: $cl = SETCCr 12, implicit $eflags
    %0:gr8 = COPY $bl
    TEST8rr %0, %0, implicit-def $eflags
    ; SET %0 <=s 0
    $cl = SETCCr 14, implicit $eflags
    ; CMP should be removed (%0 >=u 1)
    CMP8ri %0, 1, implicit-def $eflags
    $cl = SETCCr 3, implicit $eflags

    ; CMP should be removed (%0 <=s -1)
    CMP8ri %0, -1, implicit-def $eflags
    $cl = SETCCr 14, implicit $eflags
...
---
name: opt_redundant_flags_adjusted_imm_cmp_test
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_cmp_test
    ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
    ; CHECK-NEXT: CMP64ri32 [[COPY]], 1, implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 13, implicit $eflags
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr64 = COPY $edi
    ; CHECK-NEXT: CMP64ri32 [[COPY1]], -1, implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 14, implicit $eflags
    %0:gr64 = COPY $rsi
    CMP64ri32 %0, 1, implicit-def $eflags
    ; TEST should be removed
    TEST64rr %0, %0, implicit-def $eflags
    $cl = SETCCr 15, implicit $eflags

    %1:gr64 = COPY $edi
    CMP64ri32 %1, -1, implicit-def $eflags
    ; TEST should be removed
    TEST64rr %1, %1, implicit-def $eflags
    $cl = SETCCr 12, implicit $eflags
...
---
name: opt_redundant_flags_adjusted_imm_noopt_0
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_noopt_0
    ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
    ; CHECK-NEXT: CMP64ri8 [[COPY]], 42, implicit-def $eflags
    ; CHECK-NEXT: $cl = SETCCr 4, implicit $eflags
    ; CHECK-NEXT: CMP64ri8 [[COPY]], 41, implicit-def $eflags
    ; CHECK-NEXT: $bl = SETCCr 4, implicit $eflags
    %0:gr64 = COPY $rsi
    ; CMP+SETCC   %0 <s 1
    CMP64ri8 %0, 42, implicit-def $eflags
    $cl = SETCCr 4, implicit $eflags
    ; CMP should not be removed.
    CMP64ri8 %0, 41, implicit-def $eflags
    ; %0 == 41
    $bl = SETCCr 4, implicit $eflags
...
---
name: opt_redundant_flags_adjusted_imm_noopt_1
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_noopt_1
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
    ; CHECK-NEXT: CMP32ri [[COPY]], 2147483647, implicit-def $eflags
    ; CHECK-NEXT: CMP32ri [[COPY]], -2147483648, implicit-def $eflags
    ; CHECK-NEXT: $bl = SETCCr 12, implicit $eflags
    ; CHECK-NEXT: CMP32ri [[COPY]], 4294967295, implicit-def $eflags
    ; CHECK-NEXT: CMP32ri [[COPY]], -2147483648, implicit-def $eflags
    ; CHECK-NEXT: $bl = SETCCr 12, implicit $eflags
    ; CHECK-NEXT: CMP32ri [[COPY]], 2147483647, implicit-def $eflags
    ; CHECK-NEXT: CMP32ri [[COPY]], -2147483648, implicit-def $eflags
    ; CHECK-NEXT: $bl = SETCCr 13, implicit $eflags
    ; CHECK-NEXT: CMP32ri [[COPY]], 4294967295, implicit-def $eflags
    ; CHECK-NEXT: CMP32ri [[COPY]], 0, implicit-def $eflags
    ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
    ; CHECK-NEXT: CMP32ri [[COPY]], 4294967295, implicit-def $eflags
    ; CHECK-NEXT: CMP32ri [[COPY]], 0, implicit-def $eflags
    ; CHECK-NEXT: $bl = SETCCr 3, implicit $eflags
    %0:gr32 = COPY $esi
    ; CMP+SETCC   %0 == INT32_MAX
    CMP32ri %0, 2147483647, implicit-def $eflags
    ; CMP should not be removed.
    CMP32ri %0, -2147483648, implicit-def $eflags
    ; %0 <s INT32_MIN
    $bl = SETCCr 12, implicit $eflags

    CMP32ri %0, 4294967295, implicit-def $eflags
    ; CMP should not be removed.
    CMP32ri %0, -2147483648, implicit-def $eflags
    $bl = SETCCr 12, implicit $eflags

    CMP32ri %0, 2147483647, implicit-def $eflags
    ; CMP should not be removed.
    CMP32ri %0, -2147483648, implicit-def $eflags
    $bl = SETCCr 13, implicit $eflags

    CMP32ri %0, 4294967295, implicit-def $eflags
    ; should not be removed
    CMP32ri %0, 0, implicit-def $eflags
    $bl = SETCCr 2, implicit $eflags

    CMP32ri %0, 4294967295, implicit-def $eflags
    ; should not be removed
    CMP32ri %0, 0, implicit-def $eflags
    $bl = SETCCr 3, implicit $eflags
...
---
name: opt_redundant_flags_adjusted_imm_noopt_2
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_noopt_2
    ; CHECK: [[COPY:%[0-9]+]]:gr16 = COPY $cx
    ; CHECK-NEXT: CMP16ri [[COPY]], -32768, implicit-def $eflags
    ; CHECK-NEXT: CMP16ri [[COPY]], 32767, implicit-def $eflags
    ; CHECK-NEXT: $bl = SETCCr 15, implicit $eflags
    ; CHECK-NEXT: CMP16ri [[COPY]], 65535, implicit-def $eflags
    ; CHECK-NEXT: CMP16ri [[COPY]], 32767, implicit-def $eflags
    ; CHECK-NEXT: $bl = SETCCr 15, implicit $eflags
    ; CHECK-NEXT: CMP16ri [[COPY]], -32768, implicit-def $eflags
    ; CHECK-NEXT: CMP16ri [[COPY]], 32767, implicit-def $eflags
    ; CHECK-NEXT: $bl = SETCCr 14, implicit $eflags
    ; CHECK-NEXT: CMP16ri [[COPY]], 0, implicit-def $eflags
    ; CHECK-NEXT: CMP16ri [[COPY]], 65535, implicit-def $eflags
    ; CHECK-NEXT: $bl = SETCCr 4, implicit $eflags
    ; CHECK-NEXT: CMP16ri [[COPY]], 0, implicit-def $eflags
    ; CHECK-NEXT: CMP16ri [[COPY]], 65535, implicit-def $eflags
    ; CHECK-NEXT: $bl = SETCCr 6, implicit $eflags
    %0:gr16 = COPY $cx
    ; CMP+SETCC   %0 == INT16_MIN
    CMP16ri %0, -32768, implicit-def $eflags
    ; CMP should not be removed.
    CMP16ri %0, 32767, implicit-def $eflags
    ; %0 >s INT16_MAX
    $bl = SETCCr 15, implicit $eflags

    CMP16ri %0, 65535, implicit-def $eflags
    ; CMP should not be removed.
    CMP16ri %0, 32767, implicit-def $eflags
    $bl = SETCCr 15, implicit $eflags

    CMP16ri %0, -32768, implicit-def $eflags
    ; CMP should not be removed.
    CMP16ri %0, 32767, implicit-def $eflags
    $bl = SETCCr 14, implicit $eflags

    CMP16ri %0, 0, implicit-def $eflags
    ; should not be removed
    CMP16ri %0, 65535, implicit-def $eflags
    $bl = SETCCr 4, implicit $eflags

    CMP16ri %0, 0, implicit-def $eflags
    ; should not be removed
    CMP16ri %0, 65535, implicit-def $eflags
    $bl = SETCCr 6, implicit $eflags
...
---
name: opt_adjusted_imm_multiple_blocks
body: |
  ; CHECK-LABEL: name: opt_adjusted_imm_multiple_blocks
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.3(0x40000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gr32 = COPY $eax
  ; CHECK-NEXT:   CMP32ri [[COPY]], 20, implicit-def $eflags
  ; CHECK-NEXT:   JCC_1 %bb.1, 4, implicit $eflags
  ; CHECK-NEXT:   JMP_1 %bb.3
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.2(0x40000000), %bb.3(0x40000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   JCC_1 %bb.2, 15, implicit $eflags
  ; CHECK-NEXT:   JMP_1 %bb.3
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   JMP_1 %bb.3
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.3:
  ; CHECK-NEXT:   RET 0
  bb.0:
    %0:gr32 = COPY $eax
    CMP32ri %0, 20, implicit-def $eflags
    JCC_1 %bb.1, 4, implicit $eflags
    JMP_1 %bb.3

  bb.1:
    ; CMP can be removed when adjusting the JCC.
    CMP32ri %0, 21, implicit-def $eflags
    JCC_1 %bb.2, 13, implicit $eflags
    JMP_1 %bb.3

  bb.2:
    JMP_1 %bb.3

  bb.3:
    RET 0
...
---
name: opt_adjusted_imm_multiple_blocks_noopt
body: |
  ; CHECK-LABEL: name: opt_adjusted_imm_multiple_blocks_noopt
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.3(0x40000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gr32 = COPY $eax
  ; CHECK-NEXT:   CMP32ri [[COPY]], 20, implicit-def $eflags
  ; CHECK-NEXT:   JCC_1 %bb.1, 4, implicit $eflags
  ; CHECK-NEXT:   JMP_1 %bb.3
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.2(0x40000000), %bb.3(0x40000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   CMP32ri [[COPY]], 21, implicit-def $eflags
  ; CHECK-NEXT:   JCC_1 %bb.2, 13, implicit $eflags
  ; CHECK-NEXT:   JMP_1 %bb.3
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   $al = SETCCr 4, implicit $eflags
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.3:
  ; CHECK-NEXT:   RET 0
  bb.0:
    %0:gr32 = COPY $eax
    CMP32ri %0, 20, implicit-def $eflags
    JCC_1 %bb.1, 4, implicit $eflags
    JMP_1 %bb.3

  bb.1:
    ; The following CMP should not be optimized because $eflags is live-out
    CMP32ri %0, 21, implicit-def $eflags
    JCC_1 %bb.2, 13, implicit $eflags
    JMP_1 %bb.3

  bb.2:
    liveins: $eflags
    $al = SETCCr 4, implicit $eflags

  bb.3:
    RET 0
...
---
name: opt_shift_cmp_zero
body: |
  bb.0:
    ; CHECK-LABEL: name: opt_shift_cmp_zero
    ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
    ; CHECK-NEXT: [[SHL64ri:%[0-9]+]]:gr64 = SHL64ri [[COPY]], 7, implicit-def $eflags
    ; CHECK-NEXT: $al = SETCCr 4, implicit $eflags
    %0:gr64 = COPY $rsi
    %1:gr64 = SHL64ri %0, 7, implicit-def dead $eflags
    ; TEST should be removed.
    TEST64rr %1, %1, implicit-def $eflags
    $al = SETCCr 4, implicit $eflags
...
---
name: noopt_shift_cmp_zero
body: |
  bb.0:
    ; CHECK-LABEL: name: noopt_shift_cmp_zero
    ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
    ; CHECK-NEXT: [[SHL64ri:%[0-9]+]]:gr64 = SHL64ri [[COPY]], 9, implicit-def dead $eflags
    ; CHECK-NEXT: TEST64rr [[SHL64ri]], [[SHL64ri]], implicit-def $eflags
    ; CHECK-NEXT: $al = SETCCr 14, implicit $eflags
    %0:gr64 = COPY $rsi
    %1:gr64 = SHL64ri %0, 9, implicit-def dead $eflags
    ; TEST cannot be removed if a user relies on the OF flag.
    TEST64rr %1, %1, implicit-def $eflags
    $al = SETCCr 14, implicit $eflags
...
---
name: noopt_shift_cmp_zero_multiblock
body: |
  ; CHECK-LABEL: name: noopt_shift_cmp_zero_multiblock
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gr64 = COPY $rsi
  ; CHECK-NEXT:   [[SHL64ri:%[0-9]+]]:gr64 = SHL64ri [[COPY]], 9, implicit-def dead $eflags
  ; CHECK-NEXT:   TEST64rr [[SHL64ri]], [[SHL64ri]], implicit-def $eflags
  ; CHECK-NEXT:   JMP_1 %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   $al = SETCCr 14, implicit $eflags
  bb.0:
    %0:gr64 = COPY $rsi
    %1:gr64 = SHL64ri %0, 9, implicit-def dead $eflags
    ; TEST cannot be removed if a user relies on the OF flag.
    TEST64rr %1, %1, implicit-def $eflags
    JMP_1 %bb.1

  bb.1:
    liveins: $eflags
    $al = SETCCr 14, implicit $eflags
...