Home | History | Annotate | Download | only in X86
      1 ; RUN: llc -mtriple=x86_64-apple-darwin < %s | FileCheck %s
      2 
      3 ; A MOV32ri is inside a loop, it has two successors, one successor is inside the
      4 ; same loop, the other successor is outside the loop. We should be able to sink
      5 ; MOV32ri outside the loop.
      6 ; rdar://11980766
      7 define i32 @sink_succ(i32 %argc, i8** nocapture %argv) nounwind uwtable ssp {
      8 ; CHECK-LABEL: sink_succ
      9 ; CHECK: [[OUTER_LN1:LBB0_[0-9]+]]: ## %preheader
     10 ; CHECK: %exit
     11 ; CHECK-NOT: movl
     12 ; CHECK: jne [[OUTER_LN1]]
     13 ; CHECK: movl
     14 ; CHECK: [[LN2:LBB0_[0-9]+]]: ## %for.body2
     15 ; CHECK: jne [[LN2]]
     16 ; CHECK: ret
     17 entry:
     18   br label %preheader
     19 
     20 preheader:
     21   %i.127 = phi i32 [ 0, %entry ], [ %inc9, %exit ]
     22   br label %for.body1.lr
     23 
     24 for.body1.lr:
     25   %iv30 = phi i32 [ 1, %preheader ], [ %iv.next31, %for.inc40.i ]
     26   br label %for.body1
     27 
     28 for.body1:
     29   %iv.i = phi i64 [ 0, %for.body1.lr ], [ %iv.next.i, %for.body1 ]
     30   %iv.next.i = add i64 %iv.i, 1
     31   %lftr.wideiv32 = trunc i64 %iv.next.i to i32
     32   %exitcond33 = icmp eq i32 %lftr.wideiv32, %iv30
     33   br i1 %exitcond33, label %for.inc40.i, label %for.body1
     34 
     35 for.inc40.i:
     36   %iv.next31 = add i32 %iv30, 1
     37   %exitcond49.i = icmp eq i32 %iv.next31, 32
     38   br i1 %exitcond49.i, label %exit, label %for.body1.lr
     39 
     40 exit:
     41   %inc9 = add nsw i32 %i.127, 1
     42   %exitcond34 = icmp eq i32 %inc9, 10
     43   br i1 %exitcond34, label %for.body2, label %preheader
     44 
     45 for.body2:
     46   %iv = phi i64 [ %iv.next, %for.body2 ], [ 0, %exit ]
     47   %iv.next = add i64 %iv, 1
     48   %lftr.wideiv = trunc i64 %iv.next to i32
     49   %exitcond = icmp eq i32 %lftr.wideiv, 2048
     50   br i1 %exitcond, label %for.end20, label %for.body2
     51 
     52 for.end20:
     53   ret i32 0
     54 }
     55 
     56 define i32 @sink_out_of_loop(i32 %n, i32* %output) {
     57 ; CHECK-LABEL: sink_out_of_loop:
     58 entry:
     59   br label %loop
     60 
     61 loop:
     62   %i = phi i32 [ 0, %entry ], [ %i2, %loop ]
     63   %j = mul i32 %i, %i
     64   %addr = getelementptr i32, i32* %output, i32 %i
     65   store i32 %i, i32* %addr
     66   %i2 = add i32 %i, 1
     67   %exit_cond = icmp sge i32 %i2, %n
     68   br i1 %exit_cond, label %exit, label %loop
     69 
     70 exit:
     71 ; CHECK: BB#2
     72 ; CHECK: imull %eax, %eax
     73 ; CHECK: retq
     74   ret i32 %j
     75 }
     76