121 lines · plain
1; RUN: opt -passes=mem2reg %s -S -o - | FileCheck %s2 3;; Check that mem2reg removes dbg.value(%local, DIExpression(DW_OP_deref...))4;; that instcombine LowerDbgDeclare inserted before the call to 'esc' when5;; promoting the alloca %local after 'esc' has been inlined. Without this we6;; provide no location for 'local', even though it is provably constant7;; throughout after inlining.8;;9;; $ clang reduce.c -O2 -g -emit-llvm -S -o tmp.ll -Xclang -disable-llvm-passes10;; $ opt tmp.ll -o - -instcombine -inline -S11;; $ cat reduce.c12;; 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: #dbg_value(i64 0, ![[LOCAL:[0-9]+]], !DIExpression(),31; CHECK-NOT: #dbg_value({{.*}}, ![[LOCAL]]32; CHECK: ![[LOCAL]] = !DILocalVariable(name: "local",33 34@a = dso_local global i64 0, align 8, !dbg !035@b = dso_local global i32 0, align 4, !dbg !636 37define dso_local void @fun() !dbg !14 {38entry:39 %e.addr.i = alloca ptr, align 840 %local = alloca i64, align 841 call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %local), !dbg !1942 call void @llvm.dbg.value(metadata i64 0, metadata !18, metadata !DIExpression()), !dbg !2043 store i64 0, ptr %local, align 8, !dbg !2144 call void @llvm.dbg.value(metadata ptr %local, metadata !18, metadata !DIExpression(DW_OP_deref)), !dbg !2045 call void @llvm.lifetime.start.p0(i64 8, ptr %e.addr.i), !dbg !2646 call void @llvm.dbg.value(metadata ptr %local, metadata !32, metadata !DIExpression()), !dbg !2647 store ptr %local, ptr %e.addr.i, align 848 %0 = load i64, ptr @a, align 8, !dbg !3649 call void @llvm.dbg.value(metadata ptr %local, metadata !32, metadata !DIExpression()), !dbg !2650 store i64 %0, ptr %local, align 8, !dbg !3751 call void (...) @c(), !dbg !3852 %1 = load i32, ptr @b, align 4, !dbg !3953 %tobool.not.i = icmp eq i32 %1, 0, !dbg !3954 br i1 %tobool.not.i, label %esc.exit, label %if.then.i, !dbg !4355 56if.then.i: ; preds = %entry57 %2 = load ptr, ptr %e.addr.i, align 8, !dbg !4458 call void @llvm.dbg.value(metadata ptr %2, metadata !32, metadata !DIExpression()), !dbg !2659 store i64 0, ptr %2, align 8, !dbg !4560 br label %esc.exit, !dbg !4661 62esc.exit: ; preds = %entry, %if.then.i63 call void @llvm.lifetime.end.p0(i64 8, ptr %e.addr.i), !dbg !4764 call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %local), !dbg !4865 ret void, !dbg !4866}67 68declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)69declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)70declare void @llvm.dbg.value(metadata, metadata, metadata)71declare !dbg !49 dso_local void @c(...)72 73!llvm.dbg.cu = !{!2}74!llvm.module.flags = !{!10, !11, !12}75!llvm.ident = !{!13}76 77!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())78!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !9, isLocal: false, isDefinition: true)79!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)80!3 = !DIFile(filename: "reduce.c", directory: "/")81!4 = !{}82!5 = !{!0, !6}83!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())84!7 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true)85!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)86!9 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)87!10 = !{i32 7, !"Dwarf Version", i32 4}88!11 = !{i32 2, !"Debug Info Version", i32 3}89!12 = !{i32 1, !"wchar_size", i32 4}90!13 = !{!"clang version 12.0.0"}91!14 = distinct !DISubprogram(name: "fun", scope: !3, file: !3, line: 12, type: !15, scopeLine: 12, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !17)92!15 = !DISubroutineType(types: !16)93!16 = !{null}94!17 = !{!18}95!18 = !DILocalVariable(name: "local", scope: !14, file: !3, line: 13, type: !9)96!19 = !DILocation(line: 13, column: 3, scope: !14)97!20 = !DILocation(line: 0, scope: !14)98!21 = !DILocation(line: 13, column: 8, scope: !14)99!26 = !DILocation(line: 0, scope: !27, inlinedAt: !33)100!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)101!28 = !DISubroutineType(types: !29)102!29 = !{null, !30}103!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)104!31 = !{!32}105!32 = !DILocalVariable(name: "e", arg: 1, scope: !27, file: !3, line: 5, type: !30)106!33 = distinct !DILocation(line: 14, column: 3, scope: !14)107!36 = !DILocation(line: 6, column: 8, scope: !27, inlinedAt: !33)108!37 = !DILocation(line: 6, column: 6, scope: !27, inlinedAt: !33)109!38 = !DILocation(line: 7, column: 3, scope: !27, inlinedAt: !33)110!39 = !DILocation(line: 8, column: 7, scope: !40, inlinedAt: !33)111!40 = distinct !DILexicalBlock(scope: !27, file: !3, line: 8, column: 7)112!43 = !DILocation(line: 8, column: 7, scope: !27, inlinedAt: !33)113!44 = !DILocation(line: 9, column: 6, scope: !40, inlinedAt: !33)114!45 = !DILocation(line: 9, column: 8, scope: !40, inlinedAt: !33)115!46 = !DILocation(line: 9, column: 5, scope: !40, inlinedAt: !33)116!47 = !DILocation(line: 10, column: 1, scope: !27, inlinedAt: !33)117!48 = !DILocation(line: 15, column: 1, scope: !14)118!49 = !DISubprogram(name: "c", scope: !3, file: !3, line: 3, type: !50, spFlags: DISPFlagOptimized, retainedNodes: !4)119!50 = !DISubroutineType(types: !51)120!51 = !{null, null}121