1 ; RUN: opt -S -passes=loop-rotate -verify-memoryssa < %s | FileCheck %s --implicit-check-not=dbg.value
2 ; RUN: opt -S -passes=loop-rotate -verify-memoryssa < %s --try-experimental-debuginfo-iterators | FileCheck %s --implicit-check-not=dbg.value
4 declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
5 declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone
7 ; CHECK: declare void @llvm.dbg.value(metadata,
9 ; This function rotates the exit conditon into the entry block, moving the
10 ; dbg.values with it. Check that they resolve through the PHIs to the arguments
11 ; only in the entry block. In the loop block, the dbg.values shift down below
12 ; the calls and resolve to them. Then even more dbg.values are inserted on the
13 ; newly produced PHIs at the start.
15 define i32 @tak(i32 %x, i32 %y, i32 %z) nounwind ssp !dbg !0 {
16 ; CHECK-LABEL: define i32 @tak(
18 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %x
19 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %y
20 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %z
21 ; CHECK: if.then.lr.ph:
23 ; CHECK-NEXT: %z.tr4 = phi
24 ; CHECK-NEXT: %y.tr3 = phi
25 ; CHECK-NEXT: %x.tr2 = phi
26 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %z.tr4
27 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %y.tr3
28 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %x.tr2
29 ; CHECK: %call = tail call i32 @tak(i32
30 ; CHECK: %call9 = tail call i32 @tak(i32
31 ; CHECK: %call14 = tail call i32 @tak(i32
32 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %call
33 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %call9
34 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %call14
38 tailrecurse: ; preds = %if.then, %entry
39 %x.tr = phi i32 [ %x, %entry ], [ %call, %if.then ]
40 %y.tr = phi i32 [ %y, %entry ], [ %call9, %if.then ]
41 %z.tr = phi i32 [ %z, %entry ], [ %call14, %if.then ]
42 tail call void @llvm.dbg.value(metadata i32 %x.tr, metadata !6, metadata !DIExpression()), !dbg !7
43 tail call void @llvm.dbg.value(metadata i32 %y.tr, metadata !8, metadata !DIExpression()), !dbg !9
44 tail call void @llvm.dbg.value(metadata i32 %z.tr, metadata !10, metadata !DIExpression()), !dbg !11
45 %cmp = icmp slt i32 %y.tr, %x.tr, !dbg !12
46 br i1 %cmp, label %if.then, label %if.end, !dbg !12
48 if.then: ; preds = %tailrecurse
49 %sub = sub nsw i32 %x.tr, 1, !dbg !14
50 %call = tail call i32 @tak(i32 %sub, i32 %y.tr, i32 %z.tr), !dbg !14
51 %sub6 = sub nsw i32 %y.tr, 1, !dbg !14
52 %call9 = tail call i32 @tak(i32 %sub6, i32 %z.tr, i32 %x.tr), !dbg !14
53 %sub11 = sub nsw i32 %z.tr, 1, !dbg !14
54 %call14 = tail call i32 @tak(i32 %sub11, i32 %x.tr, i32 %y.tr), !dbg !14
57 if.end: ; preds = %tailrecurse
58 br label %return, !dbg !16
60 return: ; preds = %if.end
61 ret i32 %z.tr, !dbg !17
64 ; Repeat of the tak function, with only one DILocalVariable, checking that we
65 ; don't insert duplicate debug intrinsics. The initial duplicates are preserved.
66 ; FIXME: this test checks for the de-duplication behaviour that loop-rotate
67 ; has today, however it might not be correct. In the if.then block the preserved
68 ; dbg.value is for %x -- should not the _last_dbg.value, for %z, have been
70 define i32 @tak_dup(i32 %x, i32 %y, i32 %z) nounwind ssp !dbg !50 {
71 ; CHECK-LABEL: define i32 @tak_dup(
73 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %x
74 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %y
75 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %z
76 ; CHECK: if.then.lr.ph:
78 ; CHECK-NEXT: %z.tr4 = phi
79 ; CHECK-NEXT: %y.tr3 = phi
80 ; CHECK-NEXT: %x.tr2 = phi
81 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %x.tr2
82 ; CHECK: %call = tail call i32 @tak(i32
83 ; CHECK: %call9 = tail call i32 @tak(i32
84 ; CHECK: %call14 = tail call i32 @tak(i32
85 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %call14
89 tailrecurse: ; preds = %if.then, %entry
90 %x.tr = phi i32 [ %x, %entry ], [ %call, %if.then ]
91 %y.tr = phi i32 [ %y, %entry ], [ %call9, %if.then ]
92 %z.tr = phi i32 [ %z, %entry ], [ %call14, %if.then ]
93 tail call void @llvm.dbg.value(metadata i32 %x.tr, metadata !60, metadata !DIExpression()), !dbg !61
94 tail call void @llvm.dbg.value(metadata i32 %y.tr, metadata !60, metadata !DIExpression()), !dbg !61
95 tail call void @llvm.dbg.value(metadata i32 %z.tr, metadata !60, metadata !DIExpression()), !dbg !61
96 %cmp = icmp slt i32 %y.tr, %x.tr, !dbg !62
97 br i1 %cmp, label %if.then, label %if.end, !dbg !62
99 if.then: ; preds = %tailrecurse
100 %sub = sub nsw i32 %x.tr, 1, !dbg !64
101 %call = tail call i32 @tak(i32 %sub, i32 %y.tr, i32 %z.tr), !dbg !64
102 %sub6 = sub nsw i32 %y.tr, 1, !dbg !64
103 %call9 = tail call i32 @tak(i32 %sub6, i32 %z.tr, i32 %x.tr), !dbg !64
104 %sub11 = sub nsw i32 %z.tr, 1, !dbg !64
105 %call14 = tail call i32 @tak(i32 %sub11, i32 %x.tr, i32 %y.tr), !dbg !64
106 br label %tailrecurse
108 if.end: ; preds = %tailrecurse
109 br label %return, !dbg !66
111 return: ; preds = %if.end
112 ret i32 %z.tr, !dbg !67
115 ; Check that the dbg.values move up to being immediately below the PHIs,
116 ; using their Values. However once we exit the loop, the x and y values
117 ; become irrelevant and undef, only z gets an LCSSA PHI to preserve it.
119 ; Note that while the icmp is initially undominated by any dbg.value and thus
120 ; shouldn't get a variable location, the first iteration is peeled off into the
121 ; entry block. It's then safe to have it dominated by subsequent dbg.values as
122 ; every path to the icmp is preceeded by a dbg.value.
124 ; FIXME: could we choose to preserve more information about the loop, x and y
125 ; might not be live out of the loop, but they might still be dominated by a
128 define i32 @tak2(i32 %x, i32 %y, i32 %z) nounwind ssp !dbg !21 {
129 ; CHECK-LABEL: define i32 @tak2(
131 ; CHECK-NEXT: %z.tr4 = phi i32
132 ; CHECK-NEXT: %y.tr3 = phi i32
133 ; CHECK-NEXT: %x.tr2 = phi i32
134 ; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i32 %x.tr2
135 ; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i32 %y.tr3
136 ; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i32 %z.tr4
137 ; CHECK: tail call i32 @tak(i32
138 ; CHECK: tail call i32 @tak(i32
139 ; CHECK: tail call i32 @tak(i32
141 ; CHECK-NEXT: z.tr.lcssa = phi i32
142 ; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i32 undef
143 ; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i32 undef
144 ; CHECK-NEXT: tail call void @llvm.dbg.value(metadata i32 %z.tr.lcssa
146 br label %tailrecurse
148 tailrecurse: ; preds = %if.then, %entry
149 %x.tr = phi i32 [ %x, %entry ], [ %call, %if.then ]
150 %y.tr = phi i32 [ %y, %entry ], [ %call9, %if.then ]
151 %z.tr = phi i32 [ %z, %entry ], [ %call14, %if.then ]
152 %cmp = icmp slt i32 %y.tr, %x.tr, !dbg !22
153 br i1 %cmp, label %if.then, label %if.end, !dbg !22
155 if.then: ; preds = %tailrecurse
156 tail call void @llvm.dbg.value(metadata i32 %x.tr, metadata !36, metadata !DIExpression()), !dbg !37
157 tail call void @llvm.dbg.value(metadata i32 %y.tr, metadata !38, metadata !DIExpression()), !dbg !39
158 tail call void @llvm.dbg.value(metadata i32 %z.tr, metadata !40, metadata !DIExpression()), !dbg !41
159 %sub = sub nsw i32 %x.tr, 1, !dbg !24
160 %call = tail call i32 @tak(i32 %sub, i32 %y.tr, i32 %z.tr), !dbg !24
161 %sub6 = sub nsw i32 %y.tr, 1, !dbg !24
162 %call9 = tail call i32 @tak(i32 %sub6, i32 %z.tr, i32 %x.tr), !dbg !24
163 %sub11 = sub nsw i32 %z.tr, 1, !dbg !24
164 %call14 = tail call i32 @tak(i32 %sub11, i32 %x.tr, i32 %y.tr), !dbg !24
165 br label %tailrecurse
167 if.end: ; preds = %tailrecurse
168 tail call void @llvm.dbg.value(metadata i32 %x.tr, metadata !36, metadata !DIExpression()), !dbg !37
169 tail call void @llvm.dbg.value(metadata i32 %y.tr, metadata !38, metadata !DIExpression()), !dbg !39
170 tail call void @llvm.dbg.value(metadata i32 %z.tr, metadata !40, metadata !DIExpression()), !dbg !41
171 br label %return, !dbg !26
173 return: ; preds = %if.end
174 ret i32 %z.tr, !dbg !27
177 @channelColumns = external global i64
178 @horzPlane = external global ptr, align 8
180 define void @FindFreeHorzSeg(i64 %startCol, i64 %row, ptr %rowStart) {
181 ; Ensure that the loop increment basic block is rotated into the tail of the
182 ; body, even though it contains a debug intrinsic call.
183 ; CHECK-LABEL: define void @FindFreeHorzSeg(
185 ; CHECK-NEXT: tail call void @llvm.dbg.value
188 ; CHECK: phi i64 [ %{{[^,]*}}, %{{[^,]*}} ]
189 ; CHECK-NEXT: br label %for.end
196 %i.0 = phi i64 [ %startCol, %entry ], [ %dec, %for.inc ]
197 %cmp = icmp eq i64 %i.0, 0
198 br i1 %cmp, label %for.end, label %for.body
201 %0 = load i64, ptr @channelColumns, align 8
202 %mul = mul i64 %0, %row
203 %add = add i64 %mul, %i.0
204 %1 = load ptr, ptr @horzPlane, align 8
205 %arrayidx = getelementptr inbounds i8, ptr %1, i64 %add
206 %2 = load i8, ptr %arrayidx, align 1
207 %tobool = icmp eq i8 %2, 0
208 br i1 %tobool, label %for.inc, label %for.end
211 %dec = add i64 %i.0, -1
212 tail call void @llvm.dbg.value(metadata i64 %dec, metadata !DILocalVariable(scope: !0), metadata !DIExpression()), !dbg !DILocation(scope: !0)
216 %add1 = add i64 %i.0, 1
217 store i64 %add1, ptr %rowStart, align 8
221 ; Test that dbg.value intrinsincs adjacent to the `icmp slt i32 0, 0` get
222 ; rotated as expected. The icmp is loop-invariant and so gets hoisted to the
223 ; preheader via a different code path. This is more difficult for DPValue
224 ; debug-info records to handle, because they have to get detached and moved
225 ; somewhere else during rotation.
226 define void @invariant_hoist() !dbg !70 {
227 ; CHECK-LABEL: define void @invariant_hoist()
229 ; CHECK-NEXT: br label %L0.preheader
230 ; CHECK: L0.preheader:
231 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 0,
232 ; CHECK-NEXT: %cmp = icmp slt i32 0, 0,
233 ; CHECK: L1.preheader:
234 ; CHECK-NEXT: %spec.select3 = phi i32
235 ; CHECK-NEXT: %k.02 = phi i32
236 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %k.02,
238 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %spec.select3,
240 br label %L0.preheader, !dbg !77
243 br label %L0, !dbg !77
246 %k.0 = phi i32 [ 0, %L0.preheader ], [ %spec.select, %L0.latch ]
247 call void @llvm.dbg.value(metadata i32 %k.0, metadata !80, metadata !DIExpression()), !dbg !77
248 %cmp = icmp slt i32 0, 0, !dbg !77
249 %inc = zext i1 %cmp to i32, !dbg !77
250 %spec.select = add nsw i32 %k.0, %inc, !dbg !77
251 %tobool3.not = icmp eq i32 %spec.select, 0, !dbg !77
252 br i1 %tobool3.not, label %L0.preheader, label %L1.preheader, !dbg !77
255 %tobool8.not = icmp eq i32 %k.0, 0, !dbg !77
256 br label %L1, !dbg !77
259 br i1 %tobool8.not, label %L1.latch, label %L0.latch, !dbg !77
262 br i1 false, label %L1, label %L0.latch, !dbg !77
265 br label %L0, !dbg !77
268 !llvm.module.flags = !{!20}
271 !0 = distinct !DISubprogram(name: "tak", line: 32, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !18, scope: !1, type: !3)
272 !1 = !DIFile(filename: "/Volumes/Lalgate/cj/llvm/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame/recursive.c", directory: "/Volumes/Lalgate/cj/D/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame")
273 !2 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 2.9 (trunk 125492)", isOptimized: true, emissionKind: FullDebug, file: !18)
274 !3 = !DISubroutineType(types: !4)
276 !5 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
277 !6 = !DILocalVariable(name: "x", line: 32, arg: 1, scope: !0, file: !1, type: !5)
278 !7 = !DILocation(line: 32, column: 13, scope: !0)
279 !8 = !DILocalVariable(name: "y", line: 32, arg: 2, scope: !0, file: !1, type: !5)
280 !9 = !DILocation(line: 32, column: 20, scope: !0)
281 !10 = !DILocalVariable(name: "z", line: 32, arg: 3, scope: !0, file: !1, type: !5)
282 !11 = !DILocation(line: 32, column: 27, scope: !0)
283 !12 = !DILocation(line: 33, column: 3, scope: !13)
284 !13 = distinct !DILexicalBlock(line: 32, column: 30, file: !18, scope: !0)
285 !14 = !DILocation(line: 34, column: 5, scope: !15)
286 !15 = distinct !DILexicalBlock(line: 33, column: 14, file: !18, scope: !13)
287 !16 = !DILocation(line: 36, column: 3, scope: !13)
288 !17 = !DILocation(line: 37, column: 1, scope: !13)
289 !18 = !DIFile(filename: "/Volumes/Lalgate/cj/llvm/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame/recursive.c", directory: "/Volumes/Lalgate/cj/D/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame")
290 !20 = !{i32 1, !"Debug Info Version", i32 3}
291 !21 = distinct !DISubprogram(name: "tak", line: 32, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !18, scope: !1, type: !3)
292 !22 = !DILocation(line: 33, column: 3, scope: !23)
293 !23 = distinct !DILexicalBlock(line: 32, column: 30, file: !18, scope: !21)
294 !24 = !DILocation(line: 34, column: 5, scope: !25)
295 !25 = distinct !DILexicalBlock(line: 33, column: 14, file: !18, scope: !23)
296 !26 = !DILocation(line: 36, column: 3, scope: !23)
297 !27 = !DILocation(line: 37, column: 1, scope: !23)
298 !36 = !DILocalVariable(name: "x", line: 32, arg: 1, scope: !21, file: !1, type: !5)
299 !37 = !DILocation(line: 32, column: 13, scope: !21)
300 !38 = !DILocalVariable(name: "y", line: 32, arg: 2, scope: !21, file: !1, type: !5)
301 !39 = !DILocation(line: 32, column: 20, scope: !21)
302 !40 = !DILocalVariable(name: "z", line: 32, arg: 3, scope: !21, file: !1, type: !5)
303 !41 = !DILocation(line: 32, column: 27, scope: !21)
304 !50 = distinct !DISubprogram(name: "tak_dup", line: 32, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !18, scope: !1, type: !3)
305 !57 = !DILocation(line: 32, column: 13, scope: !50)
306 !59 = !DILocation(line: 32, column: 20, scope: !50)
307 !60 = !DILocalVariable(name: "z", line: 32, arg: 3, scope: !50, file: !1, type: !5)
308 !61 = !DILocation(line: 32, column: 27, scope: !50)
309 !62 = !DILocation(line: 33, column: 3, scope: !63)
310 !63 = distinct !DILexicalBlock(line: 32, column: 30, file: !18, scope: !50)
311 !64 = !DILocation(line: 34, column: 5, scope: !65)
312 !65 = distinct !DILexicalBlock(line: 33, column: 14, file: !18, scope: !63)
313 !66 = !DILocation(line: 36, column: 3, scope: !63)
314 !67 = !DILocation(line: 37, column: 1, scope: !63)
315 !70 = distinct !DISubprogram(name: "invariant_hoist", line: 32, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !18, scope: !1, type: !3)
316 !77 = !DILocation(line: 32, column: 13, scope: !70)
317 !79 = !DILocation(line: 32, column: 20, scope: !70)
318 !80 = !DILocalVariable(name: "z", line: 32, arg: 3, scope: !70, file: !1, type: !5)
319 !81 = !DILocation(line: 32, column: 27, scope: !70)
320 !82 = !DILocation(line: 33, column: 3, scope: !83)
321 !83 = distinct !DILexicalBlock(line: 32, column: 30, file: !18, scope: !70)
322 !84 = !DILocation(line: 34, column: 5, scope: !85)
323 !85 = distinct !DILexicalBlock(line: 33, column: 14, file: !18, scope: !83)
324 !86 = !DILocation(line: 36, column: 3, scope: !83)
325 !87 = !DILocation(line: 37, column: 1, scope: !83)