• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
14for.body:                                         ; preds = %for.body, %entry
15; UNROLL-16-LABEL: for.body:
16; UNROLL-4-LABEL: for.body:
17  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
18  %sum.02 = phi i3 [ %add, %for.body ], [ 0, %entry ]
19  %arrayidx = getelementptr inbounds i3, i3* %a, i64 %indvars.iv
20
21; UNROLL-16-LABEL: for.body
22; UNROLL-16-LABEL: getelementptr
23; UNROLL-16-LABEL-NOT: getelementptr
24
25; UNROLL-4-LABEL: getelementptr
26; UNROLL-4-LABEL: getelementptr
27; UNROLL-4-LABEL: getelementptr
28; UNROLL-4-LABEL: getelementptr
29
30  %0 = load i3, i3* %arrayidx
31  %add = add nsw i3 %0, %sum.02
32  %indvars.iv.next = add i64 %indvars.iv, 1
33  %lftr.wideiv = trunc i64 %indvars.iv.next to i3
34  %exitcond = icmp eq i3 %lftr.wideiv, %n
35  br i1 %exitcond, label %for.end, label %for.body
36
37; UNROLL-16-LABEL: for.end
38; UNROLL-4-LABEL: for.end
39
40; UNROLL-16-NOT: for.body.epil:
41; UNROLL-4: for.body.epil:
42
43for.end:                                          ; preds = %for.body, %entry
44  %sum.0.lcssa = phi i3 [ 0, %entry ], [ %add, %for.body ]
45  ret i3 %sum.0.lcssa
46}
47