Home | History | Annotate | Download | only in IndVarSimplify
      1 ; RUN: opt < %s -indvars -S | FileCheck %s
      2 
      3 ; Provide legal integer types.
      4 target datalayout = "n8:16:32:64"
      5 
      6 
      7 target triple = "x86_64-apple-darwin"
      8 
      9 ; CHECK-LABEL: @loop_0
     10 ; CHECK-LABEL: B18:
     11 ; Only one phi now.
     12 ; CHECK: phi
     13 ; CHECK-NOT: phi
     14 ; One trunc for the gep.
     15 ; CHECK: trunc i64 %indvars.iv to i32
     16 ; One trunc for the dummy() call.
     17 ; CHECK-LABEL: exit24:
     18 ; CHECK: trunc i64 {{.*}}lcssa.wide to i32
     19 define void @loop_0(i32* %a) {
     20 Prologue:
     21   br i1 undef, label %B18, label %B6
     22 
     23 B18:                                        ; preds = %B24, %Prologue
     24   %.02 = phi i32 [ 0, %Prologue ], [ %tmp33, %B24 ]
     25   %tmp23 = zext i32 %.02 to i64
     26   %tmp33 = add i32 %.02, 1
     27   %o = getelementptr i32, i32* %a, i32 %.02
     28   %v = load i32, i32* %o
     29   %t = icmp eq i32 %v, 0
     30   br i1 %t, label %exit24, label %B24
     31 
     32 B24:                                        ; preds = %B18
     33   %t2 = icmp eq i32 %tmp33, 20
     34   br i1 %t2, label %B6, label %B18
     35 
     36 B6:                                       ; preds = %Prologue
     37   ret void
     38 
     39 exit24:                      ; preds = %B18
     40   call void @dummy(i32 %.02)
     41   unreachable
     42 }
     43 
     44 define void @loop_1(i32 %lim) {
     45 ; CHECK-LABEL: @loop_1(
     46  entry:
     47   %entry.cond = icmp ne i32 %lim, 0
     48   br i1 %entry.cond, label %loop, label %leave
     49 
     50  loop:
     51 ; CHECK: loop:
     52 ; CHECK:  %indvars.iv = phi i64 [ 1, %loop.preheader ], [ %indvars.iv.next, %loop ]
     53 ; CHECK:  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
     54 ; CHECK:  [[IV_INC:%[^ ]+]] = add nsw i64 %indvars.iv, -1
     55 ; CHECK:  call void @dummy.i64(i64 [[IV_INC]])
     56 
     57   %iv = phi i32 [ 1, %entry ], [ %iv.inc, %loop ]
     58   %iv.inc = add i32 %iv, 1
     59   %iv.inc.sub = add i32 %iv, -1
     60   %iv.inc.sub.zext = zext i32 %iv.inc.sub to i64
     61   call void @dummy.i64(i64 %iv.inc.sub.zext)
     62   %be.cond = icmp ult i32 %iv.inc, %lim
     63   br i1 %be.cond, label %loop, label %leave
     64 
     65  leave:
     66   ret void
     67 }
     68 
     69 declare void @dummy(i32)
     70 declare void @dummy.i64(i64)
     71