1 ; RUN: opt -S -lcssa < %s | FileCheck %s
3 ; Reproducer for PR39019.
5 ; Verify that the llvm.dbg.values are updated to use the PHI nodes inserted by
8 ; For the test case @single_exit, we can rewrite all llvm.dbg.value calls
9 ; to use the inserted PHI.
11 ; CHECK-LABEL: @single_exit(
13 ; CHECK-LABEL: inner.body:
14 ; CHECK: %add = add nsw i32 0, 2
15 ; CHECK: call void @llvm.dbg.value(metadata i32 %add, metadata [[VAR:![0-9]+]], metadata !DIExpression())
18 ; CHECK-LABEL: outer.exit:
19 ; CHECK-NEXT: [[PN:%[^ ]*]] = phi i32 [ %add.lcssa, %outer.latch ]
20 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[PN]], metadata [[VAR]], metadata !DIExpression())
21 ; CHECK-NEXT: call void @bar(i32 [[PN]])
24 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[PN]], metadata [[VAR]], metadata !DIExpression())
26 define void @single_exit() !dbg !6 {
28 br label %outer.header, !dbg !12
30 outer.header: ; preds = %outer.latch, %entry
31 br label %inner.body, !dbg !12
33 inner.body: ; preds = %inner.body, %outer.header
34 %add = add nsw i32 0, 2, !dbg !12
35 call void @llvm.dbg.value(metadata i32 %add, metadata !9, metadata !DIExpression()), !dbg !12
36 br i1 false, label %inner.body, label %inner.exit, !dbg !12
38 inner.exit: ; preds = %inner.body
41 outer.latch: ; preds = %inner.exit
42 br i1 false, label %outer.header, label %outer.exit, !dbg !12
44 outer.exit: ; preds = %outer.latch
45 call void @llvm.dbg.value(metadata i32 %add, metadata !9, metadata !DIExpression()), !dbg !12
46 tail call void @bar(i32 %add), !dbg !12
49 exit: ; preds = %outer.exit
50 call void @llvm.dbg.value(metadata i32 %add, metadata !9, metadata !DIExpression()), !dbg !12
54 ; For the test case @multi_exit, we cannot update the llvm.dbg.value call in exit,
55 ; because LCSSA did not insert a PHI node in %exit, as there is no non-debug
58 ; CHECK-LABEL: @multi_exit()
60 ; CHECK-LABEL: for.header:
61 ; CHECK-NEXT: %add = add nsw i32 0, 2
62 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %add, metadata [[VAR2:![0-9]+]], metadata !DIExpression())
64 ; CHECK-LABEL: for.exit1:
65 ; CHECK-NEXT: [[PN1:%[^ ]*]] = phi i32 [ %add, %for.header ]
66 ; CHECK-NEXT: br label %for.exit1.succ
68 ; CHECK-LABEL: for.exit1.succ:
69 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[PN1]], metadata [[VAR2]], metadata !DIExpression())
70 ; CHECK-NEXT: call void @bar(i32 [[PN1]])
72 ; CHECK-LABEL: for.exit2:
73 ; CHECK-NEXT: [[PN2:%[^ ]*]] = phi i32 [ %add, %for.latch ]
74 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[PN2]], metadata [[VAR2]], metadata !DIExpression())
75 ; CHECK-NEXT: call void @bar(i32 [[PN2]])
78 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %add, metadata [[VAR2]], metadata !DIExpression())
80 define void @multi_exit() !dbg !13 {
82 br label %for.header, !dbg !14
84 for.header: ; preds = %for.latch, %entry
85 %add = add nsw i32 0, 2, !dbg !14
86 call void @llvm.dbg.value(metadata i32 %add, metadata !16, metadata !DIExpression()), !dbg !14
87 br i1 false, label %for.latch, label %for.exit1, !dbg !14
89 for.latch: ; preds = %for.header
90 br i1 false, label %for.header, label %for.exit2, !dbg !14
92 for.exit1: ; preds = %for.header
93 br label %for.exit1.succ
95 for.exit1.succ: ; preds = %for.exit1
96 call void @llvm.dbg.value(metadata i32 %add, metadata !16, metadata !DIExpression()), !dbg !14
97 tail call void @bar(i32 %add), !dbg !14
100 for.exit2: ; preds = %for.latch
101 call void @llvm.dbg.value(metadata i32 %add, metadata !16, metadata !DIExpression()), !dbg !14
102 tail call void @bar(i32 %add), !dbg !14
105 exit: ; preds = %for.exit2, %for.exit1.succ
106 call void @llvm.dbg.value(metadata i32 %add, metadata !16, metadata !DIExpression()), !dbg !14
110 ; CHECK: [[VAR]] = !DILocalVariable(name: "sum",
111 ; CHECK: [[VAR2]] = !DILocalVariable(name: "sum2",
113 declare void @bar(i32)
115 declare void @llvm.dbg.value(metadata, metadata, metadata)
118 !llvm.module.flags = !{!3, !4}
121 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 8.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !2, nameTableKind: None)
122 !1 = !DIFile(filename: "foo.c", directory: "/")
124 !3 = !{i32 2, !"Dwarf Version", i32 4}
125 !4 = !{i32 2, !"Debug Info Version", i32 3}
126 !5 = !{!"clang version 8.0.0"}
127 !6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 10, type: !7, scopeLine: 10, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
128 !7 = !DISubroutineType(types: !2)
130 !9 = !DILocalVariable(name: "sum", scope: !10, file: !1, line: 11, type: !11)
131 !10 = !DILexicalBlockFile(scope: !6, file: !1, discriminator: 0)
132 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
133 !12 = !DILocation(line: 0, scope: !10)
134 !13 = distinct !DISubprogram(name: "multi_exit", scope: !1, file: !1, line: 10, type: !7, scopeLine: 10, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
135 !14 = !DILocation(line: 0, scope: !15)
136 !15 = !DILexicalBlockFile(scope: !13, file: !1, discriminator: 0)
137 !16 = !DILocalVariable(name: "sum2", scope: !15, file: !1, line: 11, type: !11)