Home | History | Annotate | Download | only in IndVarSimplify
      1 ; RUN: opt -S -indvars < %s | FileCheck %s
      2 
      3 define void @test1(float* nocapture %autoc, float* nocapture %data, float %d, i32 %data_len, i32 %sample) nounwind {
      4 entry:
      5   %sub = sub i32 %data_len, %sample
      6   %cmp4 = icmp eq i32 %data_len, %sample
      7   br i1 %cmp4, label %for.end, label %for.body
      8 
      9 for.body:                                         ; preds = %entry, %for.body
     10   %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
     11   %0 = trunc i64 %indvars.iv to i32
     12   %add = add i32 %0, %sample
     13   %idxprom = zext i32 %add to i64
     14   %arrayidx = getelementptr inbounds float* %data, i64 %idxprom
     15   %1 = load float* %arrayidx, align 4
     16   %mul = fmul float %1, %d
     17   %arrayidx2 = getelementptr inbounds float* %autoc, i64 %indvars.iv
     18   %2 = load float* %arrayidx2, align 4
     19   %add3 = fadd float %2, %mul
     20   store float %add3, float* %arrayidx2, align 4
     21   %indvars.iv.next = add i64 %indvars.iv, 1
     22   %3 = trunc i64 %indvars.iv.next to i32
     23   %cmp = icmp ult i32 %3, %sub
     24   br i1 %cmp, label %for.body, label %for.end
     25 
     26 for.end:                                          ; preds = %for.body, %entry
     27   ret void
     28 
     29 ; CHECK-LABEL: @test1(
     30 
     31 ; First check that we move the sub into the preheader, it doesn't have to be
     32 ; executed if %cmp4 == false
     33 ; CHECK: for.body.preheader:
     34 ; CHECK: sub i32 %data_len, %sample
     35 ; CHECK: br label %for.body
     36 
     37 ; Second, check that we turn the IV test into an eq.
     38 ; CHECK: %lftr.wideiv = trunc i64 %indvars.iv.next to i32
     39 ; CHECK: %exitcond = icmp ne i32 %lftr.wideiv, %0
     40 ; CHECK: br i1 %exitcond, label %for.body, label %for.end.loopexit
     41 }
     42 
     43