Home | History | Annotate | Download | only in LoopRotate
      1 ; RUN: opt -S -loop-rotate < %s -verify-loop-info -verify-dom-info | FileCheck %s
      2 
      3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
      4 target triple = "x86_64-apple-macosx10.8.0"
      5 
      6 ; PR7447
      7 define i32 @test1([100 x i32]* nocapture %a) nounwind readonly {
      8 entry:
      9   br label %for.cond
     10 
     11 for.cond:                                         ; preds = %for.cond1, %entry
     12   %sum.0 = phi i32 [ 0, %entry ], [ %sum.1, %for.cond1 ]
     13   %i.0 = phi i1 [ true, %entry ], [ false, %for.cond1 ]
     14   br i1 %i.0, label %for.cond1, label %return
     15 
     16 for.cond1:                                        ; preds = %for.cond, %land.rhs
     17   %sum.1 = phi i32 [ %add, %land.rhs ], [ %sum.0, %for.cond ]
     18   %i.1 = phi i32 [ %inc, %land.rhs ], [ 0, %for.cond ]
     19   %cmp2 = icmp ult i32 %i.1, 100
     20   br i1 %cmp2, label %land.rhs, label %for.cond
     21 
     22 land.rhs:                                         ; preds = %for.cond1
     23   %conv = zext i32 %i.1 to i64
     24   %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* %a, i64 0, i64 %conv
     25   %0 = load i32, i32* %arrayidx, align 4
     26   %add = add i32 %0, %sum.1
     27   %cmp4 = icmp ugt i32 %add, 1000
     28   %inc = add i32 %i.1, 1
     29   br i1 %cmp4, label %return, label %for.cond1
     30 
     31 return:                                           ; preds = %for.cond, %land.rhs
     32   %retval.0 = phi i32 [ 1000, %land.rhs ], [ %sum.0, %for.cond ]
     33   ret i32 %retval.0
     34 
     35 ; CHECK-LABEL: @test1(
     36 ; CHECK: for.cond1.preheader:
     37 ; CHECK: %sum.04 = phi i32 [ 0, %entry ], [ %sum.1.lcssa, %for.cond.loopexit ]
     38 ; CHECK: br label %for.cond1
     39 
     40 ; CHECK: for.cond1:
     41 ; CHECK: %sum.1 = phi i32 [ %add, %land.rhs ], [ %sum.04, %for.cond1.preheader ]
     42 ; CHECK: %i.1 = phi i32 [ %inc, %land.rhs ], [ 0, %for.cond1.preheader ]
     43 ; CHECK: %cmp2 = icmp ult i32 %i.1, 100
     44 ; CHECK: br i1 %cmp2, label %land.rhs, label %for.cond.loopexit
     45 }
     46 
     47 define void @test2(i32 %x) nounwind {
     48 entry:
     49   br label %for.cond
     50 
     51 for.cond:                                         ; preds = %if.end, %entry
     52   %i.0 = phi i32 [ 0, %entry ], [ %inc, %if.end ]
     53   %cmp = icmp eq i32 %i.0, %x
     54   br i1 %cmp, label %return.loopexit, label %for.body
     55 
     56 for.body:                                         ; preds = %for.cond
     57   %call = tail call i32 @foo(i32 %i.0) nounwind
     58   %tobool = icmp eq i32 %call, 0
     59   br i1 %tobool, label %if.end, label %a
     60 
     61 if.end:                                           ; preds = %for.body
     62   %call1 = tail call i32 @foo(i32 42) nounwind
     63   %inc = add i32 %i.0, 1
     64   br label %for.cond
     65 
     66 a:                                                ; preds = %for.body
     67   %call2 = tail call i32 @bar(i32 1) nounwind
     68   br label %return
     69 
     70 return.loopexit:                                  ; preds = %for.cond
     71   br label %return
     72 
     73 return:                                           ; preds = %return.loopexit, %a
     74   ret void
     75 
     76 ; CHECK-LABEL: @test2(
     77 ; CHECK: if.end:
     78 ; CHECK: %inc = add i32 %i.02, 1
     79 ; CHECK: %cmp = icmp eq i32 %inc, %x
     80 ; CHECK: br i1 %cmp, label %for.cond.return.loopexit_crit_edge, label %for.body
     81 }
     82 
     83 declare i32 @foo(i32)
     84 
     85 declare i32 @bar(i32)
     86 
     87 @_ZTIi = external constant i8*
     88 
     89 ; Verify dominators.
     90 define void @test3(i32 %x) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
     91 entry:
     92   %cmp2 = icmp eq i32 0, %x
     93   br i1 %cmp2, label %try.cont.loopexit, label %for.body.lr.ph
     94 
     95 for.body.lr.ph:                                   ; preds = %entry
     96   br label %for.body
     97 
     98 for.body:                                         ; preds = %for.body.lr.ph, %for.inc
     99   %i.03 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
    100   invoke void @_Z3fooi(i32 %i.03)
    101           to label %for.inc unwind label %lpad
    102 
    103 for.inc:                                          ; preds = %for.body
    104   %inc = add i32 %i.03, 1
    105   %cmp = icmp eq i32 %inc, %x
    106   br i1 %cmp, label %for.cond.try.cont.loopexit_crit_edge, label %for.body
    107 
    108 lpad:                                             ; preds = %for.body
    109   %0 = landingpad { i8*, i32 }
    110           catch i8* bitcast (i8** @_ZTIi to i8*)
    111   %1 = extractvalue { i8*, i32 } %0, 0
    112   %2 = extractvalue { i8*, i32 } %0, 1
    113   %3 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
    114   %matches = icmp eq i32 %2, %3
    115   br i1 %matches, label %catch, label %eh.resume
    116 
    117 catch:                                            ; preds = %lpad
    118   %4 = tail call i8* @__cxa_begin_catch(i8* %1) nounwind
    119   br i1 true, label %invoke.cont2.loopexit, label %for.body.i.lr.ph
    120 
    121 for.body.i.lr.ph:                                 ; preds = %catch
    122   br label %for.body.i
    123 
    124 for.body.i:                                       ; preds = %for.body.i.lr.ph, %for.inc.i
    125   %i.0.i1 = phi i32 [ 0, %for.body.i.lr.ph ], [ %inc.i, %for.inc.i ]
    126   invoke void @_Z3fooi(i32 %i.0.i1)
    127           to label %for.inc.i unwind label %lpad.i
    128 
    129 for.inc.i:                                        ; preds = %for.body.i
    130   %inc.i = add i32 %i.0.i1, 1
    131   %cmp.i = icmp eq i32 %inc.i, 0
    132   br i1 %cmp.i, label %for.cond.i.invoke.cont2.loopexit_crit_edge, label %for.body.i
    133 
    134 lpad.i:                                           ; preds = %for.body.i
    135   %5 = landingpad { i8*, i32 }
    136           catch i8* bitcast (i8** @_ZTIi to i8*)
    137   %6 = extractvalue { i8*, i32 } %5, 0
    138   %7 = extractvalue { i8*, i32 } %5, 1
    139   %matches.i = icmp eq i32 %7, %3
    140   br i1 %matches.i, label %catch.i, label %lpad1.body
    141 
    142 catch.i:                                          ; preds = %lpad.i
    143   %8 = tail call i8* @__cxa_begin_catch(i8* %6) nounwind
    144   invoke void @test3(i32 0)
    145           to label %invoke.cont2.i unwind label %lpad1.i
    146 
    147 invoke.cont2.i:                                   ; preds = %catch.i
    148   tail call void @__cxa_end_catch() nounwind
    149   br label %invoke.cont2
    150 
    151 lpad1.i:                                          ; preds = %catch.i
    152   %9 = landingpad { i8*, i32 }
    153           cleanup
    154   %10 = extractvalue { i8*, i32 } %9, 0
    155   %11 = extractvalue { i8*, i32 } %9, 1
    156   tail call void @__cxa_end_catch() nounwind
    157   br label %lpad1.body
    158 
    159 for.cond.i.invoke.cont2.loopexit_crit_edge:       ; preds = %for.inc.i
    160   br label %invoke.cont2.loopexit
    161 
    162 invoke.cont2.loopexit:                            ; preds = %for.cond.i.invoke.cont2.loopexit_crit_edge, %catch
    163   br label %invoke.cont2
    164 
    165 invoke.cont2:                                     ; preds = %invoke.cont2.loopexit, %invoke.cont2.i
    166   tail call void @__cxa_end_catch() nounwind
    167   br label %try.cont
    168 
    169 for.cond.try.cont.loopexit_crit_edge:             ; preds = %for.inc
    170   br label %try.cont.loopexit
    171 
    172 try.cont.loopexit:                                ; preds = %for.cond.try.cont.loopexit_crit_edge, %entry
    173   br label %try.cont
    174 
    175 try.cont:                                         ; preds = %try.cont.loopexit, %invoke.cont2
    176   ret void
    177 
    178 lpad1.body:                                       ; preds = %lpad1.i, %lpad.i
    179   %exn.slot.0.i = phi i8* [ %10, %lpad1.i ], [ %6, %lpad.i ]
    180   %ehselector.slot.0.i = phi i32 [ %11, %lpad1.i ], [ %7, %lpad.i ]
    181   tail call void @__cxa_end_catch() nounwind
    182   br label %eh.resume
    183 
    184 eh.resume:                                        ; preds = %lpad1.body, %lpad
    185   %exn.slot.0 = phi i8* [ %exn.slot.0.i, %lpad1.body ], [ %1, %lpad ]
    186   %ehselector.slot.0 = phi i32 [ %ehselector.slot.0.i, %lpad1.body ], [ %2, %lpad ]
    187   %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn.slot.0, 0
    188   %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %ehselector.slot.0, 1
    189   resume { i8*, i32 } %lpad.val5
    190 }
    191 
    192 declare void @_Z3fooi(i32)
    193 
    194 declare i32 @__gxx_personality_v0(...)
    195 
    196 declare i32 @llvm.eh.typeid.for(i8*) nounwind readnone
    197 
    198 declare i8* @__cxa_begin_catch(i8*)
    199 
    200 declare void @__cxa_end_catch()
    201 
    202 define void @test4() nounwind uwtable {
    203 entry:
    204   br label %"7"
    205 
    206 "3":                                              ; preds = %"7"
    207   br i1 undef, label %"31", label %"4"
    208 
    209 "4":                                              ; preds = %"3"
    210   %. = select i1 undef, float 0x3F50624DE0000000, float undef
    211   %0 = add i32 %1, 1
    212   br label %"7"
    213 
    214 "7":                                              ; preds = %"4", %entry
    215   %1 = phi i32 [ %0, %"4" ], [ 0, %entry ]
    216   %2 = icmp slt i32 %1, 100
    217   br i1 %2, label %"3", label %"8"
    218 
    219 "8":                                              ; preds = %"7"
    220   br i1 undef, label %"9", label %"31"
    221 
    222 "9":                                              ; preds = %"8"
    223   br label %"33"
    224 
    225 "27":                                             ; preds = %"31"
    226   unreachable
    227 
    228 "31":                                             ; preds = %"8", %"3"
    229   br i1 undef, label %"27", label %"32"
    230 
    231 "32":                                             ; preds = %"31"
    232   br label %"33"
    233 
    234 "33":                                             ; preds = %"32", %"9"
    235   ret void
    236 }
    237