1; RUN: opt < %s -S -loop-unroll -unroll-runtime=true -unroll-count=16 | FileCheck --check-prefix=UNROLL-16 %s 2; RUN: opt < %s -S -loop-unroll -unroll-runtime=true -unroll-count=4 | FileCheck --check-prefix=UNROLL-4 %s 3 4; Given that the trip-count of this loop is a 3-bit value, we cannot 5; safely unroll it with a count of anything more than 8. 6 7define i3 @test(i3* %a, i3 %n) { 8; UNROLL-16-LABEL: @test( 9; UNROLL-4-LABEL: @test( 10entry: 11 %cmp1 = icmp eq i3 %n, 0 12 br i1 %cmp1, label %for.end, label %for.body 13 14; UNROLL-16-NOT: for.body.prol: 15; UNROLL-4: for.body.prol: 16 17for.body: ; preds = %for.body, %entry 18; UNROLL-16-LABEL: for.body: 19; UNROLL-4-LABEL: for.body: 20 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] 21 %sum.02 = phi i3 [ %add, %for.body ], [ 0, %entry ] 22 %arrayidx = getelementptr inbounds i3, i3* %a, i64 %indvars.iv 23 24; UNROLL-16-LABEL: for.body 25; UNROLL-16-LABEL: getelementptr 26; UNROLL-16-LABEL-NOT: getelementptr 27 28; UNROLL-4-LABEL: getelementptr 29; UNROLL-4-LABEL: getelementptr 30; UNROLL-4-LABEL: getelementptr 31; UNROLL-4-LABEL: getelementptr 32 33 %0 = load i3, i3* %arrayidx 34 %add = add nsw i3 %0, %sum.02 35 %indvars.iv.next = add i64 %indvars.iv, 1 36 %lftr.wideiv = trunc i64 %indvars.iv.next to i3 37 %exitcond = icmp eq i3 %lftr.wideiv, %n 38 br i1 %exitcond, label %for.end, label %for.body 39 40; UNROLL-16-LABEL: for.end 41; UNROLL-4-LABEL: for.end 42for.end: ; preds = %for.body, %entry 43 %sum.0.lcssa = phi i3 [ 0, %entry ], [ %add, %for.body ] 44 ret i3 %sum.0.lcssa 45} 46