Home | History | Annotate | Download | only in LoopSimplify
      1 ; RUN: opt -loop-simplify -S < %s | FileCheck %s
      2 
      3 ; CHECK-LABEL: @test1
      4 define void @test1(i32 %n) {
      5 entry:
      6   br label %while.cond
      7 
      8 while.cond:                                       ; preds = %if.then, %if.else, %entry
      9   %count.0 = phi i32 [ 0, %entry ], [ %add, %if.then ], [ %add2, %if.else ]
     10   %cmp = icmp ugt i32 %count.0, %n
     11   br i1 %cmp, label %while.end, label %while.body
     12 
     13 while.body:                                       ; preds = %while.cond
     14   %rem = and i32 %count.0, 1
     15   %cmp1 = icmp eq i32 %rem, 0
     16   br i1 %cmp1, label %if.then, label %if.else
     17 
     18 if.then:                                          ; preds = %while.body
     19   %add = add i32 %count.0, 1
     20   br label %while.cond, !llvm.loop !0
     21 
     22 if.else:                                          ; preds = %while.body
     23   %add2 = add i32 %count.0, 2
     24   br label %while.cond, !llvm.loop !0
     25 
     26 while.end:                                        ; preds = %while.cond
     27   ret void
     28 }
     29 
     30 ; CHECK: if.then
     31 ; CHECK-NOT: br {{.*}}!llvm.loop{{.*}}
     32 
     33 ; CHECK: while.cond.backedge:
     34 ; CHECK: br label %while.cond, !llvm.loop !0
     35 
     36 ; CHECK: if.else
     37 ; CHECK-NOT: br {{.*}}!llvm.loop{{.*}}
     38 
     39 ; CHECK-LABEL: @test2
     40 ; CHECK: for.body:
     41 ; CHECK: br i1 %{{.*}}, label %for.body, label %cleanup.loopexit, !llvm.loop !0
     42 define void @test2(i32 %k)  {
     43 entry: 
     44   %cmp9 = icmp sgt i32 %k, 0
     45   br i1 %cmp9, label %for.body.preheader, label %cleanup
     46 
     47 for.body.preheader:                               ; preds = %entry
     48   br label %for.body
     49 
     50 for.cond:                                         ; preds = %for.body
     51   %cmp = icmp slt i32 %inc, %k
     52   br i1 %cmp, label %for.body, label %cleanup.loopexit, !llvm.loop !0
     53 
     54 for.body:                                         ; preds = %for.body.preheader, %for.cond
     55   %i.010 = phi i32 [ %inc, %for.cond ], [ 0, %for.body.preheader ]
     56   %cmp3 = icmp sgt i32 %i.010, 3
     57   %inc = add nsw i32 %i.010, 1
     58   br i1 %cmp3, label %cleanup.loopexit, label %for.cond
     59 
     60 cleanup.loopexit:                                 ; preds = %for.body, %for.cond
     61   br label %cleanup
     62 
     63 cleanup:                                          ; preds = %cleanup.loopexit, %entry
     64   ret void
     65 }
     66 
     67 !0 = distinct !{!0, !1}
     68 !1 = !{!"llvm.loop.distribute.enable", i1 true}
     69 ; CHECK: !0 = distinct !{!0, !1}
     70 ; CHECK: !1 = !{!"llvm.loop.distribute.enable", i1 true}
     71