Home | History | Annotate | Download | only in PowerPC
      1 ; RUN: llc -O2 -o - %s | FileCheck %s
      2 target datalayout = "e-m:e-i64:64-n32:64"
      3 target triple = "powerpc64le-grtev4-linux-gnu"
      4 
      5 ; Intended layout:
      6 ; The code for tail-duplication during layout will produce the layout:
      7 ; test1
      8 ; test2
      9 ; body1 (with copy of test2)
     10 ; body2
     11 ; exit
     12 
     13 ;CHECK-LABEL: tail_dup_break_cfg:
     14 ;CHECK: mr [[TAGREG:[0-9]+]], 3
     15 ;CHECK: andi. {{[0-9]+}}, [[TAGREG]], 1
     16 ;CHECK-NEXT: bc 12, 1, [[BODY1LABEL:[._0-9A-Za-z]+]]
     17 ;CHECK-NEXT: # %test2
     18 ;CHECK-NEXT: rlwinm. {{[0-9]+}}, [[TAGREG]], 0, 30, 30
     19 ;CHECK-NEXT: bne 0, [[BODY2LABEL:[._0-9A-Za-z]+]]
     20 ;CHECK: [[EXITLABEL:[._0-9A-Za-z]+]]: # %exit
     21 ;CHECK: blr
     22 ;CHECK-NEXT: [[BODY1LABEL]]
     23 ;CHECK: rlwinm. {{[0-9]+}}, [[TAGREG]], 0, 30, 30
     24 ;CHECK-NEXT: beq 0, [[EXITLABEL]]
     25 ;CHECK-NEXT: [[BODY2LABEL:[._0-9A-Za-z]+]]:
     26 ;CHECK: b [[EXITLABEL]]
     27 define void @tail_dup_break_cfg(i32 %tag) {
     28 entry:
     29   br label %test1
     30 test1:
     31   %tagbit1 = and i32 %tag, 1
     32   %tagbit1eq0 = icmp eq i32 %tagbit1, 0
     33   br i1 %tagbit1eq0, label %test2, label %body1, !prof !1 ; %test2 more likely
     34 body1:
     35   call void @a()
     36   call void @a()
     37   call void @a()
     38   call void @a()
     39   br label %test2
     40 test2:
     41   %tagbit2 = and i32 %tag, 2
     42   %tagbit2eq0 = icmp eq i32 %tagbit2, 0
     43   br i1 %tagbit2eq0, label %exit, label %body2, !prof !1 ; %exit more likely
     44 body2:
     45   call void @b()
     46   call void @b()
     47   call void @b()
     48   call void @b()
     49   br label %exit
     50 exit:
     51   ret void
     52 }
     53 
     54 ; The branch weights here hint that we shouldn't tail duplicate in this case.
     55 ;CHECK-LABEL: tail_dup_dont_break_cfg:
     56 ;CHECK: mr [[TAGREG:[0-9]+]], 3
     57 ;CHECK: andi. {{[0-9]+}}, [[TAGREG]], 1
     58 ;CHECK-NEXT: bc 4, 1, [[TEST2LABEL:[._0-9A-Za-z]+]]
     59 ;CHECK-NEXT: # %body1
     60 ;CHECK: [[TEST2LABEL]]: # %test2
     61 ;CHECK-NEXT: rlwinm. {{[0-9]+}}, [[TAGREG]], 0, 30, 30
     62 ;CHECK-NEXT: beq 0, [[EXITLABEL:[._0-9A-Za-z]+]]
     63 ;CHECK-NEXT: # %body2
     64 ;CHECK: [[EXITLABEL:[._0-9A-Za-z]+]]: # %exit
     65 ;CHECK: blr
     66 define void @tail_dup_dont_break_cfg(i32 %tag) {
     67 entry:
     68   br label %test1
     69 test1:
     70   %tagbit1 = and i32 %tag, 1
     71   %tagbit1eq0 = icmp eq i32 %tagbit1, 0
     72   br i1 %tagbit1eq0, label %test2, label %body1, !prof !1 ; %test2 more likely
     73 body1:
     74   call void @a()
     75   call void @a()
     76   call void @a()
     77   call void @a()
     78   br label %test2
     79 test2:
     80   %tagbit2 = and i32 %tag, 2
     81   %tagbit2eq0 = icmp ne i32 %tagbit2, 0
     82   br i1 %tagbit2eq0, label %body2, label %exit, !prof !3 ; %body2 more likely
     83 body2:
     84   call void @b()
     85   call void @b()
     86   call void @b()
     87   call void @b()
     88   br label %exit
     89 exit:
     90   ret void
     91 }
     92 declare void @a()
     93 declare void @b()
     94 declare void @c()
     95 declare void @d()
     96 
     97 ; This function arranges for the successors of %succ to have already been laid
     98 ; out. When we consider whether to lay out succ after bb and to tail-duplicate
     99 ; it, v and ret have already been placed, so we tail-duplicate as it removes a
    100 ; branch and strictly increases fallthrough
    101 ; CHECK-LABEL: tail_dup_no_succ
    102 ; CHECK: # %entry
    103 ; CHECK: # %v
    104 ; CHECK: # %ret
    105 ; CHECK: # %bb
    106 ; CHECK: # %succ
    107 ; CHECK: # %c
    108 ; CHECK: bl c
    109 ; CHECK: rlwinm. {{[0-9]+}}, {{[0-9]+}}, 0, 29, 29
    110 ; CHECK: beq
    111 ; CHECK: b
    112 define void @tail_dup_no_succ(i32 %tag) {
    113 entry:
    114   %tagbit1 = and i32 %tag, 1
    115   %tagbit1eq0 = icmp eq i32 %tagbit1, 0
    116   br i1 %tagbit1eq0, label %v, label %bb, !prof !2 ; %v very much more likely
    117 bb:
    118   %tagbit2 = and i32 %tag, 2
    119   %tagbit2eq0 = icmp eq i32 %tagbit2, 0
    120   br i1 %tagbit2eq0, label %succ, label %c, !prof !3 ; %succ more likely
    121 c:
    122   call void @c()
    123   call void @c()
    124   br label %succ
    125 succ:
    126   %tagbit3 = and i32 %tag, 4
    127   %tagbit3eq0 = icmp eq i32 %tagbit3, 0
    128   br i1 %tagbit3eq0, label %ret, label %v, !prof !1 ; %u more likely
    129 v:
    130   call void @d()
    131   call void @d()
    132   br label %ret
    133 ret:
    134   ret void
    135 }
    136 
    137 
    138 !1 = !{!"branch_weights", i32 5, i32 3}
    139 !2 = !{!"branch_weights", i32 95, i32 5}
    140 !3 = !{!"branch_weights", i32 8, i32 3}
    141