xref: /llvm-project/llvm/test/Transforms/ADCE/debug-info-intrinsic.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -passes=adce -S < %s | FileCheck %s
2; RUN: opt -passes=adce -S < %s --try-experimental-debuginfo-iterators | FileCheck %s
3; Test that debug info intrinsics in dead scopes get eliminated by -adce.
4
5; Generated with 'clang -g -S -emit-llvm | opt -passes=mem2reg -inline' at r262899
6; (before -passes=adce  was augmented) and then hand-reduced.  This was the input:
7;
8;;void sink(void);
9;;
10;;void variable_in_unused_subscope(void) {
11;;  { int i = 0; }
12;;  sink();
13;;}
14;;
15;;void variable_in_parent_scope(void) {
16;;  int i = 0;
17;;  { sink(); }
18;;}
19;;
20;;static int empty_function_with_unused_variable(void) {
21;;  { int i = 0; }
22;;  return 0;
23;;}
24;;
25;;void calls_empty_function_with_unused_variable_in_unused_subscope(void) {
26;;  { empty_function_with_unused_variable(); }
27;;  sink();
28;;}
29
30declare void @llvm.dbg.value(metadata, metadata, metadata)
31
32declare void @sink()
33
34; CHECK-LABEL: define void @variable_in_unused_subscope(
35define void @variable_in_unused_subscope() !dbg !4 {
36; CHECK-NEXT: entry:
37; CHECK-NEXT:   call void @sink
38; CHECK-NEXT:   ret void
39entry:
40  call void @llvm.dbg.value(metadata i32 0, metadata !15, metadata !17), !dbg !18
41  call void @sink(), !dbg !19
42  ret void, !dbg !20
43}
44
45; CHECK-LABEL: define void @variable_in_parent_scope(
46define void @variable_in_parent_scope() !dbg !7 {
47; CHECK-NEXT: entry:
48; CHECK-NEXT:   #dbg_value
49; CHECK-NEXT:   call void @sink
50; CHECK-NEXT:   ret void
51entry:
52  call void @llvm.dbg.value(metadata i32 0, metadata !21, metadata !17), !dbg !22
53  call void @sink(), !dbg !23
54  ret void, !dbg !25
55}
56
57; CHECK-LABEL: define void @calls_empty_function_with_unused_variable_in_unused_subscope(
58define void @calls_empty_function_with_unused_variable_in_unused_subscope() !dbg !8 {
59; CHECK-NEXT: entry:
60; CHECK-NEXT:   call void @sink
61; CHECK-NEXT:   ret void
62entry:
63  call void @llvm.dbg.value(metadata i32 0, metadata !26, metadata !17), !dbg !28
64  call void @sink(), !dbg !31
65  ret void, !dbg !32
66}
67
68!llvm.dbg.cu = !{!0}
69!llvm.module.flags = !{!14}
70
71!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
72!1 = !DIFile(filename: "t.c", directory: "/path/to/test/Transforms/ADCE")
73!2 = !{}
74!4 = distinct !DISubprogram(name: "variable_in_unused_subscope", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
75!5 = !DISubroutineType(types: !6)
76!6 = !{null}
77!7 = distinct !DISubprogram(name: "variable_in_parent_scope", scope: !1, file: !1, line: 8, type: !5, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
78!8 = distinct !DISubprogram(name: "calls_empty_function_with_unused_variable_in_unused_subscope", scope: !1, file: !1, line: 18, type: !5, isLocal: false, isDefinition: true, scopeLine: 18, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
79!10 = distinct !DISubprogram(name: "empty_function_with_unused_variable", scope: !1, file: !1, line: 13, type: !11, isLocal: true, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
80!11 = !DISubroutineType(types: !12)
81!12 = !{!13}
82!13 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
83!14 = !{i32 2, !"Debug Info Version", i32 3}
84!15 = !DILocalVariable(name: "i", scope: !16, file: !1, line: 4, type: !13)
85!16 = distinct !DILexicalBlock(scope: !4, file: !1, line: 4, column: 3)
86!17 = !DIExpression()
87!18 = !DILocation(line: 4, column: 9, scope: !16)
88!19 = !DILocation(line: 5, column: 3, scope: !4)
89!20 = !DILocation(line: 6, column: 1, scope: !4)
90!21 = !DILocalVariable(name: "i", scope: !7, file: !1, line: 9, type: !13)
91!22 = !DILocation(line: 9, column: 7, scope: !7)
92!23 = !DILocation(line: 10, column: 5, scope: !24)
93!24 = distinct !DILexicalBlock(scope: !7, file: !1, line: 10, column: 3)
94!25 = !DILocation(line: 11, column: 1, scope: !7)
95!26 = !DILocalVariable(name: "i", scope: !27, file: !1, line: 14, type: !13)
96!27 = distinct !DILexicalBlock(scope: !10, file: !1, line: 14, column: 3)
97!28 = !DILocation(line: 14, column: 9, scope: !27, inlinedAt: !29)
98!29 = distinct !DILocation(line: 19, column: 5, scope: !30)
99!30 = distinct !DILexicalBlock(scope: !8, file: !1, line: 19, column: 3)
100!31 = !DILocation(line: 20, column: 3, scope: !8)
101!32 = !DILocation(line: 21, column: 1, scope: !8)
102