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;; __attribute__((__always_inline__)) 13;; static void esc(unsigned char **c) { 14;; *c += 4; 15;; } 16;; void fun() { 17;; unsigned char *local = 0; 18;; esc(&local); 19;; } 20 21; CHECK: define dso_local void @fun() 22; CHECK-NEXT: entry: 23; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* null, metadata ![[LOCAL:[0-9]+]], metadata !DIExpression()) 24; CHECK-NOT: call void @llvm.dbg.value({{.*}}, metadata ![[LOCAL]] 25; CHECK: ![[LOCAL]] = !DILocalVariable(name: "local", 26 27define dso_local void @fun() !dbg !7 { 28entry: 29 %local = alloca i8*, align 8 30 %0 = bitcast i8** %local to i8*, !dbg !14 31 call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %0) #3, !dbg !14 32 call void @llvm.dbg.value(metadata i8* null, metadata !11, metadata !DIExpression()), !dbg !15 33 store i8* null, i8** %local, align 8, !dbg !16 34 call void @llvm.dbg.value(metadata i8** %local, metadata !11, metadata !DIExpression(DW_OP_deref)), !dbg !15 35 call void @llvm.dbg.value(metadata i8** %local, metadata !21, metadata !DIExpression()), !dbg !27 36 call void @llvm.dbg.value(metadata i8** %local, metadata !21, metadata !DIExpression()), !dbg !27 37 %1 = load i8*, i8** %local, align 8, !dbg !29 38 %add.ptr.i = getelementptr inbounds i8, i8* %1, i64 4, !dbg !29 39 store i8* %add.ptr.i, i8** %local, align 8, !dbg !29 40 %2 = bitcast i8** %local to i8*, !dbg !30 41 call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %2) #3, !dbg !30 42 ret void, !dbg !30 43} 44 45declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) 46declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) 47declare void @llvm.dbg.value(metadata, metadata, metadata) 48 49!llvm.dbg.cu = !{!0} 50!llvm.module.flags = !{!3, !4, !5} 51!llvm.ident = !{!6} 52 53!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) 54!1 = !DIFile(filename: "reduce.c", directory: "/") 55!2 = !{} 56!3 = !{i32 7, !"Dwarf Version", i32 4} 57!4 = !{i32 2, !"Debug Info Version", i32 3} 58!5 = !{i32 1, !"wchar_size", i32 4} 59!6 = !{!"clang version 12.0.0"} 60!7 = distinct !DISubprogram(name: "fun", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10) 61!8 = !DISubroutineType(types: !9) 62!9 = !{null} 63!10 = !{!11} 64!11 = !DILocalVariable(name: "local", scope: !7, file: !1, line: 6, type: !12) 65!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64) 66!13 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char) 67!14 = !DILocation(line: 6, column: 3, scope: !7) 68!15 = !DILocation(line: 0, scope: !7) 69!16 = !DILocation(line: 6, column: 18, scope: !7) 70!21 = !DILocalVariable(name: "c", arg: 1, scope: !22, file: !1, line: 2, type: !25) 71!22 = distinct !DISubprogram(name: "esc", scope: !1, file: !1, line: 2, type: !23, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !26) 72!23 = !DISubroutineType(types: !24) 73!24 = !{null, !25} 74!25 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64) 75!26 = !{!21} 76!27 = !DILocation(line: 0, scope: !22, inlinedAt: !28) 77!28 = distinct !DILocation(line: 7, column: 3, scope: !7) 78!29 = !DILocation(line: 3, column: 6, scope: !22, inlinedAt: !28) 79!30 = !DILocation(line: 8, column: 1, scope: !7) 80