xref: /llvm-project/llvm/test/Transforms/InstCombine/debuginfo-dce2.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -passes=instcombine -S %s -o - | FileCheck %s
2; RUN: opt -passes=instcombine -S %s -o - --try-experimental-debuginfo-iterators | FileCheck %s
3
4; In this example, the cast from ptr to ptr becomes trivially dead. We should
5; salvage its debug info.
6
7; C source:
8; void use_as_void(ptr);
9; void f(ptr p) {
10;   int *q = (int *)p;
11;   use_as_void(q);
12; }
13
14; ModuleID = '<stdin>'
15source_filename = "t.c"
16target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
17target triple = "x86_64-pc-windows-msvc19.11.25508"
18
19; Function Attrs: nounwind uwtable
20define void @f(ptr %p) !dbg !11 {
21entry:
22  call void @llvm.dbg.value(metadata ptr %p, metadata !16, metadata !DIExpression()), !dbg !18
23  call void @llvm.dbg.value(metadata ptr %p, metadata !17, metadata !DIExpression()), !dbg !20
24  call void @use_as_void(ptr %p), !dbg !22
25  ret void, !dbg !23
26}
27
28; CHECK-LABEL: define void @f(ptr %p)
29; CHECK: #dbg_value(ptr %p, ![[P_VAR:[0-9]+]], !DIExpression(),
30; CHECK-NOT: bitcast
31; CHECK: #dbg_value(ptr %p, ![[Q_VAR:[0-9]+]], !DIExpression(),
32; CHECK-NOT: bitcast
33; CHECK: ret void
34
35; CHECK: ![[P_VAR]] = !DILocalVariable(name: "p", {{.*}})
36; CHECK: ![[Q_VAR]] = !DILocalVariable(name: "q", {{.*}})
37
38declare void @use_as_void(ptr)
39
40declare void @llvm.dbg.value(metadata, metadata, metadata)
41
42!llvm.dbg.cu = !{!0}
43!llvm.module.flags = !{!6, !7, !8, !9}
44!llvm.ident = !{!10}
45
46!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3)
47!1 = !DIFile(filename: "t.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild", checksumkind: CSK_MD5, checksum: "56c40617ada23a8cccbd9a16bcec57af")
48!2 = !{}
49!3 = !{!4}
50!4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
51!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
52!6 = !{i32 2, !"CodeView", i32 1}
53!7 = !{i32 2, !"Debug Info Version", i32 3}
54!8 = !{i32 1, !"wchar_size", i32 2}
55!9 = !{i32 7, !"PIC Level", i32 2}
56!10 = !{!"clang version 6.0.0 "}
57!11 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 2, type: !12, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !15)
58!12 = !DISubroutineType(types: !13)
59!13 = !{null, !14}
60!14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
61!15 = !{!16, !17}
62!16 = !DILocalVariable(name: "p", arg: 1, scope: !11, file: !1, line: 2, type: !14)
63!17 = !DILocalVariable(name: "q", scope: !11, file: !1, line: 3, type: !4)
64!18 = !DILocation(line: 2, column: 14, scope: !11)
65!19 = !DILocation(line: 3, column: 12, scope: !11)
66!20 = !DILocation(line: 3, column: 8, scope: !11)
67!21 = !DILocation(line: 4, column: 15, scope: !11)
68!22 = !DILocation(line: 4, column: 3, scope: !11)
69!23 = !DILocation(line: 5, column: 1, scope: !11)
70