blob: ebb9a85600bc5c1a74f62835cd02a0c6340b953e [file] [log] [blame]
Eric Christophercee313d2019-04-17 04:52:47 +00001; 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>,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
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
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
42
43; UNROLL-16-NOT: for.body.epil:
44; UNROLL-4: for.body.epil:
45
46for.end: ; preds = %for.body, %entry
47 %sum.0.lcssa = phi i3 [ 0, %entry ], [ %add, %for.body ]
48 ret i3 %sum.0.lcssa
49}