1 ; Check for setting dbg.value undef which depends on instruction which is going to be dead
2 ; RUN: opt -passes=bdce %s -S | FileCheck %s
6 ; void optimize_me_not();
10 ; for (; a >= 0; a--) {
16 @b = common dso_local local_unnamed_addr global i8 0, align 1, !dbg !0
17 @a = common dso_local local_unnamed_addr global i8 0, align 1, !dbg !6
19 define dso_local i32 @main() local_unnamed_addr !dbg !13 {
21 ;CHECK: call void @llvm.dbg.value(metadata i8 2
22 ;CHECK: call void @llvm.dbg.value(metadata i8 2
23 call void @llvm.dbg.value(metadata i8 2, metadata !17, metadata !DIExpression()), !dbg !18
24 %.pr = load i8, ptr @b, align 1, !dbg !19
25 call void @llvm.dbg.value(metadata i8 2, metadata !17, metadata !DIExpression()), !dbg !18
26 %cmp5 = icmp slt i8 %.pr, 1, !dbg !22
27 br i1 %cmp5, label %for.cond2thread-pre-split.preheader, label %for.end9, !dbg !23
29 for.cond2thread-pre-split.preheader: ; preds = %entry
30 br label %for.cond2thread-pre-split, !dbg !23
31 for.cond2thread-pre-split: ; preds = %for.cond2thread-pre-split.preheader, %for.inc7
32 ;CHECK: call void @llvm.dbg.value(metadata i8 poison
33 %l_177.06 = phi i8 [ %l_177.1.lcssa, %for.inc7 ], [ 2, %for.cond2thread-pre-split.preheader ]
34 call void @llvm.dbg.value(metadata i8 %l_177.06, metadata !17, metadata !DIExpression()), !dbg !18
35 ;CHECK: call void @llvm.dbg.value(metadata i8 poison
36 %.pr1 = load i8, ptr @a, align 1, !dbg !24
37 call void @llvm.dbg.value(metadata i8 %l_177.06, metadata !17, metadata !DIExpression()), !dbg !18
38 %cmp42 = icmp sgt i8 %.pr1, -1, !dbg !27
39 br i1 %cmp42, label %for.body6.preheader, label %for.inc7, !dbg !28
41 for.body6.preheader: ; preds = %for.cond2thread-pre-split
42 br label %for.body6, !dbg !28
44 for.body6: ; preds = %for.body6.preheader, %for.body6
45 ;CHECK: call void @llvm.dbg.value(metadata i8 poison
46 ;CHECK: call void @llvm.dbg.value(metadata i8 poison
47 %l_177.13 = phi i8 [ %inc, %for.body6 ], [ %l_177.06, %for.body6.preheader ]
48 call void @llvm.dbg.value(metadata i8 %l_177.13, metadata !17, metadata !DIExpression()), !dbg !18
49 call void @llvm.dbg.value(metadata i8 %l_177.13, metadata !17, metadata !DIExpression(DW_OP_plus_uconst, 1, DW_OP_stack_value)), !dbg !18
50 tail call void (...) @optimize_me_not(), !dbg !29
51 %inc = add i8 %l_177.13, 1, !dbg !31
52 %0 = load i8, ptr @a, align 1, !dbg !32
53 %dec = add i8 %0, -1, !dbg !32
54 store i8 %dec, ptr @a, align 1, !dbg !32
55 call void @llvm.dbg.value(metadata i8 %inc, metadata !17, metadata !DIExpression()), !dbg !18
56 %cmp4 = icmp sgt i8 %dec, -1, !dbg !27
57 br i1 %cmp4, label %for.body6, label %for.inc7.loopexit, !dbg !28, !llvm.loop !33
59 for.inc7.loopexit: ; preds = %for.body6
60 %inc.lcssa = phi i8 [ %inc, %for.body6 ], !dbg !31
61 br label %for.inc7, !dbg !35
63 for.inc7: ; preds = %for.inc7.loopexit, %for.cond2thread-pre-split
64 ;CHECK: call void @llvm.dbg.value(metadata i8 poison
65 %l_177.1.lcssa = phi i8 [ %l_177.06, %for.cond2thread-pre-split ], [ %inc.lcssa, %for.inc7.loopexit ], !dbg !18
66 %1 = load i8, ptr @b, align 1, !dbg !35
67 %inc8 = add i8 %1, 1, !dbg !35
68 store i8 %inc8, ptr @b, align 1, !dbg !35
69 call void @llvm.dbg.value(metadata i8 %l_177.1.lcssa, metadata !17, metadata !DIExpression()), !dbg !18
70 %cmp = icmp slt i8 %inc8, 1, !dbg !22
71 br i1 %cmp, label %for.cond2thread-pre-split, label %for.end9.loopexit, !dbg !23, !llvm.loop !36
73 for.end9.loopexit: ; preds = %for.inc7
74 br label %for.end9, !dbg !38
76 for.end9: ; preds = %for.end9.loopexit, %entry
80 declare dso_local void @optimize_me_not(...) local_unnamed_addr
82 declare void @llvm.dbg.value(metadata, metadata, metadata)
85 !llvm.module.flags = !{!9, !10, !11}
88 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
89 !1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !8, isLocal: false, isDefinition: true)
90 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 10.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)
91 !3 = !DIFile(filename: "test", directory: "test")
94 !6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
95 !7 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 3, type: !8, isLocal: false, isDefinition: true)
96 !8 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
97 !9 = !{i32 2, !"Dwarf Version", i32 4}
98 !10 = !{i32 2, !"Debug Info Version", i32 3}
99 !11 = !{i32 1, !"wchar_size", i32 4}
100 !12 = !{!"clang version 10.0.0"}
101 !13 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 4, type: !14, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4)
102 !14 = !DISubroutineType(types: !15)
104 !16 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
105 !17 = !DILocalVariable(name: "l_177", scope: !13, file: !3, line: 5, type: !8)
106 !18 = !DILocation(line: 0, scope: !13)
107 !19 = !DILocation(line: 6, column: 10, scope: !20)
108 !20 = distinct !DILexicalBlock(scope: !21, file: !3, line: 6, column: 3)
109 !21 = distinct !DILexicalBlock(scope: !13, file: !3, line: 6, column: 3)
110 !22 = !DILocation(line: 6, column: 12, scope: !20)
111 !23 = !DILocation(line: 6, column: 3, scope: !21)
112 !24 = !DILocation(line: 7, column: 12, scope: !25)
113 !25 = distinct !DILexicalBlock(scope: !26, file: !3, line: 7, column: 5)
114 !26 = distinct !DILexicalBlock(scope: !20, file: !3, line: 7, column: 5)
115 !27 = !DILocation(line: 7, column: 14, scope: !25)
116 !28 = !DILocation(line: 7, column: 5, scope: !26)
117 !29 = !DILocation(line: 9, column: 7, scope: !30)
118 !30 = distinct !DILexicalBlock(scope: !25, file: !3, line: 7, column: 25)
119 !31 = !DILocation(line: 8, column: 7, scope: !30)
120 !32 = !DILocation(line: 7, column: 21, scope: !25)
121 !33 = distinct !{!33, !28, !34}
122 !34 = !DILocation(line: 10, column: 5, scope: !26)
123 !35 = !DILocation(line: 6, column: 19, scope: !20)
124 !36 = distinct !{!36, !23, !37}
125 !37 = !DILocation(line: 10, column: 5, scope: !21)
126 !38 = !DILocation(line: 11, column: 1, scope: !13)