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