xref: /llvm-project/llvm/test/DebugInfo/salvage-gep.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt %s -passes=dce -S | FileCheck %s
2; RUN: opt %s -passes=dce -S --try-experimental-debuginfo-iterators | FileCheck %s
3
4; Tests the salvaging of GEP instructions, specifically struct indexing,
5; non-constant array indexing, and non-constant array indexing into an array of
6; a type with width 0.
7
8%struct.S = type { i32, i32 }
9%zero = type [0 x [10 x i32]]
10
11;; The constant and variable offsets should be applied correctly.
12; CHECK: #dbg_value(!DIArgList(ptr %ptr, i64 %offset),
13; CHECK-SAME: ![[VAR_OFFSET_PTR:[0-9]+]],
14; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 8, DW_OP_mul, DW_OP_plus, DW_OP_plus_uconst, 4, DW_OP_stack_value),
15
16;; The variable offset should be ignored, as it applies to a type of width 0,
17;; leaving only the constant offset.
18; CHECK: #dbg_value(ptr %zptr,
19; CHECK-SAME: ![[VAR_ZERO_PTR:[0-9]+]],
20; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, 44, DW_OP_stack_value),
21
22; CHECK: ![[VAR_OFFSET_PTR]] = !DILocalVariable(name: "offset_ptr"
23; CHECK: ![[VAR_ZERO_PTR]] = !DILocalVariable(name: "zero_ptr"
24
25define void @"?foo@@YAXPEAUS@@_J@Z"(ptr %ptr, ptr %zptr, i64 %offset) !dbg !8 {
26entry:
27  call void @llvm.dbg.value(metadata i64 %offset, metadata !20, metadata !DIExpression()), !dbg !24
28  call void @llvm.dbg.value(metadata ptr %ptr, metadata !21, metadata !DIExpression()), !dbg !24
29  %arrayidx = getelementptr inbounds %struct.S, ptr %ptr, i64 %offset, !dbg !25
30  %b = getelementptr inbounds %struct.S, ptr %arrayidx, i32 0, i32 1, !dbg !25
31  %c = getelementptr inbounds %zero, ptr %zptr, i64 %offset, i32 1, i32 1, !dbg !25
32  call void @llvm.dbg.value(metadata ptr %b, metadata !22, metadata !DIExpression()), !dbg !24
33  call void @llvm.dbg.value(metadata ptr %c, metadata !27, metadata !DIExpression()), !dbg !24
34  ret void, !dbg !26
35}
36
37declare void @llvm.dbg.value(metadata, metadata, metadata)
38
39!llvm.dbg.cu = !{!0}
40!llvm.module.flags = !{!3, !4, !5, !6}
41!llvm.ident = !{!7}
42
43!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
44!1 = !DIFile(filename: "salvage-gep.cpp", directory: "/")
45!2 = !{}
46!3 = !{i32 2, !"CodeView", i32 1}
47!4 = !{i32 2, !"Debug Info Version", i32 3}
48!5 = !{i32 1, !"wchar_size", i32 2}
49!6 = !{i32 7, !"PIC Level", i32 2}
50!7 = !{!"clang version 11.0.0"}
51!8 = distinct !DISubprogram(name: "foo", linkageName: "?foo@@YAXPEAUS@@_J@Z", scope: !9, file: !9, line: 7, type: !10, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !19)
52!9 = !DIFile(filename: ".\\salvage-gep.cpp", directory: "/")
53!10 = !DISubroutineType(types: !11)
54!11 = !{null, !12, !18}
55!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
56!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !9, line: 2, size: 64, flags: DIFlagTypePassByValue, elements: !14, identifier: ".?AUS@@")
57!14 = !{!15, !17}
58!15 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !13, file: !9, line: 3, baseType: !16, size: 32)
59!16 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
60!17 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !13, file: !9, line: 4, baseType: !16, size: 32, offset: 32)
61!18 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed)
62!19 = !{!20, !21, !22}
63!20 = !DILocalVariable(name: "offset", arg: 2, scope: !8, file: !9, line: 7, type: !18)
64!21 = !DILocalVariable(name: "ptr", arg: 1, scope: !8, file: !9, line: 7, type: !12)
65!22 = !DILocalVariable(name: "offset_ptr", scope: !8, file: !9, line: 8, type: !23)
66!23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64)
67!24 = !DILocation(line: 0, scope: !8)
68!25 = !DILocation(line: 8, scope: !8)
69!26 = !DILocation(line: 9, scope: !8)
70!27 = !DILocalVariable(name: "zero_ptr", scope: !8, file: !9, line: 8, type: !23)
71