1 ; RUN: opt < %s -S -loop-unroll -unroll-count=4 | FileCheck -check-prefix=CHECK_COUNT4 %s
\r
2 ; RUN: opt < %s -S -loop-unroll | FileCheck -check-prefix=CHECK_NOCOUNT %s
\r
3 ; RUN: opt < %s -S -passes='require<profile-summary>,function(unroll)' -pgso | FileCheck -check-prefix=PGSO %s
\r
4 ; RUN: opt < %s -S -passes='require<profile-summary>,function(unroll)' -pgso=false | FileCheck -check-prefix=NPGSO %s
\r
7 ;///////////////////// TEST 1 //////////////////////////////
\r
9 ; This test shows that the loop is unrolled according to the specified
\r
12 define void @Test1() nounwind {
\r
17 %iv = phi i32 [ 0, %entry ], [ %inc, %loop ]
\r
18 %inc = add i32 %iv, 1
\r
19 %exitcnd = icmp uge i32 %inc, 1024
\r
20 br i1 %exitcnd, label %exit, label %loop
\r
26 ; CHECK_COUNT4-LABEL: @Test1
\r
28 ; CHECK_COUNT4-NEXT: add
\r
29 ; CHECK_COUNT4-NEXT: add
\r
30 ; CHECK_COUNT4-NEXT: add
\r
31 ; CHECK_COUNT4-NEXT: add
\r
32 ; CHECK_COUNT4-NEXT: icmp
\r
35 ;///////////////////// TEST 2 //////////////////////////////
\r
37 ; This test shows that with optnone attribute, the loop is not unrolled
\r
38 ; even if an unroll factor was specified.
\r
40 define void @Test2() nounwind optnone noinline {
\r
45 %iv = phi i32 [ 0, %entry ], [ %inc, %loop ]
\r
46 %inc = add i32 %iv, 1
\r
47 %exitcnd = icmp uge i32 %inc, 1024
\r
48 br i1 %exitcnd, label %exit, label %loop
\r
54 ; CHECK_COUNT4-LABEL: @Test2
\r
56 ; CHECK_COUNT4-NEXT: add
\r
57 ; CHECK_COUNT4-NEXT: icmp
\r
60 ;///////////////////// TEST 3 //////////////////////////////
\r
62 ; This test shows that this loop is fully unrolled by default.
\r
64 @tab = common global [24 x i32] zeroinitializer, align 4
\r
66 define i32 @Test3() {
\r
70 for.body: ; preds = %for.body, %entry
\r
71 %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
\r
72 %arrayidx = getelementptr inbounds [24 x i32], [24 x i32]* @tab, i32 0, i32 %i.05
\r
73 store i32 %i.05, i32* %arrayidx, align 4
\r
74 %inc = add nuw nsw i32 %i.05, 1
\r
75 %exitcond = icmp eq i32 %inc, 24
\r
76 br i1 %exitcond, label %for.end, label %for.body
\r
78 for.end: ; preds = %for.body
\r
82 ; CHECK_NOCOUNT-LABEL: @Test3
\r
83 ; CHECK_NOCOUNT: store
\r
84 ; CHECK_NOCOUNT-NEXT: store
\r
85 ; CHECK_NOCOUNT-NEXT: store
\r
86 ; CHECK_NOCOUNT-NEXT: store
\r
87 ; CHECK_NOCOUNT-NEXT: store
\r
88 ; CHECK_NOCOUNT-NEXT: store
\r
89 ; CHECK_NOCOUNT-NEXT: store
\r
90 ; CHECK_NOCOUNT-NEXT: store
\r
91 ; CHECK_NOCOUNT-NEXT: store
\r
92 ; CHECK_NOCOUNT-NEXT: store
\r
93 ; CHECK_NOCOUNT-NEXT: store
\r
94 ; CHECK_NOCOUNT-NEXT: store
\r
95 ; CHECK_NOCOUNT-NEXT: store
\r
96 ; CHECK_NOCOUNT-NEXT: store
\r
97 ; CHECK_NOCOUNT-NEXT: store
\r
98 ; CHECK_NOCOUNT-NEXT: store
\r
99 ; CHECK_NOCOUNT-NEXT: store
\r
100 ; CHECK_NOCOUNT-NEXT: store
\r
101 ; CHECK_NOCOUNT-NEXT: store
\r
102 ; CHECK_NOCOUNT-NEXT: store
\r
103 ; CHECK_NOCOUNT-NEXT: store
\r
104 ; CHECK_NOCOUNT-NEXT: store
\r
105 ; CHECK_NOCOUNT-NEXT: store
\r
106 ; CHECK_NOCOUNT-NEXT: store
\r
107 ; CHECK_NOCOUNT-NEXT: ret
\r
110 ;///////////////////// TEST 4 //////////////////////////////
\r
112 ; This test shows that with optsize attribute, this loop is not unrolled.
\r
114 define i32 @Test4() optsize {
\r
118 for.body: ; preds = %for.body, %entry
\r
119 %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
\r
120 %arrayidx = getelementptr inbounds [24 x i32], [24 x i32]* @tab, i32 0, i32 %i.05
\r
121 store i32 %i.05, i32* %arrayidx, align 4
\r
122 %inc = add nuw nsw i32 %i.05, 1
\r
123 %exitcond = icmp eq i32 %inc, 24
\r
124 br i1 %exitcond, label %for.end, label %for.body
\r
126 for.end: ; preds = %for.body
\r
130 ; CHECK_NOCOUNT-LABEL: @Test4
\r
131 ; CHECK_NOCOUNT: phi
\r
132 ; CHECK_NOCOUNT: icmp
\r
134 ;///////////////////// TEST 5 //////////////////////////////
\r
136 ; This test shows that with PGO, this loop is cold and not unrolled.
\r
138 define i32 @Test5() !prof !14 {
\r
142 for.body: ; preds = %for.body, %entry
\r
143 %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
\r
144 %arrayidx = getelementptr inbounds [24 x i32], [24 x i32]* @tab, i32 0, i32 %i.05
\r
145 store i32 %i.05, i32* %arrayidx, align 4
\r
146 %inc = add nuw nsw i32 %i.05, 1
\r
147 %exitcond = icmp eq i32 %inc, 24
\r
148 br i1 %exitcond, label %for.end, label %for.body
\r
150 for.end: ; preds = %for.body
\r
154 ; PGSO-LABEL: @Test5
\r
157 ; NPGSO-LABEL: @Test5
\r
161 !llvm.module.flags = !{!0}
\r
162 !0 = !{i32 1, !"ProfileSummary", !1}
\r
163 !1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
\r
164 !2 = !{!"ProfileFormat", !"InstrProf"}
\r
165 !3 = !{!"TotalCount", i64 10000}
\r
166 !4 = !{!"MaxCount", i64 10}
\r
167 !5 = !{!"MaxInternalCount", i64 1}
\r
168 !6 = !{!"MaxFunctionCount", i64 1000}
\r
169 !7 = !{!"NumCounts", i64 3}
\r
170 !8 = !{!"NumFunctions", i64 3}
\r
171 !9 = !{!"DetailedSummary", !10}
\r
172 !10 = !{!11, !12, !13}
\r
173 !11 = !{i32 10000, i64 100, i32 1}
\r
174 !12 = !{i32 999000, i64 100, i32 1}
\r
175 !13 = !{i32 999999, i64 1, i32 2}
\r
176 !14 = !{!"function_entry_count", i64 0}
\r