1 ; RUN: opt -S -passes=jump-threading < %s | FileCheck %s
2 ; RUN: opt -S -passes=jump-threading < %s --try-experimental-debuginfo-iterators | FileCheck %s
4 @a = global i32 0, align 4
5 ; Test that the llvm.dbg.value calls in a threaded block are correctly updated to
6 ; target the locals in their threaded block, and not the unthreaded one.
7 define void @test1(i32 %cond1, i32 %cond2) {
8 ; CHECK: [[globalptr:@.*]] = global i32 0, align 4
10 ; CHECK: #dbg_value(ptr null, ![[DBG1ptr:[0-9]+]], !DIExpression(), ![[DBG2ptr:[0-9]+]]
11 ; CHECK-NEXT: [[TOBOOL1:%.*]] = icmp eq i32 %cond2, 0, !dbg ![[DBGLOCtobool1:[0-9]+]]
12 ; CHECK-NEXT: #dbg_value(!DIArgList(ptr null, i1 [[TOBOOL1]], i1 [[TOBOOL1]]), !{{[0-9]+}}, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_LLVM_arg, 2, DW_OP_plus), !{{[0-9]+}}
13 ; CHECK: bb.cond2.thread:
14 ; CHECK-NEXT: #dbg_value(ptr [[globalptr]], ![[DBG1ptr]], !DIExpression(), ![[DBG2ptr]]
15 ; CHECK-NEXT: [[TOBOOL12:%.*]] = icmp eq i32 %cond2, 0, !dbg ![[DBGLOCtobool1]]
16 ; CHECK-NEXT: #dbg_value(!DIArgList(ptr [[globalptr]], i1 [[TOBOOL12]], i1 [[TOBOOL12]]), !{{[0-9]+}}, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_LLVM_arg, 2, DW_OP_plus), !{{[0-9]+}}
18 %tobool = icmp eq i32 %cond1, 0, !dbg !15
19 call void @llvm.dbg.value(metadata i1 %tobool, metadata !9, metadata !DIExpression()), !dbg !15
20 br i1 %tobool, label %bb.cond2, label %bb.f1, !dbg !16
22 bb.f1: ; preds = %entry
23 call void @f1(), !dbg !17
24 br label %bb.cond2, !dbg !18
26 bb.cond2: ; preds = %bb.f1, %entry
27 %ptr = phi ptr [ null, %bb.f1 ], [ @a, %entry ], !dbg !19
28 call void @llvm.dbg.value(metadata ptr %ptr, metadata !11, metadata !DIExpression()), !dbg !19
29 %tobool1 = icmp eq i32 %cond2, 0, !dbg !20
30 call void @llvm.dbg.value(metadata !DIArgList(ptr %ptr, i1 %tobool1, i1 %tobool1), metadata !13, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_LLVM_arg, 2, DW_OP_plus)), !dbg !20
31 br i1 %tobool1, label %bb.file, label %bb.f2, !dbg !21
33 bb.f2: ; preds = %bb.cond2
34 call void @f2(), !dbg !22
35 br label %exit, !dbg !23
37 bb.file: ; preds = %bb.cond2
38 %cmp = icmp eq ptr %ptr, null, !dbg !24
39 call void @llvm.dbg.value(metadata i1 %cmp, metadata !14, metadata !DIExpression()), !dbg !24
40 br i1 %cmp, label %bb.f4, label %bb.f3, !dbg !25
42 bb.f3: ; preds = %bb.file
43 br label %exit, !dbg !26
45 bb.f4: ; preds = %bb.file
46 call void @f4(), !dbg !27
47 br label %exit, !dbg !28
49 exit: ; preds = %bb.f4, %bb.f3, %bb.f2
53 ; This is testing for debug value instrinsics outside of the threaded block pointing to a value
54 ; inside to correctly take any new definitions.
55 define void @test2(i32 %cond1, i32 %cond2) !dbg !5 {
57 ; CHECK: #dbg_value(ptr @a, !{{[0-9]+}}, !DIExpression(), !{{[0-9]+}}
59 ; CHECK-NEXT: [[PTR3:%.*]] = phi ptr [ null, %bb.cond2 ]
60 ; CHECK-NEXT: #dbg_value(ptr [[PTR3]], !{{[0-9]+}}, !DIExpression(), !{{[0-9]+}}
62 %tobool = icmp eq i32 %cond1, 0, !dbg !15
63 br i1 %tobool, label %bb.cond2, label %bb.f1, !dbg !16
65 bb.f1: ; preds = %entry
66 call void @f1(), !dbg !17
67 br label %bb.cond2, !dbg !18
69 bb.cond2: ; preds = %bb.f1, %entry
70 %ptr = phi ptr [ null, %bb.f1 ], [ @a, %entry ], !dbg !19
71 %tobool1 = icmp eq i32 %cond2, 0, !dbg !20
72 br i1 %tobool1, label %bb.file, label %bb.f2, !dbg !21
74 bb.f2: ; preds = %bb.cond2
75 call void @f2(), !dbg !22
76 br label %exit, !dbg !23
78 bb.file: ; preds = %bb.cond2
79 %cmp = icmp eq ptr %ptr, null, !dbg !24
80 call void @llvm.dbg.value(metadata ptr %ptr, metadata !14, metadata !DIExpression()), !dbg !21
81 br i1 %cmp, label %bb.f4, label %bb.f3, !dbg !25
83 bb.f3: ; preds = %bb.file
84 call void @f3(), !dbg !26
85 br label %exit, !dbg !27
87 bb.f4: ; preds = %bb.file
88 call void @f4(), !dbg !28
89 br label %exit, !dbg !29
91 exit: ; preds = %bb.f4, %bb.f3, %bb.f2
95 ; Test for the cloning of dbg.values on elided instructions -- down one path
96 ; being threaded, the `and` in the function below is optimised away, but its
97 ; debug-info should still be preserved.
98 ; Similarly, the call to f1 gets cloned, its dbg.value should be cloned too.
99 define void @test16(i1 %c, i1 %c2, i1 %c3, i1 %c4) nounwind ssp !dbg !30 {
100 ; CHECK-LABEL: define void @test16(i1
102 %cmp = icmp sgt i32 undef, 1, !dbg !33
103 br i1 %c, label %land.end, label %land.rhs, !dbg !33
106 br i1 %c2, label %lor.lhs.false.i, label %land.end, !dbg !33
109 br i1 %c3, label %land.end, label %land.end, !dbg !33
111 ; CHECK-LABEL: land.end.thr_comm:
112 ; CHECK-NEXT: #dbg_value(i32 0,
113 ; CHECK-NEXT: #dbg_value(i32 1,
114 ; CHECK-NEXT: call void @f1()
115 ; CHECK-NEXT: br i1 %c4,
117 ; CHECK-LABEL: land.end:
118 ; CHECK-NEXT: %0 = phi i1
119 ; CHECK-NEXT: #dbg_value(i32 0,
121 %0 = phi i1 [ true, %entry ], [ false, %land.rhs ], [false, %lor.lhs.false.i], [false, %lor.lhs.false.i]
122 call void @llvm.dbg.value(metadata i32 0, metadata !32, metadata !DIExpression()), !dbg !33
123 %cmp12 = and i1 %cmp, %0, !dbg !33
124 %xor1 = xor i1 %cmp12, %c4, !dbg !33
125 call void @llvm.dbg.value(metadata i32 1, metadata !32, metadata !DIExpression()), !dbg !33
127 br i1 %xor1, label %if.then, label %if.end, !dbg !33
144 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
145 declare void @llvm.dbg.value(metadata, metadata, metadata) #0
147 attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
150 !llvm.debugify = !{!2, !3}
151 !llvm.module.flags = !{!4}
153 !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
154 !1 = !DIFile(filename: "/home/ben/Documents/llvm-project/llvm/test/Transforms/JumpThreading/thread-debug-info.ll", directory: "/")
157 !4 = !{i32 2, !"Debug Info Version", i32 3}
158 !5 = distinct !DISubprogram(name: "test2", linkageName: "test2", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
159 !6 = !DISubroutineType(types: !7)
161 !8 = !{!9, !11, !13, !14}
162 !9 = !DILocalVariable(name: "1", scope: !5, file: !1, line: 1, type: !10)
163 !10 = !DIBasicType(name: "ty8", size: 8, encoding: DW_ATE_unsigned)
164 !11 = !DILocalVariable(name: "2", scope: !5, file: !1, line: 5, type: !12)
165 !12 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
166 !13 = !DILocalVariable(name: "3", scope: !5, file: !1, line: 6, type: !10)
167 !14 = !DILocalVariable(name: "4", scope: !5, file: !1, line: 10, type: !10)
168 !15 = !DILocation(line: 1, column: 1, scope: !5)
169 !16 = !DILocation(line: 2, column: 1, scope: !5)
170 !17 = !DILocation(line: 3, column: 1, scope: !5)
171 !18 = !DILocation(line: 4, column: 1, scope: !5)
172 !19 = !DILocation(line: 5, column: 1, scope: !5)
173 !20 = !DILocation(line: 6, column: 1, scope: !5)
174 !21 = !DILocation(line: 7, column: 1, scope: !5)
175 !22 = !DILocation(line: 8, column: 1, scope: !5)
176 !23 = !DILocation(line: 9, column: 1, scope: !5)
177 !24 = !DILocation(line: 10, column: 1, scope: !5)
178 !25 = !DILocation(line: 11, column: 1, scope: !5)
179 !26 = !DILocation(line: 12, column: 1, scope: !5)
180 !27 = !DILocation(line: 13, column: 1, scope: !5)
181 !28 = !DILocation(line: 14, column: 1, scope: !5)
182 !29 = !DILocation(line: 15, column: 1, scope: !5)
183 !30 = distinct !DISubprogram(name: "test13", linkageName: "test13", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !31)
185 !32 = !DILocalVariable(name: "1", scope: !30, file: !1, line: 1, type: !10)
186 !33 = !DILocation(line: 1, column: 1, scope: !30)