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