1 ; RUN: opt -passes=mem2reg %s -S -o - | FileCheck %s
3 ;; Check that mem2reg removes dbg.value(%param.addr, DIExpression(DW_OP_deref...))
4 ;; when promoting the alloca %param.addr.
6 ;; $ clang inlining.c -O2 -g -emit-llvm -S -o tmp.ll -Xclang -disable-llvm-passes
7 ;; $ opt tmp.ll -o - -instcombine -inline -S
10 ;; __attribute__((__always_inline__))
11 ;; static void use(int* p) {
15 ;; __attribute__((__noinline__))
16 ;; void fun(int param) {
20 ; CHECK: define dso_local void @fun(i32 %param)
22 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %param, metadata ![[PARAM:[0-9]+]], metadata !DIExpression())
23 ; CHECK-NOT: call void @llvm.dbg.value({{.*}}, metadata ![[PARAM]]
24 ; CHECK: ![[PARAM]] = !DILocalVariable(name: "param",
26 @g = dso_local global i32 0, align 4, !dbg !0
28 define dso_local void @fun(i32 %param) !dbg !12 {
30 %param.addr = alloca i32, align 4
31 call void @llvm.dbg.value(metadata i32 %param, metadata !16, metadata !DIExpression()), !dbg !17
32 store i32 %param, ptr %param.addr, align 4
33 call void @llvm.dbg.value(metadata ptr %param.addr, metadata !16, metadata !DIExpression(DW_OP_deref)), !dbg !17
34 call void @llvm.dbg.value(metadata ptr %param.addr, metadata !22, metadata !DIExpression()), !dbg !28
35 call void @llvm.dbg.value(metadata ptr %param.addr, metadata !22, metadata !DIExpression()), !dbg !28
36 %0 = load i32, ptr %param.addr, align 4, !dbg !30
37 store i32 %0, ptr @g, align 4, !dbg !31
41 declare void @llvm.dbg.value(metadata, metadata, metadata)
44 !llvm.module.flags = !{!8, !9, !10}
47 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
48 !1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !6, line: 8, type: !7, isLocal: false, isDefinition: true)
49 !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)
50 !3 = !DIFile(filename: "inlining.c", directory: "/")
53 !6 = !DIFile(filename: "inlining.c", directory: "/")
54 !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
55 !8 = !{i32 7, !"Dwarf Version", i32 4}
56 !9 = !{i32 2, !"Debug Info Version", i32 3}
57 !10 = !{i32 1, !"wchar_size", i32 4}
58 !11 = !{!"clang version 12.0.0"}
59 !12 = distinct !DISubprogram(name: "fun", scope: !6, file: !6, line: 15, type: !13, scopeLine: 15, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !15)
60 !13 = !DISubroutineType(types: !14)
63 !16 = !DILocalVariable(name: "param", arg: 1, scope: !12, file: !6, line: 15, type: !7)
64 !17 = !DILocation(line: 0, scope: !12)
65 !22 = !DILocalVariable(name: "p", arg: 1, scope: !23, file: !6, line: 10, type: !26)
66 !23 = distinct !DISubprogram(name: "use", scope: !6, file: !6, line: 10, type: !24, scopeLine: 10, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !27)
67 !24 = !DISubroutineType(types: !25)
69 !26 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)
71 !28 = !DILocation(line: 0, scope: !23, inlinedAt: !29)
72 !29 = distinct !DILocation(line: 16, column: 3, scope: !12)
73 !30 = !DILocation(line: 11, column: 7, scope: !23, inlinedAt: !29)
74 !31 = !DILocation(line: 11, column: 5, scope: !23, inlinedAt: !29)
75 !32 = !DILocation(line: 17, column: 1, scope: !12)
76 !34 = !DISubroutineType(types: !35)