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