1 ; RUN: opt -S -indvars < %s | FileCheck %s 2 3 ; Provide legal integer types. 4 target datalayout = "n8:16:32:64" 5 6 7 define void @test1(float* %autoc, 8 float* %data, 9 float %d, i32 %data_len, i32 %sample) nounwind { 10 entry: 11 %sub = sub i32 %data_len, %sample 12 %cmp4 = icmp eq i32 %data_len, %sample 13 br i1 %cmp4, label %for.end, label %for.body 14 15 for.body: ; preds = %entry, %for.body 16 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 68719476736, %entry ] 17 %temp = trunc i64 %indvars.iv to i32 18 %add = add i32 %temp, %sample 19 %idxprom = zext i32 %add to i64 20 %arrayidx = getelementptr inbounds float, float* %data, i64 %idxprom 21 %temp1 = load float, float* %arrayidx, align 4 22 %mul = fmul float %temp1, %d 23 %arrayidx2 = getelementptr inbounds float, float* %autoc, i64 %indvars.iv 24 %temp2 = load float, float* %arrayidx2, align 4 25 %add3 = fadd float %temp2, %mul 26 store float %add3, float* %arrayidx2, align 4 27 %indvars.iv.next = add i64 %indvars.iv, 1 28 %temp3 = trunc i64 %indvars.iv.next to i32 29 %cmp = icmp ult i32 %temp3, %sub 30 br i1 %cmp, label %for.body, label %for.end 31 32 for.end: ; preds = %for.body, %entry 33 ret void 34 35 ; CHECK-LABEL: @test1( 36 37 ; With the given initial value for IV, it is not legal to widen 38 ; trip count to IV size 39 ; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 40 ; CHECK: %lftr.wideiv = trunc i64 %indvars.iv.next to i32 41 ; CHECK: %exitcond = icmp ne i32 %lftr.wideiv, %sub 42 ; CHECK: br i1 %exitcond, label %for.body, label %for.end.loopexit 43 } 44 45 define float @test2(float* %a, 46 float* %b, 47 i32 zeroext %m) local_unnamed_addr #0 { 48 entry: 49 %cmp5 = icmp ugt i32 %m, 500 50 br i1 %cmp5, label %for.body.preheader, label %for.end 51 52 for.body.preheader: ; preds = %entry 53 br label %for.body 54 55 for.body: ; preds = %for.body.preheader, %for.body 56 %sum.07 = phi float [ %add, %for.body ], [ 0.000000e+00, %for.body.preheader ] 57 %i.06 = phi i32 [ %inc, %for.body ], [ 500, %for.body.preheader ] 58 %idxprom = zext i32 %i.06 to i64 59 %arrayidx = getelementptr inbounds float, float* %b, i64 %idxprom 60 %temp = load float, float* %arrayidx, align 4 61 %arrayidx2 = getelementptr inbounds float, float* %a, i64 %idxprom 62 %temp1 = load float, float* %arrayidx2, align 4 63 %mul = fmul float %temp, %temp1 64 %add = fadd float %sum.07, %mul 65 %inc = add i32 %i.06, 1 66 %cmp = icmp ult i32 %inc, %m 67 br i1 %cmp, label %for.body, label %for.end.loopexit 68 69 for.end.loopexit: ; preds = %for.body 70 br label %for.end 71 72 for.end: ; preds = %for.end.loopexit, %entry 73 %sum.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add, %for.end.loopexit ] 74 ret float %sum.0.lcssa 75 76 ; CHECK-LABEL: @test2( 77 ; Trip count should be widened and LFTR should canonicalize the condition 78 ; CHECK: %wide.trip.count = zext 79 ; CHECK: %exitcond = icmp ne i64 %indvars.iv.next, %wide.trip.count 80 ; CHECK: br i1 %exitcond 81 } 82 83 define float @test3(float* %b, 84 i32 signext %m) local_unnamed_addr #0 { 85 entry: 86 %cmp5 = icmp sgt i32 %m, -10 87 br i1 %cmp5, label %for.body.preheader, label %for.end 88 89 for.body.preheader: ; preds = %entry 90 br label %for.body 91 92 for.body: ; preds = %for.body.preheader, %for.body 93 %sum.07 = phi float [ %add1, %for.body ], [ 0.000000e+00, %for.body.preheader ] 94 %i.06 = phi i32 [ %inc, %for.body ], [ -10, %for.body.preheader ] 95 %add = add nsw i32 %i.06, 20 96 %idxprom = sext i32 %add to i64 97 %arrayidx = getelementptr inbounds float, float* %b, i64 %idxprom 98 %temp = load float, float* %arrayidx, align 4 99 %conv = sitofp i32 %i.06 to float 100 %mul = fmul float %conv, %temp 101 %add1 = fadd float %sum.07, %mul 102 %inc = add nsw i32 %i.06, 1 103 %cmp = icmp slt i32 %inc, %m 104 br i1 %cmp, label %for.body, label %for.end.loopexit 105 106 for.end.loopexit: ; preds = %for.body 107 br label %for.end 108 109 for.end: ; preds = %for.end.loopexit, %entry 110 %sum.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add1, %for.end.loopexit ] 111 ret float %sum.0.lcssa 112 113 ; CHECK-LABEL: @test3( 114 ; Trip count should be widened and LFTR should canonicalize the condition 115 ; CHECK: %wide.trip.count = sext 116 ; CHECK: %exitcond = icmp ne i64 %indvars.iv.next, %wide.trip.count 117 ; CHECK: br i1 %exitcond 118 } 119 120 define float @test4(float* %b, 121 i32 signext %m) local_unnamed_addr #0 { 122 entry: 123 %cmp5 = icmp sgt i32 %m, 10 124 br i1 %cmp5, label %for.body.preheader, label %for.end 125 126 for.body.preheader: ; preds = %entry 127 br label %for.body 128 129 for.body: ; preds = %for.body.preheader, %for.body 130 %sum.07 = phi float [ %add1, %for.body ], [ 0.000000e+00, %for.body.preheader ] 131 %i.06 = phi i32 [ %inc, %for.body ], [ 10, %for.body.preheader ] 132 %add = add nsw i32 %i.06, 20 133 %idxprom = sext i32 %add to i64 134 %arrayidx = getelementptr inbounds float, float* %b, i64 %idxprom 135 %temp = load float, float* %arrayidx, align 4 136 %conv = sitofp i32 %i.06 to float 137 %mul = fmul float %conv, %temp 138 %add1 = fadd float %sum.07, %mul 139 %inc = add nsw i32 %i.06, 1 140 %cmp = icmp slt i32 %inc, %m 141 br i1 %cmp, label %for.body, label %for.end.loopexit 142 143 for.end.loopexit: ; preds = %for.body 144 %add1.lcssa = phi float [ %add1, %for.body ] 145 br label %for.end 146 147 for.end: ; preds = %for.end.loopexit, %entry 148 %sum.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add1.lcssa, %for.end.loopexit ] 149 ret float %sum.0.lcssa 150 151 ; CHECK-LABEL: @test4( 152 ; Trip count should be widened and LFTR should canonicalize the condition 153 ; CHECK: %wide.trip.count = zext 154 ; CHECK: %exitcond = icmp ne i64 %indvars.iv.next, %wide.trip.count 155 ; CHECK: br i1 %exitcond 156 } 157 158 159