1 ; RUN: opt -S -loop-fusion -pass-remarks-missed=loop-fusion -disable-output < %s 2>&1 | FileCheck %s
3 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
5 @B = common global [1024 x i32] zeroinitializer, align 16, !dbg !0
7 ; CHECK: remark: diagnostics_missed.c:18:3: [non_adjacent]: entry and for.end: Loops are not adjacent
8 define void @non_adjacent(i32* noalias %A) !dbg !67 {
12 for.cond: ; preds = %for.inc, %entry
13 %i.0 = phi i64 [ 0, %entry ], [ %inc, %for.inc ]
14 %exitcond1 = icmp ne i64 %i.0, 100
15 br i1 %exitcond1, label %for.body, label %for.cond.cleanup
17 for.cond.cleanup: ; preds = %for.cond
20 for.body: ; preds = %for.cond
21 %sub = add nsw i64 %i.0, -3
22 %add = add nuw nsw i64 %i.0, 3
23 %mul = mul nsw i64 %sub, %add
24 %rem = srem i64 %mul, %i.0
25 %conv = trunc i64 %rem to i32
26 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %i.0
27 store i32 %conv, i32* %arrayidx, align 4
30 for.inc: ; preds = %for.body
31 %inc = add nuw nsw i64 %i.0, 1, !dbg !86
32 br label %for.cond, !dbg !87, !llvm.loop !88
34 for.end: ; preds = %for.cond.cleanup
37 for.cond2: ; preds = %for.inc13, %for.end
38 %i1.0 = phi i64 [ 0, %for.end ], [ %inc14, %for.inc13 ]
39 %exitcond = icmp ne i64 %i1.0, 100
40 br i1 %exitcond, label %for.body6, label %for.cond.cleanup5
42 for.cond.cleanup5: ; preds = %for.cond2
45 for.body6: ; preds = %for.cond2
46 %sub7 = add nsw i64 %i1.0, -3
47 %add8 = add nuw nsw i64 %i1.0, 3
48 %mul9 = mul nsw i64 %sub7, %add8
49 %rem10 = srem i64 %mul9, %i1.0
50 %conv11 = trunc i64 %rem10 to i32
51 %arrayidx12 = getelementptr inbounds [1024 x i32], [1024 x i32]* @B, i64 0, i64 %i1.0
52 store i32 %conv11, i32* %arrayidx12, align 4
55 for.inc13: ; preds = %for.body6
56 %inc14 = add nuw nsw i64 %i1.0, 1, !dbg !100
57 br label %for.cond2, !dbg !101, !llvm.loop !102
59 for.end15: ; preds = %for.cond.cleanup5
64 ; CHECK: remark: diagnostics_missed.c:28:3: [different_bounds]: entry and for.end: Loop trip counts are not the same
65 define void @different_bounds(i32* noalias %A) !dbg !105 {
69 for.cond: ; preds = %for.inc, %entry
70 %i.0 = phi i64 [ 0, %entry ], [ %inc, %for.inc ]
71 %exitcond1 = icmp ne i64 %i.0, 100
72 br i1 %exitcond1, label %for.body, label %for.cond.cleanup
74 for.cond.cleanup: ; preds = %for.cond
77 for.body: ; preds = %for.cond
78 %sub = add nsw i64 %i.0, -3
79 %add = add nuw nsw i64 %i.0, 3
80 %mul = mul nsw i64 %sub, %add
81 %rem = srem i64 %mul, %i.0
82 %conv = trunc i64 %rem to i32
83 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %i.0
84 store i32 %conv, i32* %arrayidx, align 4
87 for.inc: ; preds = %for.body
88 %inc = add nuw nsw i64 %i.0, 1, !dbg !123
89 br label %for.cond, !dbg !124, !llvm.loop !125
91 for.end: ; preds = %for.cond.cleanup
94 for.cond2: ; preds = %for.inc13, %for.end
95 %i1.0 = phi i64 [ 0, %for.end ], [ %inc14, %for.inc13 ]
96 %exitcond = icmp ne i64 %i1.0, 200
97 br i1 %exitcond, label %for.body6, label %for.cond.cleanup5
99 for.cond.cleanup5: ; preds = %for.cond2
102 for.body6: ; preds = %for.cond2
103 %sub7 = add nsw i64 %i1.0, -3
104 %add8 = add nuw nsw i64 %i1.0, 3
105 %mul9 = mul nsw i64 %sub7, %add8
106 %rem10 = srem i64 %mul9, %i1.0
107 %conv11 = trunc i64 %rem10 to i32
108 %arrayidx12 = getelementptr inbounds [1024 x i32], [1024 x i32]* @B, i64 0, i64 %i1.0
109 store i32 %conv11, i32* %arrayidx12, align 4
112 for.inc13: ; preds = %for.body6
113 %inc14 = add nuw nsw i64 %i1.0, 1
114 br label %for.cond2, !dbg !138, !llvm.loop !139
116 for.end15: ; preds = %for.cond.cleanup5
120 ; CHECK: remark: diagnostics_missed.c:38:3: [negative_dependence]: entry and for.end: Loop has a non-empty preheader
121 define void @negative_dependence(i32* noalias %A) !dbg !142 {
125 for.cond: ; preds = %for.inc, %entry
126 %indvars.iv1 = phi i64 [ %indvars.iv.next2, %for.inc ], [ 0, %entry ]
127 %exitcond3 = icmp ne i64 %indvars.iv1, 100
128 br i1 %exitcond3, label %for.body, label %for.end
130 for.body: ; preds = %for.cond
131 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv1
132 %tmp = trunc i64 %indvars.iv1 to i32
133 store i32 %tmp, i32* %arrayidx, align 4
136 for.inc: ; preds = %for.body
137 %indvars.iv.next2 = add nuw nsw i64 %indvars.iv1, 1
138 br label %for.cond, !dbg !160, !llvm.loop !161
140 for.end: ; preds = %for.cond
141 call void @llvm.dbg.value(metadata i32 0, metadata !147, metadata !DIExpression()), !dbg !163
142 br label %for.cond2, !dbg !164
144 for.cond2: ; preds = %for.inc10, %for.end
145 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc10 ], [ 0, %for.end ]
146 %exitcond = icmp ne i64 %indvars.iv, 100
147 br i1 %exitcond, label %for.body5, label %for.end12
149 for.body5: ; preds = %for.cond2
150 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
151 %arrayidx7 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv.next
152 %tmp4 = load i32, i32* %arrayidx7, align 4
153 %mul = shl nsw i32 %tmp4, 1
154 %arrayidx9 = getelementptr inbounds [1024 x i32], [1024 x i32]* @B, i64 0, i64 %indvars.iv
155 store i32 %mul, i32* %arrayidx9, align 4
158 for.inc10: ; preds = %for.body5
161 for.end12: ; preds = %for.cond.
165 ; CHECK: remark: diagnostics_missed.c:51:3: [sumTest]: entry and for.cond2.preheader: Dependencies prevent fusion
166 define i32 @sumTest(i32* noalias %A) !dbg !179 {
170 for.cond: ; preds = %for.inc, %entry
171 %indvars.iv1 = phi i64 [ %indvars.iv.next2, %for.inc ], [ 0, %entry ]
172 %sum.0 = phi i32 [ 0, %entry ], [ %add, %for.inc ]
173 %exitcond3 = icmp ne i64 %indvars.iv1, 100
174 br i1 %exitcond3, label %for.body, label %for.cond2
176 for.body: ; preds = %for.cond
179 for.inc: ; preds = %for.body
180 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv1
181 %tmp = load i32, i32* %arrayidx, align 4
182 %add = add nsw i32 %sum.0, %tmp
183 %indvars.iv.next2 = add nuw nsw i64 %indvars.iv1, 1
184 br label %for.cond, !dbg !199, !llvm.loop !200
186 for.cond2: ; preds = %for.inc10, %for.cond
187 %sum.0.lcssa = phi i32 [ %sum.0, %for.cond ], [ %sum.0.lcssa, %for.inc10 ]
188 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc10 ], [ 0, %for.cond ]
189 %exitcond = icmp ne i64 %indvars.iv, 100
190 br i1 %exitcond, label %for.body5, label %for.end12
192 for.body5: ; preds = %for.cond2
193 %arrayidx7 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
194 %tmp4 = load i32, i32* %arrayidx7, align 4
195 %div = sdiv i32 %tmp4, %sum.0.lcssa
196 %arrayidx9 = getelementptr inbounds [1024 x i32], [1024 x i32]* @B, i64 0, i64 %indvars.iv
197 store i32 %div, i32* %arrayidx9, align 4
200 for.inc10: ; preds = %for.body5
201 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
204 for.end12: ; preds = %for.cond2
205 ret i32 %sum.0.lcssa, !dbg !215
208 declare void @llvm.dbg.value(metadata, metadata, metadata)
212 !llvm.module.flags = !{!11, !12, !13, !14}
214 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
215 !1 = distinct !DIGlobalVariable(name: "B", scope: !2, file: !6, line: 46, type: !7, isLocal: false, isDefinition: true)
216 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 9.0.0 (git@github.ibm.com:compiler/llvm-project.git 23c4baaa9f5b33d2d52eda981d376c6b0a7a3180)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: GNU)
217 !3 = !DIFile(filename: "diagnostics_missed.c", directory: "/tmp")
220 !6 = !DIFile(filename: "diagnostics_missed.c", directory: "/tmp")
221 !7 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 32768, elements: !9)
222 !8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
224 !10 = !DISubrange(count: 1024)
225 !11 = !{i32 2, !"Dwarf Version", i32 4}
226 !12 = !{i32 2, !"Debug Info Version", i32 3}
227 !13 = !{i32 1, !"wchar_size", i32 4}
228 !14 = !{i32 7, !"PIC Level", i32 2}
229 !17 = !DISubroutineType(types: !18)
231 !19 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !20)
232 !20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
233 !67 = distinct !DISubprogram(name: "non_adjacent", scope: !6, file: !6, line: 17, type: !17, scopeLine: 17, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !68)
234 !68 = !{!69, !70, !73}
235 !69 = !DILocalVariable(name: "A", arg: 1, scope: !67, file: !6, line: 17, type: !19)
236 !70 = !DILocalVariable(name: "i", scope: !71, file: !6, line: 18, type: !72)
237 !71 = distinct !DILexicalBlock(scope: !67, file: !6, line: 18, column: 3)
238 !72 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
239 !73 = !DILocalVariable(name: "i", scope: !74, file: !6, line: 22, type: !72)
240 !74 = distinct !DILexicalBlock(scope: !67, file: !6, line: 22, column: 3)
241 !79 = distinct !DILexicalBlock(scope: !71, file: !6, line: 18, column: 3)
242 !80 = !DILocation(line: 18, column: 3, scope: !71)
243 !86 = !DILocation(line: 18, column: 30, scope: !79)
244 !87 = !DILocation(line: 18, column: 3, scope: !79)
245 !88 = distinct !{!88, !80, !89}
246 !89 = !DILocation(line: 20, column: 3, scope: !71)
247 !93 = distinct !DILexicalBlock(scope: !74, file: !6, line: 22, column: 3)
248 !94 = !DILocation(line: 22, column: 3, scope: !74)
249 !100 = !DILocation(line: 22, column: 30, scope: !93)
250 !101 = !DILocation(line: 22, column: 3, scope: !93)
251 !102 = distinct !{!102, !94, !103}
252 !103 = !DILocation(line: 24, column: 3, scope: !74)
253 !105 = distinct !DISubprogram(name: "different_bounds", scope: !6, file: !6, line: 27, type: !17, scopeLine: 27, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !106)
254 !106 = !{!107, !108, !110}
255 !107 = !DILocalVariable(name: "A", arg: 1, scope: !105, file: !6, line: 27, type: !19)
256 !108 = !DILocalVariable(name: "i", scope: !109, file: !6, line: 28, type: !72)
257 !109 = distinct !DILexicalBlock(scope: !105, file: !6, line: 28, column: 3)
258 !110 = !DILocalVariable(name: "i", scope: !111, file: !6, line: 32, type: !72)
259 !111 = distinct !DILexicalBlock(scope: !105, file: !6, line: 32, column: 3)
260 !116 = distinct !DILexicalBlock(scope: !109, file: !6, line: 28, column: 3)
261 !117 = !DILocation(line: 28, column: 3, scope: !109)
262 !123 = !DILocation(line: 28, column: 30, scope: !116)
263 !124 = !DILocation(line: 28, column: 3, scope: !116)
264 !125 = distinct !{!125, !117, !126}
265 !126 = !DILocation(line: 30, column: 3, scope: !109)
266 !130 = distinct !DILexicalBlock(scope: !111, file: !6, line: 32, column: 3)
267 !131 = !DILocation(line: 32, column: 3, scope: !111)
268 !138 = !DILocation(line: 32, column: 3, scope: !130)
269 !139 = distinct !{!139, !131, !140}
270 !140 = !DILocation(line: 34, column: 3, scope: !111)
271 !142 = distinct !DISubprogram(name: "negative_dependence", scope: !6, file: !6, line: 37, type: !17, scopeLine: 37, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !143)
272 !143 = !{!144, !145, !147}
273 !144 = !DILocalVariable(name: "A", arg: 1, scope: !142, file: !6, line: 37, type: !19)
274 !145 = !DILocalVariable(name: "i", scope: !146, file: !6, line: 38, type: !8)
275 !146 = distinct !DILexicalBlock(scope: !142, file: !6, line: 38, column: 3)
276 !147 = !DILocalVariable(name: "i", scope: !148, file: !6, line: 42, type: !8)
277 !148 = distinct !DILexicalBlock(scope: !142, file: !6, line: 42, column: 3)
278 !153 = distinct !DILexicalBlock(scope: !146, file: !6, line: 38, column: 3)
279 !154 = !DILocation(line: 38, column: 3, scope: !146)
280 !160 = !DILocation(line: 38, column: 3, scope: !153)
281 !161 = distinct !{!161, !154, !162}
282 !162 = !DILocation(line: 40, column: 3, scope: !146)
283 !163 = !DILocation(line: 0, scope: !148)
284 !164 = !DILocation(line: 42, column: 8, scope: !148)
285 !178 = !DILocation(line: 45, column: 1, scope: !142)
286 !179 = distinct !DISubprogram(name: "sumTest", scope: !6, file: !6, line: 48, type: !180, scopeLine: 48, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !182)
287 !180 = !DISubroutineType(types: !181)
289 !182 = !{!183, !184, !185, !187}
290 !183 = !DILocalVariable(name: "A", arg: 1, scope: !179, file: !6, line: 48, type: !19)
291 !184 = !DILocalVariable(name: "sum", scope: !179, file: !6, line: 49, type: !8)
292 !185 = !DILocalVariable(name: "i", scope: !186, file: !6, line: 51, type: !8)
293 !186 = distinct !DILexicalBlock(scope: !179, file: !6, line: 51, column: 3)
294 !187 = !DILocalVariable(name: "i", scope: !188, file: !6, line: 54, type: !8)
295 !188 = distinct !DILexicalBlock(scope: !179, file: !6, line: 54, column: 3)
296 !193 = distinct !DILexicalBlock(scope: !186, file: !6, line: 51, column: 3)
297 !194 = !DILocation(line: 51, column: 3, scope: !186)
298 !199 = !DILocation(line: 51, column: 3, scope: !193)
299 !200 = distinct !{!200, !194, !201}
300 !201 = !DILocation(line: 52, column: 15, scope: !186)
301 !215 = !DILocation(line: 57, column: 3, scope: !179)