Home | History | Annotate | Download | only in SimplifyCFG
      1 ; RUN: opt -S < %s -simplifycfg -simplifycfg-merge-cond-stores=true -simplifycfg-merge-cond-stores-aggressively=false -phi-node-folding-threshold=2 | FileCheck %s
      2 
      3 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
      4 target triple = "armv7--linux-gnueabihf"
      5 
      6 ; This is a bit reversal that has been run through the early optimizer (-mem2reg -gvn -instcombine).
      7 ; There should be no additional PHIs created at all. The store should be on its own in a predicated
      8 ; block and there should be no PHIs.
      9 
     10 ; CHECK-LABEL: @f
     11 ; Exactly 15 phis, as there are 15 in the original test case.
     12 ; CHECK: select
     13 ; CHECK: select
     14 ; CHECK: select
     15 ; CHECK: select
     16 ; CHECK: select
     17 ; CHECK: select
     18 ; CHECK: select
     19 ; CHECK: select
     20 ; CHECK: select
     21 ; CHECK: select
     22 ; CHECK: select
     23 ; CHECK: select
     24 ; CHECK: select
     25 ; CHECK: select
     26 ; CHECK: select
     27 ; CHECK: select
     28 ; CHECK-NOT: select
     29 ; CHECK: br i1 {{.*}}, label %[[L:.*]], label %[[R:.*]]
     30 ; CHECK: [[L]] ; preds = 
     31 ; CHECK-NEXT: store
     32 ; CHECK-NEXT: br label %[[R]]
     33 ; CHECK: [[R]] ; preds = 
     34 ; CHECK-NEXT: ret i32 0
     35 
     36 define i32 @f(i32* %b) {
     37 entry:
     38   %0 = load i32, i32* %b, align 4
     39   %and = and i32 %0, 1
     40   %tobool = icmp eq i32 %and, 0
     41   br i1 %tobool, label %if.end, label %if.then
     42 
     43 if.then:                                          ; preds = %entry
     44   %or = or i32 %0, -2147483648
     45   store i32 %or, i32* %b, align 4
     46   br label %if.end
     47 
     48 if.end:                                           ; preds = %entry, %if.then
     49   %1 = phi i32 [ %0, %entry ], [ %or, %if.then ]
     50   %and1 = and i32 %1, 2
     51   %tobool2 = icmp eq i32 %and1, 0
     52   br i1 %tobool2, label %if.end5, label %if.then3
     53 
     54 if.then3:                                         ; preds = %if.end
     55   %or4 = or i32 %1, 1073741824
     56   store i32 %or4, i32* %b, align 4
     57   br label %if.end5
     58 
     59 if.end5:                                          ; preds = %if.end, %if.then3
     60   %2 = phi i32 [ %1, %if.end ], [ %or4, %if.then3 ]
     61   %and6 = and i32 %2, 4
     62   %tobool7 = icmp eq i32 %and6, 0
     63   br i1 %tobool7, label %if.end10, label %if.then8
     64 
     65 if.then8:                                         ; preds = %if.end5
     66   %or9 = or i32 %2, 536870912
     67   store i32 %or9, i32* %b, align 4
     68   br label %if.end10
     69 
     70 if.end10:                                         ; preds = %if.end5, %if.then8
     71   %3 = phi i32 [ %2, %if.end5 ], [ %or9, %if.then8 ]
     72   %and11 = and i32 %3, 8
     73   %tobool12 = icmp eq i32 %and11, 0
     74   br i1 %tobool12, label %if.end15, label %if.then13
     75 
     76 if.then13:                                        ; preds = %if.end10
     77   %or14 = or i32 %3, 268435456
     78   store i32 %or14, i32* %b, align 4
     79   br label %if.end15
     80 
     81 if.end15:                                         ; preds = %if.end10, %if.then13
     82   %4 = phi i32 [ %3, %if.end10 ], [ %or14, %if.then13 ]
     83   %and16 = and i32 %4, 16
     84   %tobool17 = icmp eq i32 %and16, 0
     85   br i1 %tobool17, label %if.end20, label %if.then18
     86 
     87 if.then18:                                        ; preds = %if.end15
     88   %or19 = or i32 %4, 134217728
     89   store i32 %or19, i32* %b, align 4
     90   br label %if.end20
     91 
     92 if.end20:                                         ; preds = %if.end15, %if.then18
     93   %5 = phi i32 [ %4, %if.end15 ], [ %or19, %if.then18 ]
     94   %and21 = and i32 %5, 32
     95   %tobool22 = icmp eq i32 %and21, 0
     96   br i1 %tobool22, label %if.end25, label %if.then23
     97 
     98 if.then23:                                        ; preds = %if.end20
     99   %or24 = or i32 %5, 67108864
    100   store i32 %or24, i32* %b, align 4
    101   br label %if.end25
    102 
    103 if.end25:                                         ; preds = %if.end20, %if.then23
    104   %6 = phi i32 [ %5, %if.end20 ], [ %or24, %if.then23 ]
    105   %and26 = and i32 %6, 64
    106   %tobool27 = icmp eq i32 %and26, 0
    107   br i1 %tobool27, label %if.end30, label %if.then28
    108 
    109 if.then28:                                        ; preds = %if.end25
    110   %or29 = or i32 %6, 33554432
    111   store i32 %or29, i32* %b, align 4
    112   br label %if.end30
    113 
    114 if.end30:                                         ; preds = %if.end25, %if.then28
    115   %7 = phi i32 [ %6, %if.end25 ], [ %or29, %if.then28 ]
    116   %and31 = and i32 %7, 256
    117   %tobool32 = icmp eq i32 %and31, 0
    118   br i1 %tobool32, label %if.end35, label %if.then33
    119 
    120 if.then33:                                        ; preds = %if.end30
    121   %or34 = or i32 %7, 8388608
    122   store i32 %or34, i32* %b, align 4
    123   br label %if.end35
    124 
    125 if.end35:                                         ; preds = %if.end30, %if.then33
    126   %8 = phi i32 [ %7, %if.end30 ], [ %or34, %if.then33 ]
    127   %and36 = and i32 %8, 512
    128   %tobool37 = icmp eq i32 %and36, 0
    129   br i1 %tobool37, label %if.end40, label %if.then38
    130 
    131 if.then38:                                        ; preds = %if.end35
    132   %or39 = or i32 %8, 4194304
    133   store i32 %or39, i32* %b, align 4
    134   br label %if.end40
    135 
    136 if.end40:                                         ; preds = %if.end35, %if.then38
    137   %9 = phi i32 [ %8, %if.end35 ], [ %or39, %if.then38 ]
    138   %and41 = and i32 %9, 1024
    139   %tobool42 = icmp eq i32 %and41, 0
    140   br i1 %tobool42, label %if.end45, label %if.then43
    141 
    142 if.then43:                                        ; preds = %if.end40
    143   %or44 = or i32 %9, 2097152
    144   store i32 %or44, i32* %b, align 4
    145   br label %if.end45
    146 
    147 if.end45:                                         ; preds = %if.end40, %if.then43
    148   %10 = phi i32 [ %9, %if.end40 ], [ %or44, %if.then43 ]
    149   %and46 = and i32 %10, 2048
    150   %tobool47 = icmp eq i32 %and46, 0
    151   br i1 %tobool47, label %if.end50, label %if.then48
    152 
    153 if.then48:                                        ; preds = %if.end45
    154   %or49 = or i32 %10, 1048576
    155   store i32 %or49, i32* %b, align 4
    156   br label %if.end50
    157 
    158 if.end50:                                         ; preds = %if.end45, %if.then48
    159   %11 = phi i32 [ %10, %if.end45 ], [ %or49, %if.then48 ]
    160   %and51 = and i32 %11, 4096
    161   %tobool52 = icmp eq i32 %and51, 0
    162   br i1 %tobool52, label %if.end55, label %if.then53
    163 
    164 if.then53:                                        ; preds = %if.end50
    165   %or54 = or i32 %11, 524288
    166   store i32 %or54, i32* %b, align 4
    167   br label %if.end55
    168 
    169 if.end55:                                         ; preds = %if.end50, %if.then53
    170   %12 = phi i32 [ %11, %if.end50 ], [ %or54, %if.then53 ]
    171   %and56 = and i32 %12, 8192
    172   %tobool57 = icmp eq i32 %and56, 0
    173   br i1 %tobool57, label %if.end60, label %if.then58
    174 
    175 if.then58:                                        ; preds = %if.end55
    176   %or59 = or i32 %12, 262144
    177   store i32 %or59, i32* %b, align 4
    178   br label %if.end60
    179 
    180 if.end60:                                         ; preds = %if.end55, %if.then58
    181   %13 = phi i32 [ %12, %if.end55 ], [ %or59, %if.then58 ]
    182   %and61 = and i32 %13, 16384
    183   %tobool62 = icmp eq i32 %and61, 0
    184   br i1 %tobool62, label %if.end65, label %if.then63
    185 
    186 if.then63:                                        ; preds = %if.end60
    187   %or64 = or i32 %13, 131072
    188   store i32 %or64, i32* %b, align 4
    189   br label %if.end65
    190 
    191 if.end65:                                         ; preds = %if.end60, %if.then63
    192   %14 = phi i32 [ %13, %if.end60 ], [ %or64, %if.then63 ]
    193   %and66 = and i32 %14, 32768
    194   %tobool67 = icmp eq i32 %and66, 0
    195   br i1 %tobool67, label %if.end70, label %if.then68
    196 
    197 if.then68:                                        ; preds = %if.end65
    198   %or69 = or i32 %14, 65536
    199   store i32 %or69, i32* %b, align 4
    200   br label %if.end70
    201 
    202 if.end70:                                         ; preds = %if.end65, %if.then68
    203   %15 = phi i32 [ %14, %if.end65 ], [ %or69, %if.then68 ]
    204   %and71 = and i32 %15, 128
    205   %tobool72 = icmp eq i32 %and71, 0
    206   br i1 %tobool72, label %if.end75, label %if.then73
    207 
    208 if.then73:                                        ; preds = %if.end70
    209   %or74 = or i32 %15, 16777216
    210   store i32 %or74, i32* %b, align 4
    211   br label %if.end75
    212 
    213 if.end75:                                         ; preds = %if.end70, %if.then73
    214   ret i32 0
    215 }
    216