Home | History | Annotate | Download | only in LoopStrengthReduce
      1 ; RUN: opt -loop-reduce -S < %s | FileCheck %s
      2 ;
      3 ; Test LSR's use of SplitCriticalEdge during phi rewriting.
      4 
      5 target triple = "x86-apple-darwin"
      6 
      7 ; Verify that identical edges are merged. rdar://problem/6453893
      8 ; CHECK: @test1
      9 ; CHECK: bb89:
     10 ; CHECK: phi i8* [ %lsr.iv.next1, %bbA.bb89_crit_edge ], [ %lsr.iv.next1, %bbB.bb89_crit_edge ]{{$}}
     11 
     12 define i8* @test1() {
     13 entry:
     14   br label %loop
     15 
     16 loop:
     17   %rec = phi i32 [ %next, %loop ], [ 0, %entry ]
     18   %next = add i32 %rec, 1
     19   %tmp75 = getelementptr i8* null, i32 %next
     20   br i1 false, label %loop, label %loopexit
     21 
     22 loopexit:
     23   br i1 false, label %bbA, label %bbB
     24 
     25 bbA:
     26   switch i32 0, label %bb89 [
     27     i32 47, label %bb89
     28     i32 58, label %bb89
     29   ]
     30 
     31 bbB:
     32   switch i8 0, label %bb89 [
     33     i8 47, label %bb89
     34     i8 58, label %bb89
     35   ]
     36 
     37 bb89:
     38   %tmp75phi = phi i8* [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbB ], [ %tmp75, %bbB ], [ %tmp75, %bbB ]
     39   br label %exit
     40 
     41 exit:
     42   ret i8* %tmp75phi
     43 }
     44 
     45 ; Handle single-predecessor phis: PR13756
     46 ; CHECK: @test2
     47 ; CHECK: bb89:
     48 ; CHECK: phi i8* [ %lsr.iv.next1, %bbA ], [ %lsr.iv.next1, %bbA ], [ %lsr.iv.next1, %bbA ]{{$}}
     49 define i8* @test2() {
     50 entry:
     51   br label %loop
     52 
     53 loop:
     54   %rec = phi i32 [ %next, %loop ], [ 0, %entry ]
     55   %next = add i32 %rec, 1
     56   %tmp75 = getelementptr i8* null, i32 %next
     57   br i1 false, label %loop, label %loopexit
     58 
     59 loopexit:
     60   br i1 false, label %bbA, label %bbB
     61 
     62 bbA:
     63   switch i32 0, label %bb89 [
     64     i32 47, label %bb89
     65     i32 58, label %bb89
     66   ]
     67 
     68 bbB:
     69   switch i8 0, label %exit [
     70     i8 47, label %exit
     71     i8 58, label %exit
     72   ]
     73 
     74 bb89:
     75   %tmp75phi = phi i8* [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbA ]
     76   br label %exit
     77 
     78 exit:
     79   %result = phi i8* [ %tmp75phi, %bb89 ], [ %tmp75, %bbB ], [ %tmp75, %bbB ], [ %tmp75, %bbB ]
     80   ret i8* %result
     81 }
     82