Home | History | Annotate | Download | only in LoopDeletion
      1 ; RUN: opt < %s -loop-deletion -S | FileCheck %s
      2 
      3 ; Checks whether dead loops with multiple exits can be eliminated
      4 
      5 define void @foo(i64 %n, i64 %m) nounwind {
      6 ; CHECK-LABEL: @foo(
      7 ; CHECK:      entry:
      8 ; CHECK-NEXT:   br label %return
      9 
     10 ; CHECK:      return:
     11 ; CHECK-NEXT:   ret void
     12 entry:
     13   br label %bb
     14 
     15 bb:
     16   %x.0 = phi i64 [ 0, %entry ], [ %t0, %bb2 ]
     17   %t0 = add i64 %x.0, 1
     18   %t1 = icmp slt i64 %x.0, %n
     19   br i1 %t1, label %bb2, label %return
     20 bb2:
     21   %t2 = icmp slt i64 %x.0, %m
     22   br i1 %t1, label %bb, label %return
     23 
     24 return:
     25   ret void
     26 }
     27 
     28 define i64 @bar(i64 %n, i64 %m) nounwind {
     29 ; CHECK-LABEL:  @bar(
     30 ; CHECK: entry:
     31 ; CHECK-NEXT:  br label %return
     32 
     33 ; CHECK: return:
     34 ; CHECK-NEXT:  ret i64 10
     35 
     36 entry:
     37   br label %bb
     38 
     39 bb:
     40   %x.0 = phi i64 [ 0, %entry ], [ %t0, %bb3 ]
     41   %t0 = add i64 %x.0, 1
     42   %t1 = icmp slt i64 %x.0, %n
     43   br i1 %t1, label %bb2, label %return
     44 bb2:
     45   %t2 = icmp slt i64 %x.0, %m
     46   br i1 %t2, label %bb3, label %return
     47 bb3:
     48   %t3 = icmp slt i64 %x.0, %m
     49   br i1 %t3, label %bb, label %return
     50 
     51 return:
     52   %x.lcssa = phi i64 [ 10, %bb ], [ 10, %bb2 ], [ 10, %bb3 ]
     53   ret i64 %x.lcssa
     54 }
     55 
     56 define i64 @baz(i64 %n, i64 %m) nounwind {
     57 ; CHECK-LABEL:  @baz(
     58 ; CHECK: return:
     59 ; CHECK-NEXT:  %x.lcssa = phi i64 [ 12, %bb ], [ 10, %bb2 ]
     60 ; CHECK-NEXT:  ret i64 %x.lcssa
     61 
     62 entry:
     63   br label %bb
     64 
     65 bb:
     66   %x.0 = phi i64 [ 0, %entry ], [ %t0, %bb3 ]
     67   %t0 = add i64 %x.0, 1
     68   %t1 = icmp slt i64 %x.0, %n
     69   br i1 %t1, label %bb2, label %return
     70 bb2:
     71   %t2 = icmp slt i64 %x.0, %m
     72   br i1 %t2, label %bb3, label %return
     73 bb3:
     74   %t3 = icmp slt i64 %x.0, %m
     75   br i1 %t3, label %bb, label %return
     76 
     77 return:
     78   %x.lcssa = phi i64 [ 12, %bb ], [ 10, %bb2 ], [ 10, %bb3 ]
     79   ret i64 %x.lcssa
     80 }
     81