xref: /llvm-project/llvm/test/DebugInfo/Generic/mem2reg-promote-alloca-3.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -passes=mem2reg %s -S -o - | FileCheck %s
2; RUN: opt -passes=mem2reg %s -S -o - --try-experimental-debuginfo-iterators | FileCheck %s
3
4;; Check that mem2reg removes dbg.value(%local, DIExpression(DW_OP_deref...))
5;; that instcombine LowerDbgDeclare inserted before the call to 'esc' when
6;; promoting the alloca %local after 'esc' has been inlined. Without this we
7;; provide no location for 'local', even though it is provably constant
8;; throughout after inlining.
9;;
10;; $ clang reduce.c -O2 -g -emit-llvm -S -o tmp.ll -Xclang -disable-llvm-passes
11;; $ opt tmp.ll -o - -instcombine -inline -S
12;; $ cat reduce.c
13;; __attribute__((__always_inline__))
14;; static void esc(unsigned char **c) {
15;;   *c += 4;
16;; }
17;; void fun() {
18;;   unsigned char *local = 0;
19;;   esc(&local);
20;; }
21
22; CHECK: define dso_local void @fun()
23; CHECK-NEXT: entry:
24; CHECK-NEXT: #dbg_value(ptr null, ![[LOCAL:[0-9]+]], !DIExpression(),
25; CHECK-NOT: #dbg_value({{.*}}, ![[LOCAL]]
26; CHECK: ![[LOCAL]] = !DILocalVariable(name: "local",
27
28define dso_local void @fun() !dbg !7 {
29entry:
30  %local = alloca ptr, align 8
31  %0 = bitcast ptr %local to ptr, !dbg !14
32  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %0) #3, !dbg !14
33  call void @llvm.dbg.value(metadata ptr null, metadata !11, metadata !DIExpression()), !dbg !15
34  store ptr null, ptr %local, align 8, !dbg !16
35  call void @llvm.dbg.value(metadata ptr %local, metadata !11, metadata !DIExpression(DW_OP_deref)), !dbg !15
36  call void @llvm.dbg.value(metadata ptr %local, metadata !21, metadata !DIExpression()), !dbg !27
37  call void @llvm.dbg.value(metadata ptr %local, metadata !21, metadata !DIExpression()), !dbg !27
38  %1 = load ptr, ptr %local, align 8, !dbg !29
39  %add.ptr.i = getelementptr inbounds i8, ptr %1, i64 4, !dbg !29
40  store ptr %add.ptr.i, ptr %local, align 8, !dbg !29
41  %2 = bitcast ptr %local to ptr, !dbg !30
42  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3, !dbg !30
43  ret void, !dbg !30
44}
45
46declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
47declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
48declare void @llvm.dbg.value(metadata, metadata, metadata)
49
50!llvm.dbg.cu = !{!0}
51!llvm.module.flags = !{!3, !4, !5}
52!llvm.ident = !{!6}
53
54!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)
55!1 = !DIFile(filename: "reduce.c", directory: "/")
56!2 = !{}
57!3 = !{i32 7, !"Dwarf Version", i32 4}
58!4 = !{i32 2, !"Debug Info Version", i32 3}
59!5 = !{i32 1, !"wchar_size", i32 4}
60!6 = !{!"clang version 12.0.0"}
61!7 = distinct !DISubprogram(name: "fun", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)
62!8 = !DISubroutineType(types: !9)
63!9 = !{null}
64!10 = !{!11}
65!11 = !DILocalVariable(name: "local", scope: !7, file: !1, line: 6, type: !12)
66!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
67!13 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)
68!14 = !DILocation(line: 6, column: 3, scope: !7)
69!15 = !DILocation(line: 0, scope: !7)
70!16 = !DILocation(line: 6, column: 18, scope: !7)
71!21 = !DILocalVariable(name: "c", arg: 1, scope: !22, file: !1, line: 2, type: !25)
72!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)
73!23 = !DISubroutineType(types: !24)
74!24 = !{null, !25}
75!25 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
76!26 = !{!21}
77!27 = !DILocation(line: 0, scope: !22, inlinedAt: !28)
78!28 = distinct !DILocation(line: 7, column: 3, scope: !7)
79!29 = !DILocation(line: 3, column: 6, scope: !22, inlinedAt: !28)
80!30 = !DILocation(line: 8, column: 1, scope: !7)
81