xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/dse/shorten-offset.ll (revision 2499978aae8398023363a157185c8021c32ea363)
1; RUN: opt %s -S -passes=dse -o - | FileCheck %s --implicit-check-not="call void @llvm.dbg"
2; RUN: opt --try-experimental-debuginfo-iterators %s -S -passes=dse -o - | FileCheck %s --implicit-check-not="call void @llvm.dbg"
3
4;; Based on the test shorten.ll with some adjustments.
5;;
6;; $ cat test.cpp
7;; void esc(char*);
8;; void shortenEnd() {
9;;   char local[80];                      //        bits    frag
10;;   __builtin_memset(local + 8,  0, 24); // local:  64-160 ( 64, 96)
11;;   __builtin_memset(local + 16, 8, 40); // local: 128-160 (128, 32)
12;;   esc(local);
13;; }
14;; void shortenStart() {
15;;   char local2[40];                 //          bits   frag
16;;   __builtin_memset(local2, 0, 40); // local2:  0-160  (0, 160)
17;;   __builtin_memset(local2, 8, 16); // local2:  0-128  (0, 128)
18;;   esc(local2);
19;; }
20
21;; The variables and intrinsics have been adjusted with by hand to test
22;; what happens when the variable doesn't fill the whole alloca, and
23;; when offsets are encoded with both the address component of the dbg.assign
24;; and the address modifying DIExpression.
25
26;; DeadStoreElimination will shorten the first store in shortenEnd from [64,
27;; 192) bits to [64, 128) bits. Variable 'local' has been adjusted to be 160
28;; bits large. Check that we get an unlinked dbg.assign covering the deleted
29;; bits that overlap the dbg.assign's fagment: [128, 160) (offset=128 size=32).
30
31; CHECK: @_Z10shortenEndv
32; CHECK:      #dbg_assign({{.*}}, ptr %local, !DIExpression(),
33; CHECK:      call void @llvm.memset{{.*}}, !DIAssignID ![[ID:[0-9]+]]
34; CHECK-NEXT: #dbg_assign(i8 0, ![[VAR:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 64, 96), ![[ID:[0-9]+]], ptr %offset_4_bytes, !DIExpression(DW_OP_plus_uconst, 4),
35; CHECK-NEXT: #dbg_assign(i8 0, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 128, 32), ![[UniqueID1:[0-9]+]], ptr poison, !DIExpression({{.*}}),
36
37;; DSE will shorten the first store in shortenStart from [0, 160) bits to [128,
38;; 160) bits. Variable 'local2' has been adjusted to be 160 bits.  Check we get
39;; an unlinked dbg.assign covering the deleted bits that overlap the
40;; dbg.assign's fragment (no fragment in this case, i.e. the whole variable):
41;; [0, 128) (offset=0, size=128).
42
43; CHECK: @_Z12shortenStartv
44; CHECK:      #dbg_assign({{.*}}, ptr %local2, !DIExpression(),
45; CHECK:      call void @llvm.memset{{.*}}, !DIAssignID ![[ID2:[0-9]+]]
46; CHECK-NEXT: #dbg_assign(i8 0, ![[VAR2:[0-9]+]], !DIExpression(), ![[ID2]], ptr %local2, !DIExpression(),
47; CHECK-NEXT: #dbg_assign(i8 0, ![[VAR2]], !DIExpression(DW_OP_LLVM_fragment, 0, 128), ![[UniqueID2:[0-9]+]], ptr poison, !DIExpression(),
48
49; CHECK-DAG: ![[ID]] = distinct !DIAssignID()
50; CHECK-DAG: ![[UniqueID1]] = distinct !DIAssignID()
51; CHECK-DAG: ![[UniqueID2]] = distinct !DIAssignID()
52
53define dso_local void @_Z10shortenEndv() local_unnamed_addr #0 !dbg !7 {
54entry:
55  %local = alloca [80 x i8], align 16, !DIAssignID !16
56  call void @llvm.dbg.assign(metadata i1 poison, metadata !11, metadata !DIExpression(), metadata !16, metadata ptr %local, metadata !DIExpression()), !dbg !17
57  %arraydecay = getelementptr inbounds [80 x i8], ptr %local, i64 0, i64 0, !dbg !19
58  %offset_4_bytes = getelementptr inbounds [80 x i8], ptr %local, i64 0, i64 4, !dbg !21
59  %offset_8_bytes = getelementptr inbounds [80 x i8], ptr %local, i64 0, i64 8, !dbg !21
60  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %offset_8_bytes, i8 0, i64 72, i1 false), !dbg !19, !DIAssignID !20
61  call void @llvm.dbg.assign(metadata i8 0, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 96), metadata !20, metadata ptr %offset_4_bytes, metadata !DIExpression(DW_OP_plus_uconst, 4)), !dbg !17
62  %offset_16_bytes = getelementptr inbounds [80 x i8], ptr %local, i64 0, i64 4, !dbg !21
63  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %offset_16_bytes, i8 8, i64 64, i1 false), !dbg !22, !DIAssignID !23
64  call void @_Z3escPi(ptr noundef nonnull %arraydecay), !dbg !24
65  ret void, !dbg !25
66}
67
68declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)
69declare !dbg !26 dso_local void @_Z3escPi(ptr noundef) local_unnamed_addr
70
71define dso_local void @_Z12shortenStartv() local_unnamed_addr #0 !dbg !31 {
72entry:
73  %local2 = alloca [40 x i8], align 16, !DIAssignID !37
74  call void @llvm.dbg.assign(metadata i1 poison, metadata !33, metadata !DIExpression(), metadata !37, metadata ptr %local2, metadata !DIExpression()), !dbg !38
75  %arraydecay = getelementptr inbounds [40 x i8], ptr %local2, i64 0, i64 0, !dbg !40
76  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %local2, i8 0, i64 36, i1 false), !dbg !40, !DIAssignID !41
77  call void @llvm.dbg.assign(metadata i8 0, metadata !33, metadata !DIExpression(), metadata !41, metadata ptr %local2, metadata !DIExpression()), !dbg !38
78  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %local2, i8 8, i64 16, i1 false), !dbg !42, !DIAssignID !43
79  call void @_Z3escPi(ptr noundef nonnull %arraydecay), !dbg !44
80  ret void, !dbg !45
81}
82
83declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
84
85!llvm.dbg.cu = !{!0}
86!llvm.module.flags = !{!2, !3, !4, !5, !1000}
87!llvm.ident = !{!6}
88
89!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
90!1 = !DIFile(filename: "test.cpp", directory: "/")
91!2 = !{i32 7, !"Dwarf Version", i32 5}
92!3 = !{i32 2, !"Debug Info Version", i32 3}
93!4 = !{i32 1, !"wchar_size", i32 4}
94!5 = !{i32 7, !"uwtable", i32 1}
95!6 = !{!"clang version 14.0.0"}
96!7 = distinct !DISubprogram(name: "shortenEnd", linkageName: "_Z10shortenEndv", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)
97!8 = !DISubroutineType(types: !9)
98!9 = !{null}
99!10 = !{!11}
100!11 = !DILocalVariable(name: "local", scope: !7, file: !1, line: 3, type: !12)
101!12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, size: 160, elements: !14)
102!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
103!14 = !{!15}
104!15 = !DISubrange(count: 5)
105!16 = distinct !DIAssignID()
106!17 = !DILocation(line: 0, scope: !7)
107!18 = !DILocation(line: 3, column: 3, scope: !7)
108!19 = !DILocation(line: 4, column: 3, scope: !7)
109!20 = distinct !DIAssignID()
110!21 = !DILocation(line: 5, column: 26, scope: !7)
111!22 = !DILocation(line: 5, column: 3, scope: !7)
112!23 = distinct !DIAssignID()
113!24 = !DILocation(line: 6, column: 3, scope: !7)
114!25 = !DILocation(line: 7, column: 1, scope: !7)
115!26 = !DISubprogram(name: "esc", linkageName: "_Z3escPi", scope: !1, file: !1, line: 1, type: !27, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !30)
116!27 = !DISubroutineType(types: !28)
117!28 = !{null, !29}
118!29 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
119!30 = !{}
120!31 = distinct !DISubprogram(name: "shortenStart", linkageName: "_Z12shortenStartv", scope: !1, file: !1, line: 8, type: !8, scopeLine: 8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !32)
121!32 = !{!33}
122!33 = !DILocalVariable(name: "local2", scope: !31, file: !1, line: 9, type: !34)
123!34 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, size: 160, elements: !35)
124!35 = !{!36}
125!36 = !DISubrange(count: 5)
126!37 = distinct !DIAssignID()
127!38 = !DILocation(line: 0, scope: !31)
128!39 = !DILocation(line: 9, column: 3, scope: !31)
129!40 = !DILocation(line: 10, column: 3, scope: !31)
130!41 = distinct !DIAssignID()
131!42 = !DILocation(line: 11, column: 3, scope: !31)
132!43 = distinct !DIAssignID()
133!44 = !DILocation(line: 12, column: 3, scope: !31)
134!45 = !DILocation(line: 13, column: 1, scope: !31)
135!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
136