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