1; RUN: opt -mem2reg %s -S -o - | FileCheck %s 2 3;; Check that mem2reg removes dbg.value(%local, DIExpression(DW_OP_deref...)) 4;; that instcombine LowerDbgDeclare inserted before the call to 'esc' when 5;; promoting the alloca %local after 'esc' has been inlined. Without this we 6;; provide no location for 'local', even though it is provably constant 7;; throughout after inlining. 8;; 9;; $ clang reduce.c -O2 -g -emit-llvm -S -o tmp.ll -Xclang -disable-llvm-passes 10;; $ opt tmp.ll -o - -instcombine -inline -S 11;; $ cat reduce.c 12;; long a; 13;; int b; 14;; void c(); 15;; __attribute__((__always_inline__)) 16;; static void esc(long *e) { 17;; *e = a; 18;; c(); 19;; if (b) 20;; *e = 0; 21;; } 22;; 23;; void fun() { 24;; long local = 0; 25;; esc(&local); 26;; } 27 28; CHECK: define dso_local void @fun() 29; CHECK-NEXT: entry: 30; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 0, metadata ![[LOCAL:[0-9]+]], metadata !DIExpression()) 31; CHECK-NOT: call void @llvm.dbg.value({{.*}}, metadata ![[LOCAL]] 32; CHECK: ![[LOCAL]] = !DILocalVariable(name: "local", 33 34@a = dso_local global i64 0, align 8, !dbg !0 35@b = dso_local global i32 0, align 4, !dbg !6 36 37define dso_local void @fun() !dbg !14 { 38entry: 39 %e.addr.i = alloca i64*, align 8 40 %local = alloca i64, align 8 41 %0 = bitcast i64* %local to i8*, !dbg !19 42 call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %0), !dbg !19 43 call void @llvm.dbg.value(metadata i64 0, metadata !18, metadata !DIExpression()), !dbg !20 44 store i64 0, i64* %local, align 8, !dbg !21 45 call void @llvm.dbg.value(metadata i64* %local, metadata !18, metadata !DIExpression(DW_OP_deref)), !dbg !20 46 %1 = bitcast i64** %e.addr.i to i8*, !dbg !26 47 call void @llvm.lifetime.start.p0i8(i64 8, i8* %1), !dbg !26 48 call void @llvm.dbg.value(metadata i64* %local, metadata !32, metadata !DIExpression()), !dbg !26 49 store i64* %local, i64** %e.addr.i, align 8 50 %2 = load i64, i64* @a, align 8, !dbg !36 51 call void @llvm.dbg.value(metadata i64* %local, metadata !32, metadata !DIExpression()), !dbg !26 52 store i64 %2, i64* %local, align 8, !dbg !37 53 call void (...) @c(), !dbg !38 54 %3 = load i32, i32* @b, align 4, !dbg !39 55 %tobool.not.i = icmp eq i32 %3, 0, !dbg !39 56 br i1 %tobool.not.i, label %esc.exit, label %if.then.i, !dbg !43 57 58if.then.i: ; preds = %entry 59 %4 = load i64*, i64** %e.addr.i, align 8, !dbg !44 60 call void @llvm.dbg.value(metadata i64* %4, metadata !32, metadata !DIExpression()), !dbg !26 61 store i64 0, i64* %4, align 8, !dbg !45 62 br label %esc.exit, !dbg !46 63 64esc.exit: ; preds = %entry, %if.then.i 65 %5 = bitcast i64** %e.addr.i to i8*, !dbg !47 66 call void @llvm.lifetime.end.p0i8(i64 8, i8* %5), !dbg !47 67 %6 = bitcast i64* %local to i8*, !dbg !48 68 call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %6), !dbg !48 69 ret void, !dbg !48 70} 71 72declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) 73declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) 74declare void @llvm.dbg.value(metadata, metadata, metadata) 75declare !dbg !49 dso_local void @c(...) 76 77!llvm.dbg.cu = !{!2} 78!llvm.module.flags = !{!10, !11, !12} 79!llvm.ident = !{!13} 80 81!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 82!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !9, isLocal: false, isDefinition: true) 83!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 12.0.0)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) 84!3 = !DIFile(filename: "reduce.c", directory: "/") 85!4 = !{} 86!5 = !{!0, !6} 87!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) 88!7 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true) 89!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 90!9 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed) 91!10 = !{i32 7, !"Dwarf Version", i32 4} 92!11 = !{i32 2, !"Debug Info Version", i32 3} 93!12 = !{i32 1, !"wchar_size", i32 4} 94!13 = !{!"clang version 12.0.0"} 95!14 = distinct !DISubprogram(name: "fun", scope: !3, file: !3, line: 12, type: !15, scopeLine: 12, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !17) 96!15 = !DISubroutineType(types: !16) 97!16 = !{null} 98!17 = !{!18} 99!18 = !DILocalVariable(name: "local", scope: !14, file: !3, line: 13, type: !9) 100!19 = !DILocation(line: 13, column: 3, scope: !14) 101!20 = !DILocation(line: 0, scope: !14) 102!21 = !DILocation(line: 13, column: 8, scope: !14) 103!26 = !DILocation(line: 0, scope: !27, inlinedAt: !33) 104!27 = distinct !DISubprogram(name: "esc", scope: !3, file: !3, line: 5, type: !28, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !31) 105!28 = !DISubroutineType(types: !29) 106!29 = !{null, !30} 107!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64) 108!31 = !{!32} 109!32 = !DILocalVariable(name: "e", arg: 1, scope: !27, file: !3, line: 5, type: !30) 110!33 = distinct !DILocation(line: 14, column: 3, scope: !14) 111!36 = !DILocation(line: 6, column: 8, scope: !27, inlinedAt: !33) 112!37 = !DILocation(line: 6, column: 6, scope: !27, inlinedAt: !33) 113!38 = !DILocation(line: 7, column: 3, scope: !27, inlinedAt: !33) 114!39 = !DILocation(line: 8, column: 7, scope: !40, inlinedAt: !33) 115!40 = distinct !DILexicalBlock(scope: !27, file: !3, line: 8, column: 7) 116!43 = !DILocation(line: 8, column: 7, scope: !27, inlinedAt: !33) 117!44 = !DILocation(line: 9, column: 6, scope: !40, inlinedAt: !33) 118!45 = !DILocation(line: 9, column: 8, scope: !40, inlinedAt: !33) 119!46 = !DILocation(line: 9, column: 5, scope: !40, inlinedAt: !33) 120!47 = !DILocation(line: 10, column: 1, scope: !27, inlinedAt: !33) 121!48 = !DILocation(line: 15, column: 1, scope: !14) 122!49 = !DISubprogram(name: "c", scope: !3, file: !3, line: 3, type: !50, spFlags: DISPFlagOptimized, retainedNodes: !4) 123!50 = !DISubroutineType(types: !51) 124!51 = !{null, null} 125