1 # RUN: llc -run-pass=peephole-opt %s -o - | FileCheck %s
3 # Test the compare fold peephole.
5 # CHECK-LABEL: name: test0a
6 # TODO: Enhance combiner to handle this case. This expands into:
9 # sel.eq $r18, $r3, $rv
10 # This is different from the pattern currently matched. If the lowered form had
11 # been sub.f $r3, 0, $r0 then it would have matched.
13 # CHECK-LABEL: name: test1a
14 # CHECK: [[IN1:%.*]]:gpr = COPY $r7
15 # CHECK: [[IN2:%.*]]:gpr = COPY $r6
16 # CHECK: SUB_F_R [[IN1]], [[IN2]], 0, implicit-def $sr
18 # CHECK-LABEL: name: test1b
19 # CHECK: [[IN1:%.*]]:gpr = COPY $r7
20 # CHECK: [[IN2:%.*]]:gpr = COPY $r6
21 # CHECK: SUB_F_R [[IN1]], [[IN2]], 0, implicit-def $sr
23 # CHECK-LABEL: name: test2a
24 # CHECK: [[IN1:%.*]]:gpr = COPY $r7
25 # CHECK: [[IN2:%.*]]:gpr = COPY $r6
26 # CHECK: SUB_F_R [[IN1]], [[IN2]], 0, implicit-def $sr
28 # CHECK-LABEL: name: test2b
29 # CHECK: [[IN1:%.*]]:gpr = COPY $r7
30 # CHECK: [[IN2:%.*]]:gpr = COPY $r6
31 # CHECK: SUB_F_R [[IN1]], [[IN2]], 0, implicit-def $sr
33 # CHECK-LABEL: name: test3
39 target datalayout = "E-m:e-p:32:32-i64:64-a:0:32-n32-S64"
40 target triple = "lanai-unknown-unknown"
42 @a = global i32 -1, align 4
43 @b = global i32 0, align 4
45 define i32 @test0a(i32 inreg %a, i32 inreg %b, i32 inreg %c, i32 inreg %d) {
48 %cmp = icmp eq i32 %sub, 0
49 %cond = select i1 %cmp, i32 %c, i32 %sub
53 define i32 @test0b(i32 inreg %a, i32 inreg %b, i32 inreg %c, i32 inreg %d) {
55 %cmp = icmp eq i32 %b, %a
56 %cond = select i1 %cmp, i32 %c, i32 %b
60 define i32 @test1a(i32 inreg %a, i32 inreg %b, i32 inreg %c, i32 inreg %d) {
63 %cmp = icmp slt i32 %sub, 0
64 %cond = select i1 %cmp, i32 %c, i32 %d
68 define i32 @test1b(i32 inreg %a, i32 inreg %b, i32 inreg %c, i32 inreg %d) {
71 %cmp = icmp slt i32 %sub, 0
72 %cond = select i1 %cmp, i32 %c, i32 %d
76 define i32 @test2a(i32 inreg %a, i32 inreg %b, i32 inreg %c, i32 inreg %d) {
79 %cmp = icmp sgt i32 %sub, -1
80 %cond = select i1 %cmp, i32 %c, i32 %d
84 define i32 @test2b(i32 inreg %a, i32 inreg %b, i32 inreg %c, i32 inreg %d) {
87 %cmp = icmp sgt i32 %sub, -1
88 %cond = select i1 %cmp, i32 %c, i32 %d
92 define i32 @test3(i32 inreg %a, i32 inreg %b, i32 inreg %c, i32 inreg %d) {
95 %cmp = icmp slt i32 %sub, 1
96 %cond = select i1 %cmp, i32 %c, i32 %d
100 define i32 @test4(i32 inreg %a, i32 inreg %b, i32 inreg %c, i32 inreg %d) {
102 %cmp = icmp ne i32 %a, 0
103 %cmp1 = icmp ult i32 %a, %b
104 %or.cond = and i1 %cmp, %cmp1
105 br i1 %or.cond, label %return, label %if.end
107 if.end: ; preds = %entry
108 %cmp2 = icmp ne i32 %b, 0
109 %cmp4 = icmp ult i32 %b, %c
110 %or.cond29 = and i1 %cmp2, %cmp4
111 br i1 %or.cond29, label %return, label %if.end6
113 if.end6: ; preds = %if.end
114 %cmp7 = icmp ne i32 %c, 0
115 %cmp9 = icmp ult i32 %c, %d
116 %or.cond30 = and i1 %cmp7, %cmp9
117 br i1 %or.cond30, label %return, label %if.end11
119 if.end11: ; preds = %if.end6
120 %cmp12 = icmp ne i32 %d, 0
121 %cmp14 = icmp ult i32 %d, %a
122 %or.cond31 = and i1 %cmp12, %cmp14
123 %b. = select i1 %or.cond31, i32 %b, i32 21
126 return: ; preds = %if.end6, %if.end, %entry
127 %retval.0 = phi i32 [ %c, %entry ], [ %d, %if.end ], [ %a, %if.end6 ]
131 define void @testBB() {
133 %0 = load i32, i32* @a, align 4, !tbaa !0
134 %1 = load i32, i32* @b, align 4, !tbaa !0
135 %sub.i = sub i32 %1, %0
136 %tobool = icmp sgt i32 %sub.i, -1
137 br i1 %tobool, label %if.end, label %if.then
139 if.then: ; preds = %entry
140 %call1 = tail call i32 bitcast (i32 (...)* @g to i32 ()*)()
143 while.body: ; preds = %while.body, %if.then
146 if.end: ; preds = %entry
147 %cmp.i = icmp slt i32 %sub.i, 1
148 br i1 %cmp.i, label %if.then4, label %if.end7
150 if.then4: ; preds = %if.end
151 %call5 = tail call i32 bitcast (i32 (...)* @g to i32 ()*)()
152 br label %while.body6
154 while.body6: ; preds = %while.body6, %if.then4
155 br label %while.body6
157 if.end7: ; preds = %if.end
163 ; Function Attrs: nounwind
164 declare void @llvm.stackprotector(i8*, i8**) #0
166 attributes #0 = { nounwind }
168 !0 = !{!1, !1, i64 0}
169 !1 = !{!"int", !2, i64 0}
170 !2 = !{!"omnipotent char", !3, i64 0}
171 !3 = !{!"Simple C/C++ TBAA"}
177 exposesReturnsTwice: false
178 tracksRegLiveness: true
180 - { id: 0, class: gpr }
181 - { id: 1, class: gpr }
182 - { id: 2, class: gpr }
183 - { id: 3, class: gpr }
184 - { id: 4, class: gpr }
185 - { id: 5, class: gpr }
187 - { reg: '$r6', virtual-reg: '%0' }
188 - { reg: '$r7', virtual-reg: '%1' }
189 - { reg: '$r18', virtual-reg: '%2' }
191 isFrameAddressTaken: false
192 isReturnAddressTaken: false
201 hasOpaqueSPAdjustment: false
203 hasMustTailInVarArgFunc: false
206 liveins: $r6, $r7, $r18
212 SFSUB_F_RI_LO %4, 0, implicit-def $sr
213 %5 = SELECT %2, %4, 7, implicit $sr
215 RET implicit $rca, implicit $rv
221 exposesReturnsTwice: false
222 tracksRegLiveness: true
224 - { id: 0, class: gpr }
225 - { id: 1, class: gpr }
226 - { id: 2, class: gpr }
227 - { id: 3, class: gpr }
228 - { id: 4, class: gpr }
230 - { reg: '$r6', virtual-reg: '%0' }
231 - { reg: '$r7', virtual-reg: '%1' }
232 - { reg: '$r18', virtual-reg: '%2' }
234 isFrameAddressTaken: false
235 isReturnAddressTaken: false
244 hasOpaqueSPAdjustment: false
246 hasMustTailInVarArgFunc: false
249 liveins: $r6, $r7, $r18
254 SFSUB_F_RR %1, %0, implicit-def $sr
255 %4 = SELECT %2, %1, 7, implicit $sr
257 RET implicit $rca, implicit $rv
263 exposesReturnsTwice: false
264 tracksRegLiveness: true
266 - { id: 0, class: gpr }
267 - { id: 1, class: gpr }
268 - { id: 2, class: gpr }
269 - { id: 3, class: gpr }
270 - { id: 4, class: gpr }
271 - { id: 5, class: gpr }
273 - { reg: '$r6', virtual-reg: '%0' }
274 - { reg: '$r7', virtual-reg: '%1' }
275 - { reg: '$r18', virtual-reg: '%2' }
276 - { reg: '$r19', virtual-reg: '%3' }
278 isFrameAddressTaken: false
279 isReturnAddressTaken: false
288 hasOpaqueSPAdjustment: false
290 hasMustTailInVarArgFunc: false
293 liveins: $r6, $r7, $r18, $r19
300 SFSUB_F_RI_LO killed %4, 0, implicit-def $sr
301 %5 = SELECT %2, %3, 11, implicit $sr
303 RET implicit $rca, implicit $rv
309 exposesReturnsTwice: false
310 tracksRegLiveness: true
312 - { id: 0, class: gpr }
313 - { id: 1, class: gpr }
314 - { id: 2, class: gpr }
315 - { id: 3, class: gpr }
316 - { id: 4, class: gpr }
317 - { id: 5, class: gpr }
319 - { reg: '$r6', virtual-reg: '%0' }
320 - { reg: '$r7', virtual-reg: '%1' }
321 - { reg: '$r18', virtual-reg: '%2' }
322 - { reg: '$r19', virtual-reg: '%3' }
324 isFrameAddressTaken: false
325 isReturnAddressTaken: false
334 hasOpaqueSPAdjustment: false
336 hasMustTailInVarArgFunc: false
339 liveins: $r6, $r7, $r18, $r19
346 SFSUB_F_RI_LO killed %4, 0, implicit-def $sr
347 %5 = SELECT %2, %3, 11, implicit $sr
349 RET implicit $rca, implicit $rv
355 exposesReturnsTwice: false
356 tracksRegLiveness: true
358 - { id: 0, class: gpr }
359 - { id: 1, class: gpr }
360 - { id: 2, class: gpr }
361 - { id: 3, class: gpr }
362 - { id: 4, class: gpr }
363 - { id: 5, class: gpr }
365 - { reg: '$r6', virtual-reg: '%0' }
366 - { reg: '$r7', virtual-reg: '%1' }
367 - { reg: '$r18', virtual-reg: '%2' }
368 - { reg: '$r19', virtual-reg: '%3' }
370 isFrameAddressTaken: false
371 isReturnAddressTaken: false
380 hasOpaqueSPAdjustment: false
382 hasMustTailInVarArgFunc: false
385 liveins: $r6, $r7, $r18, $r19
392 SFSUB_F_RI_LO killed %4, 0, implicit-def $sr
393 %5 = SELECT %2, %3, 10, implicit $sr
395 RET implicit $rca, implicit $rv
401 exposesReturnsTwice: false
402 tracksRegLiveness: true
404 - { id: 0, class: gpr }
405 - { id: 1, class: gpr }
406 - { id: 2, class: gpr }
407 - { id: 3, class: gpr }
408 - { id: 4, class: gpr }
409 - { id: 5, class: gpr }
411 - { reg: '$r6', virtual-reg: '%0' }
412 - { reg: '$r7', virtual-reg: '%1' }
413 - { reg: '$r18', virtual-reg: '%2' }
414 - { reg: '$r19', virtual-reg: '%3' }
416 isFrameAddressTaken: false
417 isReturnAddressTaken: false
426 hasOpaqueSPAdjustment: false
428 hasMustTailInVarArgFunc: false
431 liveins: $r6, $r7, $r18, $r19
438 SFSUB_F_RI_LO killed %4, 0, implicit-def $sr
439 %5 = SELECT %2, %3, 10, implicit $sr
441 RET implicit $rca, implicit $rv
447 exposesReturnsTwice: false
448 tracksRegLiveness: true
450 - { id: 0, class: gpr }
451 - { id: 1, class: gpr }
452 - { id: 2, class: gpr }
453 - { id: 3, class: gpr }
454 - { id: 4, class: gpr }
455 - { id: 5, class: gpr }
457 - { reg: '$r6', virtual-reg: '%0' }
458 - { reg: '$r7', virtual-reg: '%1' }
459 - { reg: '$r18', virtual-reg: '%2' }
460 - { reg: '$r19', virtual-reg: '%3' }
462 isFrameAddressTaken: false
463 isReturnAddressTaken: false
472 hasOpaqueSPAdjustment: false
474 hasMustTailInVarArgFunc: false
477 liveins: $r6, $r7, $r18, $r19
484 SFSUB_F_RI_LO killed %4, 1, implicit-def $sr
485 %5 = SELECT %2, %3, 13, implicit $sr
487 RET implicit $rca, implicit $rv
493 exposesReturnsTwice: false
494 tracksRegLiveness: true
496 - { id: 0, class: gpr }
497 - { id: 1, class: gpr }
498 - { id: 2, class: gpr }
499 - { id: 3, class: gpr }
500 - { id: 4, class: gpr }
501 - { id: 5, class: gpr }
502 - { id: 6, class: gpr }
503 - { id: 7, class: gpr }
504 - { id: 8, class: gpr }
505 - { id: 9, class: gpr }
506 - { id: 10, class: gpr }
507 - { id: 11, class: gpr }
508 - { id: 12, class: gpr }
509 - { id: 13, class: gpr }
510 - { id: 14, class: gpr }
511 - { id: 15, class: gpr }
512 - { id: 16, class: gpr }
513 - { id: 17, class: gpr }
514 - { id: 18, class: gpr }
515 - { id: 19, class: gpr }
516 - { id: 20, class: gpr }
517 - { id: 21, class: gpr }
518 - { id: 22, class: gpr }
520 - { reg: '$r6', virtual-reg: '%1' }
521 - { reg: '$r7', virtual-reg: '%2' }
522 - { reg: '$r18', virtual-reg: '%3' }
523 - { reg: '$r19', virtual-reg: '%4' }
525 isFrameAddressTaken: false
526 isReturnAddressTaken: false
535 hasOpaqueSPAdjustment: false
537 hasMustTailInVarArgFunc: false
540 successors: %bb.4.return, %bb.1.if.end
541 liveins: $r6, $r7, $r18, $r19
547 SFSUB_F_RI_LO %1, 0, implicit-def $sr
548 %5 = SCC 6, implicit $sr
549 SFSUB_F_RR %1, %2, implicit-def $sr
550 %6 = SCC 4, implicit $sr
551 %7 = AND_R killed %5, killed %6, 0
553 %9 = AND_R killed %7, %8, 0
554 SFSUB_F_RI_LO killed %9, 0, implicit-def $sr
555 BRCC %bb.4.return, 6, implicit $sr
559 successors: %bb.4.return, %bb.2.if.end6
561 SFSUB_F_RI_LO %2, 0, implicit-def $sr
562 %10 = SCC 6, implicit $sr
563 SFSUB_F_RR %2, %3, implicit-def $sr
564 %11 = SCC 4, implicit $sr
565 %12 = AND_R killed %10, killed %11, 0
566 %14 = AND_R killed %12, %8, 0
567 SFSUB_F_RI_LO killed %14, 0, implicit-def $sr
568 BRCC %bb.4.return, 6, implicit $sr
572 successors: %bb.4.return, %bb.3.if.end11
574 SFSUB_F_RI_LO %3, 0, implicit-def $sr
575 %15 = SCC 6, implicit $sr
576 SFSUB_F_RR %3, %4, implicit-def $sr
577 %16 = SCC 4, implicit $sr
578 %17 = AND_R killed %15, killed %16, 0
580 %19 = AND_R killed %17, killed %18, 0
581 SFSUB_F_RI_LO killed %19, 0, implicit-def $sr
582 BRCC %bb.4.return, 6, implicit $sr
587 SFSUB_F_RR %4, %1, implicit-def $sr
588 %21 = SELECT %2, %20, 4, implicit $sr
589 SFSUB_F_RI_LO %4, 0, implicit-def $sr
590 %22 = SELECT killed %21, %20, 6, implicit $sr
592 RET implicit $rca, implicit $rv
595 %0 = PHI %3, %bb.0.entry, %4, %bb.1.if.end, %1, %bb.2.if.end6
597 RET implicit $rca, implicit $rv
603 exposesReturnsTwice: false
604 tracksRegLiveness: true
606 - { id: 0, class: gpr }
607 - { id: 1, class: gpr }
608 - { id: 2, class: gpr }
609 - { id: 3, class: gpr }
610 - { id: 4, class: gpr }
611 - { id: 5, class: gpr }
612 - { id: 6, class: gpr }
613 - { id: 7, class: gpr }
614 - { id: 8, class: gpr }
616 isFrameAddressTaken: false
617 isReturnAddressTaken: false
626 hasOpaqueSPAdjustment: false
628 hasMustTailInVarArgFunc: false
631 successors: %bb.3.if.end, %bb.1.if.then
633 %1 = MOVHI target-flags(lanai-hi) @a
634 %2 = OR_I_LO killed %1, target-flags(lanai-lo) @a
635 %3 = LDW_RI killed %2, 0, 0 :: (load (s32) from @a, !tbaa !0)
636 %4 = MOVHI target-flags(lanai-hi) @b
637 %5 = OR_I_LO killed %4, target-flags(lanai-lo) @b
638 %6 = LDW_RI killed %5, 0, 0 :: (load (s32) from @b, !tbaa !0)
639 %0 = SUB_R killed %6, killed %3, 0
640 SFSUB_F_RI_LO %0, 0, implicit-def $sr
641 BRCC %bb.3.if.end, 10, implicit $sr
645 successors: %bb.2.while.body
647 ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp
648 CALL @g, csr, implicit-def dead $rca, implicit $sp, implicit-def $sp, implicit-def $rv
649 ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp
652 successors: %bb.2.while.body
657 successors: %bb.4.if.then4, %bb.6.if.end7
660 BRCC %bb.6.if.end7, 14, implicit $sr
664 successors: %bb.5.while.body6
666 ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp
667 CALL @g, csr, implicit-def dead $rca, implicit $sp, implicit-def $sp, implicit-def $rv
668 ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp
671 successors: %bb.5.while.body6