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
4 ; RUN: opt < %s -S -passes='require<opt-remark-emit>,unroll' -unroll-runtime=true -unroll-count=16 | FileCheck --check-prefix=UNROLL-16 %s
5 ; RUN: opt < %s -S -passes='require<opt-remark-emit>,unroll' -unroll-runtime=true -unroll-count=4 | FileCheck --check-prefix=UNROLL-4 %s
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.
10 define i3 @test(i3* %a, i3 %n) {
11 ; UNROLL-16-LABEL: @test(
12 ; UNROLL-4-LABEL: @test(
14 %cmp1 = icmp eq i3 %n, 0
15 br i1 %cmp1, label %for.end, label %for.body
17 for.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
24 ; UNROLL-16-LABEL: for.body
25 ; UNROLL-16-LABEL: getelementptr
26 ; UNROLL-16-LABEL-NOT: getelementptr
28 ; UNROLL-4-LABEL: getelementptr
29 ; UNROLL-4-LABEL: getelementptr
30 ; UNROLL-4-LABEL: getelementptr
31 ; UNROLL-4-LABEL: getelementptr
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
40 ; UNROLL-16-LABEL: for.end
41 ; UNROLL-4-LABEL: for.end
43 ; UNROLL-16-NOT: for.body.epil:
44 ; UNROLL-4: for.body.epil:
46 for.end: ; preds = %for.body, %entry
47 %sum.0.lcssa = phi i3 [ 0, %entry ], [ %add, %for.body ]