1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 # RUN: llc -o - %s -mtriple=x86_64-- -run-pass peephole-opt | FileCheck %s
8 ; CHECK-LABEL: name: opt_zerocmp_0
9 ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
10 ; CHECK-NEXT: [[XOR32ri:%[0-9]+]]:gr32 = XOR32ri [[COPY]], i32 1234, implicit-def $eflags
11 ; CHECK-NEXT: $al = SETCCr 5, implicit $eflags
13 %1:gr32 = XOR32ri %0, i32 1234, implicit-def $eflags
14 ; TEST should be removed.
15 TEST32rr %1, %1, implicit-def $eflags
16 $al = SETCCr 5, implicit $eflags
22 ; CHECK-LABEL: name: opt_zerocmp_1
23 ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
24 ; CHECK-NEXT: [[DEC64r:%[0-9]+]]:gr64 = DEC64r [[COPY]], implicit-def $eflags
25 ; CHECK-NEXT: [[LEA64r:%[0-9]+]]:gr64 = LEA64r [[DEC64r]], 5, $noreg, 12, $noreg
26 ; CHECK-NEXT: $al = SETCCr 4, implicit $eflags
28 %1:gr64 = DEC64r %0, implicit-def $eflags
29 ; CMP should be removed.
30 CMP64ri32 %1, 0, implicit-def $eflags
31 %2:gr64 = LEA64r %1, 5, $noreg, 12, $noreg
32 $al = SETCCr 4, implicit $eflags
35 name: opt_multiple_blocks
36 tracksRegLiveness: true
38 ; CHECK-LABEL: name: opt_multiple_blocks
40 ; CHECK-NEXT: successors: %bb.1(0x80000000)
42 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr64 = COPY undef $rsi
43 ; CHECK-NEXT: [[INC64r:%[0-9]+]]:gr64 = INC64r [[COPY]], implicit-def $eflags
44 ; CHECK-NEXT: PUSH64r undef $rcx, implicit-def $rsp, implicit $rsp
45 ; CHECK-NEXT: $rcx = POP64r implicit-def $rsp, implicit $rsp
46 ; CHECK-NEXT: JMP_1 %bb.1
49 ; CHECK-NEXT: liveins: $eflags
51 ; CHECK-NEXT: [[LEA64r:%[0-9]+]]:gr64 = LEA64r [[INC64r]], 5, $noreg, 12, $noreg
52 ; CHECK-NEXT: $al = SETCCr 4, implicit $eflags
54 %0:gr64 = COPY undef $rsi
55 %1:gr64 = INC64r %0, implicit-def $eflags
56 PUSH64r undef $rcx, implicit-def $rsp, implicit $rsp
57 $rcx = POP64r implicit-def $rsp, implicit $rsp
61 ; TEST should be removed.
62 TEST64rr %1, %1, implicit-def $eflags
63 %2:gr64 = LEA64r %1, 5, $noreg, 12, $noreg
64 $al = SETCCr 4, implicit $eflags
67 name: opt_multiple_blocks_noopt_0
69 ; CHECK-LABEL: name: opt_multiple_blocks_noopt_0
71 ; CHECK-NEXT: successors: %bb.1(0x80000000)
73 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr64 = COPY undef $rsi
74 ; CHECK-NEXT: [[INC64r:%[0-9]+]]:gr64 = INC64r [[COPY]], implicit-def $eflags
75 ; CHECK-NEXT: JMP_1 %bb.1
78 ; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
80 ; CHECK-NEXT: TEST64rr [[INC64r]], [[INC64r]], implicit-def $eflags
81 ; CHECK-NEXT: [[LEA64r:%[0-9]+]]:gr64 = LEA64r [[INC64r]], 5, $noreg, 12, $noreg
82 ; CHECK-NEXT: $al = SETCCr 4, implicit $eflags
83 ; CHECK-NEXT: JCC_1 %bb.1, 2, implicit $eflags
87 %0:gr64 = COPY undef $rsi
88 %1:gr64 = INC64r %0, implicit-def $eflags
92 ; The TEST64rr should not be removed, since there are multiple preds.
93 TEST64rr %1, %1, implicit-def $eflags
94 %2:gr64 = LEA64r %1, 5, $noreg, 12, $noreg
95 $al = SETCCr 4, implicit $eflags
96 JCC_1 %bb.1, 2, implicit $eflags
101 name: opt_multiple_blocks_noopt_1
103 ; CHECK-LABEL: name: opt_multiple_blocks_noopt_1
105 ; CHECK-NEXT: successors: %bb.1(0x80000000)
107 ; CHECK-NEXT: JMP_1 %bb.1
110 ; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
112 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr64 = COPY undef $rsi
113 ; CHECK-NEXT: TEST64rr [[COPY]], [[COPY]], implicit-def $eflags
114 ; CHECK-NEXT: JCC_1 %bb.1, 2, implicit $eflags
117 ; CHECK-NEXT: [[MOV32r0_:%[0-9]+]]:gr32 = MOV32r0 implicit-def $eflags
118 ; CHECK-NEXT: TEST64rr [[COPY]], [[COPY]], implicit-def $eflags
119 ; CHECK-NEXT: $al = SETCCr 4, implicit $eflags
124 %0:gr64 = COPY undef $rsi
125 TEST64rr %0, %0, implicit-def $eflags
126 JCC_1 %bb.1, 2, implicit $eflags
129 ; We should not move MOV32r0 up into the loop (that would be correct but
131 %1:gr32 = MOV32r0 implicit-def $eflags
132 ; TEST should not be removed because of MOV32r0.
133 TEST64rr %0, %0, implicit-def $eflags
134 $al = SETCCr 4, implicit $eflags
137 name: opt_zerocmp_user_0
140 ; CHECK-LABEL: name: opt_zerocmp_user_0
141 ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
142 ; CHECK-NEXT: [[NEG32r:%[0-9]+]]:gr32 = NEG32r [[COPY]], implicit-def $eflags
143 ; CHECK-NEXT: $al = SETCCr 3, implicit $eflags
145 %1:gr32 = NEG32r %0, implicit-def dead $eflags
146 ; TEST should be removed.
147 TEST32rr %0, %0, implicit-def $eflags
148 $al = SETCCr 4, implicit $eflags
151 name: opt_redundant_flags_0
154 ; CHECK-LABEL: name: opt_redundant_flags_0
155 ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
156 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
157 ; CHECK-NEXT: [[SUB32rr:%[0-9]+]]:gr32 = SUB32rr [[COPY]], [[COPY1]], implicit-def $eflags
158 ; CHECK-NEXT: $eax = COPY [[SUB32rr]]
159 ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
162 %2:gr32 = SUB32rr %0, %1, implicit-def dead $eflags
164 ; CMP should be removed.
165 CMP32rr %0, %1, implicit-def $eflags
166 $bl = SETCCr 2, implicit $eflags
169 name: opt_redundant_flags_1
172 ; CHECK-LABEL: name: opt_redundant_flags_1
173 ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
174 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
175 ; CHECK-NEXT: [[SUB32rr:%[0-9]+]]:gr32 = SUB32rr [[COPY]], [[COPY1]], implicit-def $eflags
176 ; CHECK-NEXT: $eax = COPY [[SUB32rr]]
177 ; CHECK-NEXT: $bl = SETCCr 6, implicit $eflags
180 %2:gr32 = SUB32rr %0, %1, implicit-def dead $eflags
182 ; CMP should be removed.
183 CMP32rr %1, %0, implicit-def $eflags
184 $bl = SETCCr 3, implicit $eflags
187 name: opt_redundant_flags_2
190 ; CHECK-LABEL: name: opt_redundant_flags_2
191 ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
192 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
193 ; CHECK-NEXT: [[SUB32rr:%[0-9]+]]:gr32 = SUB32rr [[COPY]], [[COPY1]], implicit-def $eflags
194 ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
195 ; CHECK-NEXT: $eax = COPY [[SUB32rr]]
196 ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
199 %2:gr32 = SUB32rr %0, %1, implicit-def $eflags
200 ; an extra eflags reader shouldn't stop optimization.
201 $cl = SETCCr 2, implicit $eflags
203 CMP32rr %0, %1, implicit-def $eflags
204 $bl = SETCCr 2, implicit $eflags
207 name: opt_redundant_flags_cmp_cmp
210 ; CHECK-LABEL: name: opt_redundant_flags_cmp_cmp
211 ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
212 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
213 ; CHECK-NEXT: CMP32rr [[COPY]], [[COPY1]], implicit-def $eflags
214 ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
215 ; CHECK-NEXT: $bl = SETCCr 7, implicit $eflags
218 CMP32rr %0, %1, implicit-def $eflags
219 $cl = SETCCr 2, implicit $eflags
220 ; 2nd CMP should be removed.
221 CMP32rr %1, %0, implicit-def $eflags
222 $bl = SETCCr 2, implicit $eflags
225 name: opt_redundant_flags_cmp_cmp_2
228 ; CHECK-LABEL: name: opt_redundant_flags_cmp_cmp_2
229 ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
230 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr64 = COPY $rdi
231 ; CHECK-NEXT: CMP64ri32 [[COPY]], 15, implicit-def $eflags
232 ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
233 ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
236 CMP64ri32 %0, 15, implicit-def $eflags
237 $cl = SETCCr 2, implicit $eflags
238 ; 2nd CMP should be removed.
239 CMP64ri32 %0, 15, implicit-def $eflags
240 $bl = SETCCr 2, implicit $eflags
243 name: opt_redundant_flags_test_test
246 ; CHECK-LABEL: name: opt_redundant_flags_test_test
247 ; CHECK: [[COPY:%[0-9]+]]:gr16 = COPY $ax
248 ; CHECK-NEXT: TEST16rr [[COPY]], [[COPY]], implicit-def $eflags
249 ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
250 ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
252 TEST16rr %0, %0, implicit-def $eflags
253 $cl = SETCCr 2, implicit $eflags
254 ; 2nd CMP should be removed.
255 TEST16rr %0, %0, implicit-def $eflags
256 $bl = SETCCr 2, implicit $eflags
259 name: opt_redundant_flags_cmp_sub
262 ; CHECK-LABEL: name: opt_redundant_flags_cmp_sub
263 ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
264 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
265 ; CHECK-NEXT: CMP32rr [[COPY]], [[COPY1]], implicit-def $eflags
266 ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
267 ; CHECK-NEXT: $bl = SETCCr 7, implicit $eflags
270 CMP32rr %0, %1, implicit-def $eflags
271 $cl = SETCCr 2, implicit $eflags
272 ; SUB should be removed.
273 dead %2:gr32 = SUB32rr %1, %0, implicit-def $eflags
274 $bl = SETCCr 2, implicit $eflags
277 name: opt_redundant_flags_cmp_sub_2
280 ; CHECK-LABEL: name: opt_redundant_flags_cmp_sub_2
281 ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
282 ; CHECK-NEXT: CMP32ri [[COPY]], -12345, implicit-def $eflags
283 ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
284 ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
286 CMP32ri %0, -12345, implicit-def $eflags
287 $cl = SETCCr 2, implicit $eflags
288 ; SUB should be removed
289 dead %2:gr32 = SUB32ri %0, -12345, implicit-def $eflags
290 $bl = SETCCr 2, implicit $eflags
293 name: opt_redundant_flags_cmp_sub_noopt
296 ; CHECK-LABEL: name: opt_redundant_flags_cmp_sub_noopt
297 ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
298 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr32 = COPY $edi
299 ; CHECK-NEXT: CMP32rr [[COPY]], [[COPY1]], implicit-def $eflags
300 ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
301 ; CHECK-NEXT: [[SUB32rr:%[0-9]+]]:gr32 = SUB32rr [[COPY]], [[COPY1]], implicit-def $eflags
302 ; CHECK-NEXT: $rdx = COPY [[SUB32rr]]
303 ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
306 CMP32rr %0, %1, implicit-def $eflags
307 $cl = SETCCr 2, implicit $eflags
308 ; cannot optimize the SUB because the result value is used.
309 %2:gr32 = SUB32rr %0, %1, implicit-def $eflags
311 $bl = SETCCr 2, implicit $eflags
314 name: opt_redundant_flags_cmp_test
317 ; CHECK-LABEL: name: opt_redundant_flags_cmp_test
318 ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
319 ; CHECK-NEXT: CMP32ri [[COPY]], 0, implicit-def $eflags
320 ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
321 ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
323 CMP32ri %0, 0, implicit-def $eflags
324 $cl = SETCCr 2, implicit $eflags
325 ; TEST should be removed
326 TEST32rr %0, %0, implicit-def $eflags
327 $bl = SETCCr 2, implicit $eflags
330 name: opt_redundant_flags_test_cmp
333 ; CHECK-LABEL: name: opt_redundant_flags_test_cmp
334 ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
335 ; CHECK-NEXT: TEST32rr [[COPY]], [[COPY]], implicit-def $eflags
336 ; CHECK-NEXT: $cl = SETCCr 2, implicit $eflags
337 ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
339 TEST32rr %0, %0, implicit-def $eflags
340 $cl = SETCCr 2, implicit $eflags
341 ; TEST should be removed
342 CMP32ri %0, 0, implicit-def $eflags
343 $bl = SETCCr 2, implicit $eflags
346 name: opt_redundant_flags_cmp_addr
348 - { id: 0, size: 4, alignment: 4 }
351 ; CHECK-LABEL: name: opt_redundant_flags_cmp_addr
352 ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
353 ; CHECK-NEXT: CMP64ri32 [[COPY]], @opt_redundant_flags_cmp_addr + 4, implicit-def $eflags
354 ; CHECK-NEXT: $cl = SETCCr 7, implicit $eflags
355 ; CHECK-NEXT: $cl = SETCCr 3, implicit $eflags
357 CMP64ri32 %0, @opt_redundant_flags_cmp_addr + 4, implicit-def $eflags
358 $cl = SETCCr 7, implicit $eflags
359 ; CMP should be removed
360 CMP64ri32 %0, @opt_redundant_flags_cmp_addr + 4, implicit-def $eflags
361 $cl = SETCCr 3, implicit $eflags
364 name: opt_redundant_flags_cmp_addr_noopt
366 - { id: 0, size: 4, alignment: 4 }
369 ; CHECK-LABEL: name: opt_redundant_flags_cmp_addr_noopt
370 ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
371 ; CHECK-NEXT: CMP64ri32 [[COPY]], @opt_redundant_flags_cmp_addr_noopt + 24, implicit-def $eflags
372 ; CHECK-NEXT: $cl = SETCCr 7, implicit $eflags
373 ; CHECK-NEXT: CMP64ri32 [[COPY]], 24, implicit-def $eflags
374 ; CHECK-NEXT: $cl = SETCCr 3, implicit $eflags
376 CMP64ri32 %0, @opt_redundant_flags_cmp_addr_noopt + 24, implicit-def $eflags
377 $cl = SETCCr 7, implicit $eflags
378 ; CMP should not be removed
379 CMP64ri32 %0, 24, implicit-def $eflags
380 $cl = SETCCr 3, implicit $eflags
383 name: opt_redundant_flags_adjusted_imm_0
386 ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_0
387 ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
388 ; CHECK-NEXT: CMP64ri32 [[COPY]], 1, implicit-def $eflags
389 ; CHECK-NEXT: $cl = SETCCr 4, implicit $eflags
390 ; CHECK-NEXT: $bl = SETCCr 15, implicit $eflags
391 ; CHECK-NEXT: $bl = SETCCr 7, implicit $eflags
392 ; CHECK-NEXT: $bl = SETCCr 14, implicit $eflags
393 ; CHECK-NEXT: $bl = SETCCr 6, implicit $eflags
396 CMP64ri32 %0, 1, implicit-def $eflags
397 $cl = SETCCr 4, implicit $eflags
398 ; CMP+SETCC %0 >= 2; CMP can be removed.
399 CMP64ri32 %0, 2, implicit-def $eflags
400 ; %0 >=s 2 --> %0 >s 1
401 $bl = SETCCr 13, implicit $eflags
402 ; %0 >=u 2 --> %0 >u 1
403 $bl = SETCCr 3, implicit $eflags
404 ; %0 <s 2 --> %0 <=s 1
405 $bl = SETCCr 12, implicit $eflags
406 ; %0 <u 2 --> %0 <=u 1
407 $bl = SETCCr 2, implicit $eflags
410 name: opt_redundant_flags_adjusted_imm_1
413 ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_1
414 ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
415 ; CHECK-NEXT: CMP64ri32 [[COPY]], 42, implicit-def $eflags
416 ; CHECK-NEXT: $cl = SETCCr 5, implicit $eflags
417 ; CHECK-NEXT: $bl = SETCCr 13, implicit $eflags
418 ; CHECK-NEXT: $bl = SETCCr 3, implicit $eflags
419 ; CHECK-NEXT: $bl = SETCCr 12, implicit $eflags
420 ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
423 CMP64ri32 %0, 42, implicit-def $eflags
424 $cl = SETCCr 5, implicit $eflags
425 ; CMP+SETCC %0 >= 2; CMP can be removed.
426 CMP64ri32 %0, 41, implicit-def $eflags
427 ; %0 >s 41 --> %0 >=s 42
428 $bl = SETCCr 15, implicit $eflags
429 ; %0 >u 41 --> %0 >=u 42
430 $bl = SETCCr 7, implicit $eflags
431 ; %0 <=s 41 --> %0 <s 42
432 $bl = SETCCr 14, implicit $eflags
433 ; %0 <=u 41 --> %0 <u 42
434 $bl = SETCCr 6, implicit $eflags
437 name: opt_redundant_flags_adjusted_imm_test_cmp
440 ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_test_cmp
441 ; CHECK: [[COPY:%[0-9]+]]:gr8 = COPY $bl
442 ; CHECK-NEXT: TEST8rr [[COPY]], [[COPY]], implicit-def $eflags
443 ; CHECK-NEXT: $cl = SETCCr 14, implicit $eflags
444 ; CHECK-NEXT: $cl = SETCCr 7, implicit $eflags
445 ; CHECK-NEXT: $cl = SETCCr 12, implicit $eflags
447 TEST8rr %0, %0, implicit-def $eflags
449 $cl = SETCCr 14, implicit $eflags
450 ; CMP should be removed (%0 >=u 1)
451 CMP8ri %0, 1, implicit-def $eflags
452 $cl = SETCCr 3, implicit $eflags
454 ; CMP should be removed (%0 <=s -1)
455 CMP8ri %0, -1, implicit-def $eflags
456 $cl = SETCCr 14, implicit $eflags
459 name: opt_redundant_flags_adjusted_imm_cmp_test
462 ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_cmp_test
463 ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
464 ; CHECK-NEXT: CMP64ri32 [[COPY]], 1, implicit-def $eflags
465 ; CHECK-NEXT: $cl = SETCCr 13, implicit $eflags
466 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr64 = COPY $edi
467 ; CHECK-NEXT: CMP64ri32 [[COPY1]], -1, implicit-def $eflags
468 ; CHECK-NEXT: $cl = SETCCr 14, implicit $eflags
470 CMP64ri32 %0, 1, implicit-def $eflags
471 ; TEST should be removed
472 TEST64rr %0, %0, implicit-def $eflags
473 $cl = SETCCr 15, implicit $eflags
476 CMP64ri32 %1, -1, implicit-def $eflags
477 ; TEST should be removed
478 TEST64rr %1, %1, implicit-def $eflags
479 $cl = SETCCr 12, implicit $eflags
482 name: opt_redundant_flags_adjusted_imm_noopt_0
485 ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_noopt_0
486 ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
487 ; CHECK-NEXT: CMP64ri32 [[COPY]], 42, implicit-def $eflags
488 ; CHECK-NEXT: $cl = SETCCr 4, implicit $eflags
489 ; CHECK-NEXT: CMP64ri32 [[COPY]], 41, implicit-def $eflags
490 ; CHECK-NEXT: $bl = SETCCr 4, implicit $eflags
493 CMP64ri32 %0, 42, implicit-def $eflags
494 $cl = SETCCr 4, implicit $eflags
495 ; CMP should not be removed.
496 CMP64ri32 %0, 41, implicit-def $eflags
498 $bl = SETCCr 4, implicit $eflags
501 name: opt_redundant_flags_adjusted_imm_noopt_1
504 ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_noopt_1
505 ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $esi
506 ; CHECK-NEXT: CMP32ri [[COPY]], 2147483647, implicit-def $eflags
507 ; CHECK-NEXT: CMP32ri [[COPY]], -2147483648, implicit-def $eflags
508 ; CHECK-NEXT: $bl = SETCCr 12, implicit $eflags
509 ; CHECK-NEXT: CMP32ri [[COPY]], 4294967295, implicit-def $eflags
510 ; CHECK-NEXT: CMP32ri [[COPY]], -2147483648, implicit-def $eflags
511 ; CHECK-NEXT: $bl = SETCCr 12, implicit $eflags
512 ; CHECK-NEXT: CMP32ri [[COPY]], 2147483647, implicit-def $eflags
513 ; CHECK-NEXT: CMP32ri [[COPY]], -2147483648, implicit-def $eflags
514 ; CHECK-NEXT: $bl = SETCCr 13, implicit $eflags
515 ; CHECK-NEXT: CMP32ri [[COPY]], 4294967295, implicit-def $eflags
516 ; CHECK-NEXT: CMP32ri [[COPY]], 0, implicit-def $eflags
517 ; CHECK-NEXT: $bl = SETCCr 2, implicit $eflags
518 ; CHECK-NEXT: CMP32ri [[COPY]], 4294967295, implicit-def $eflags
519 ; CHECK-NEXT: CMP32ri [[COPY]], 0, implicit-def $eflags
520 ; CHECK-NEXT: $bl = SETCCr 3, implicit $eflags
522 ; CMP+SETCC %0 == INT32_MAX
523 CMP32ri %0, 2147483647, implicit-def $eflags
524 ; CMP should not be removed.
525 CMP32ri %0, -2147483648, implicit-def $eflags
527 $bl = SETCCr 12, implicit $eflags
529 CMP32ri %0, 4294967295, implicit-def $eflags
530 ; CMP should not be removed.
531 CMP32ri %0, -2147483648, implicit-def $eflags
532 $bl = SETCCr 12, implicit $eflags
534 CMP32ri %0, 2147483647, implicit-def $eflags
535 ; CMP should not be removed.
536 CMP32ri %0, -2147483648, implicit-def $eflags
537 $bl = SETCCr 13, implicit $eflags
539 CMP32ri %0, 4294967295, implicit-def $eflags
540 ; should not be removed
541 CMP32ri %0, 0, implicit-def $eflags
542 $bl = SETCCr 2, implicit $eflags
544 CMP32ri %0, 4294967295, implicit-def $eflags
545 ; should not be removed
546 CMP32ri %0, 0, implicit-def $eflags
547 $bl = SETCCr 3, implicit $eflags
550 name: opt_redundant_flags_adjusted_imm_noopt_2
553 ; CHECK-LABEL: name: opt_redundant_flags_adjusted_imm_noopt_2
554 ; CHECK: [[COPY:%[0-9]+]]:gr16 = COPY $cx
555 ; CHECK-NEXT: CMP16ri [[COPY]], -32768, implicit-def $eflags
556 ; CHECK-NEXT: CMP16ri [[COPY]], 32767, implicit-def $eflags
557 ; CHECK-NEXT: $bl = SETCCr 15, implicit $eflags
558 ; CHECK-NEXT: CMP16ri [[COPY]], 65535, implicit-def $eflags
559 ; CHECK-NEXT: CMP16ri [[COPY]], 32767, implicit-def $eflags
560 ; CHECK-NEXT: $bl = SETCCr 15, implicit $eflags
561 ; CHECK-NEXT: CMP16ri [[COPY]], -32768, implicit-def $eflags
562 ; CHECK-NEXT: CMP16ri [[COPY]], 32767, implicit-def $eflags
563 ; CHECK-NEXT: $bl = SETCCr 14, implicit $eflags
564 ; CHECK-NEXT: CMP16ri [[COPY]], 0, implicit-def $eflags
565 ; CHECK-NEXT: CMP16ri [[COPY]], 65535, implicit-def $eflags
566 ; CHECK-NEXT: $bl = SETCCr 4, implicit $eflags
567 ; CHECK-NEXT: CMP16ri [[COPY]], 0, implicit-def $eflags
568 ; CHECK-NEXT: CMP16ri [[COPY]], 65535, implicit-def $eflags
569 ; CHECK-NEXT: $bl = SETCCr 6, implicit $eflags
571 ; CMP+SETCC %0 == INT16_MIN
572 CMP16ri %0, -32768, implicit-def $eflags
573 ; CMP should not be removed.
574 CMP16ri %0, 32767, implicit-def $eflags
576 $bl = SETCCr 15, implicit $eflags
578 CMP16ri %0, 65535, implicit-def $eflags
579 ; CMP should not be removed.
580 CMP16ri %0, 32767, implicit-def $eflags
581 $bl = SETCCr 15, implicit $eflags
583 CMP16ri %0, -32768, implicit-def $eflags
584 ; CMP should not be removed.
585 CMP16ri %0, 32767, implicit-def $eflags
586 $bl = SETCCr 14, implicit $eflags
588 CMP16ri %0, 0, implicit-def $eflags
589 ; should not be removed
590 CMP16ri %0, 65535, implicit-def $eflags
591 $bl = SETCCr 4, implicit $eflags
593 CMP16ri %0, 0, implicit-def $eflags
594 ; should not be removed
595 CMP16ri %0, 65535, implicit-def $eflags
596 $bl = SETCCr 6, implicit $eflags
599 name: opt_adjusted_imm_multiple_blocks
601 ; CHECK-LABEL: name: opt_adjusted_imm_multiple_blocks
603 ; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.3(0x40000000)
605 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $eax
606 ; CHECK-NEXT: CMP32ri [[COPY]], 20, implicit-def $eflags
607 ; CHECK-NEXT: JCC_1 %bb.1, 4, implicit $eflags
608 ; CHECK-NEXT: JMP_1 %bb.3
611 ; CHECK-NEXT: successors: %bb.2(0x40000000), %bb.3(0x40000000)
612 ; CHECK-NEXT: liveins: $eflags
614 ; CHECK-NEXT: JCC_1 %bb.2, 15, implicit $eflags
615 ; CHECK-NEXT: JMP_1 %bb.3
618 ; CHECK-NEXT: successors: %bb.3(0x80000000)
620 ; CHECK-NEXT: JMP_1 %bb.3
626 CMP32ri %0, 20, implicit-def $eflags
627 JCC_1 %bb.1, 4, implicit $eflags
631 ; CMP can be removed when adjusting the JCC.
632 CMP32ri %0, 21, implicit-def $eflags
633 JCC_1 %bb.2, 13, implicit $eflags
643 name: opt_adjusted_imm_multiple_blocks_noopt
645 ; CHECK-LABEL: name: opt_adjusted_imm_multiple_blocks_noopt
647 ; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.3(0x40000000)
649 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $eax
650 ; CHECK-NEXT: CMP32ri [[COPY]], 20, implicit-def $eflags
651 ; CHECK-NEXT: JCC_1 %bb.1, 4, implicit $eflags
652 ; CHECK-NEXT: JMP_1 %bb.3
655 ; CHECK-NEXT: successors: %bb.2(0x40000000), %bb.3(0x40000000)
657 ; CHECK-NEXT: CMP32ri [[COPY]], 21, implicit-def $eflags
658 ; CHECK-NEXT: JCC_1 %bb.2, 13, implicit $eflags
659 ; CHECK-NEXT: JMP_1 %bb.3
662 ; CHECK-NEXT: successors: %bb.3(0x80000000)
663 ; CHECK-NEXT: liveins: $eflags
665 ; CHECK-NEXT: $al = SETCCr 4, implicit $eflags
671 CMP32ri %0, 20, implicit-def $eflags
672 JCC_1 %bb.1, 4, implicit $eflags
676 ; The following CMP should not be optimized because $eflags is live-out
677 CMP32ri %0, 21, implicit-def $eflags
678 JCC_1 %bb.2, 13, implicit $eflags
683 $al = SETCCr 4, implicit $eflags
689 name: opt_shift_cmp_zero
692 ; CHECK-LABEL: name: opt_shift_cmp_zero
693 ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
694 ; CHECK-NEXT: [[SHL64ri:%[0-9]+]]:gr64 = SHL64ri [[COPY]], 7, implicit-def $eflags
695 ; CHECK-NEXT: $al = SETCCr 4, implicit $eflags
697 %1:gr64 = SHL64ri %0, 7, implicit-def dead $eflags
698 ; TEST should be removed.
699 TEST64rr %1, %1, implicit-def $eflags
700 $al = SETCCr 4, implicit $eflags
703 name: noopt_shift_cmp_zero
706 ; CHECK-LABEL: name: noopt_shift_cmp_zero
707 ; CHECK: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
708 ; CHECK-NEXT: [[SHL64ri:%[0-9]+]]:gr64 = SHL64ri [[COPY]], 9, implicit-def dead $eflags
709 ; CHECK-NEXT: TEST64rr [[SHL64ri]], [[SHL64ri]], implicit-def $eflags
710 ; CHECK-NEXT: $al = SETCCr 14, implicit $eflags
712 %1:gr64 = SHL64ri %0, 9, implicit-def dead $eflags
713 ; TEST cannot be removed if a user relies on the OF flag.
714 TEST64rr %1, %1, implicit-def $eflags
715 $al = SETCCr 14, implicit $eflags
718 name: noopt_shift_cmp_zero_multiblock
720 ; CHECK-LABEL: name: noopt_shift_cmp_zero_multiblock
722 ; CHECK-NEXT: successors: %bb.1(0x80000000)
724 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr64 = COPY $rsi
725 ; CHECK-NEXT: [[SHL64ri:%[0-9]+]]:gr64 = SHL64ri [[COPY]], 9, implicit-def dead $eflags
726 ; CHECK-NEXT: TEST64rr [[SHL64ri]], [[SHL64ri]], implicit-def $eflags
727 ; CHECK-NEXT: JMP_1 %bb.1
730 ; CHECK-NEXT: liveins: $eflags
732 ; CHECK-NEXT: $al = SETCCr 14, implicit $eflags
735 %1:gr64 = SHL64ri %0, 9, implicit-def dead $eflags
736 ; TEST cannot be removed if a user relies on the OF flag.
737 TEST64rr %1, %1, implicit-def $eflags
742 $al = SETCCr 14, implicit $eflags