xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/sroa/user-memcpy.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -passes=sroa -S %s -o - \
2; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
3; RUN: opt --try-experimental-debuginfo-iterators -passes=sroa -S %s -o - \
4; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
5
6;; Check that the fragments generated in SROA for a split alloca that has a
7;; dbg.assign with non-zero-offset fragment are correct.
8
9;; $ cat test.cpp
10;; #include <cstring>
11;;
12;; struct V3i { long x, y, z; };
13;; void fun() {
14;;   V3i point = {0, 0, 0};
15;;   point.z = 5000;
16;;   V3i other = {10, 9, 8};
17;;   std::memcpy(&point.y, &other.x, sizeof(long) * 2);
18;; }
19;; $ clang++ -c -O2 -g test.cpp -o - -Xclang -disable-llvm-passes -S -emit-llvm \
20;;   | opt -passes=declare-to-assign -S -o -
21
22; CHECK: entry:
23;; Allocas have been promoted - the linked dbg.assigns have been removed.
24
25;; | V3i point = {0, 0, 0};
26; CHECK-NEXT: #dbg_value(i64 0, ![[point:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 0, 64),
27; CHECK-NEXT: #dbg_value(i64 0, ![[point]], !DIExpression(DW_OP_LLVM_fragment, 64, 64),
28
29;; point.z = 5000;
30; CHECK-NEXT: #dbg_value(i64 5000, ![[point]], !DIExpression(DW_OP_LLVM_fragment, 128, 64),
31
32;; | V3i other = {10, 9, 8};
33;;   other is global const:
34;;     local.other.x = global.other.x
35;;     local.other.y = global.other.y
36;;     local.other.z = global.other.z
37; CHECK-NEXT: %other.sroa.0.0.copyload = load i64, ptr @__const._Z3funv.other
38; CHECK-NEXT: %other.sroa.2.0.copyload = load i64, ptr getelementptr inbounds (i8, ptr @__const._Z3funv.other, i64 8)
39; CHECK-NEXT: %other.sroa.3.0.copyload = load i64, ptr getelementptr inbounds (i8, ptr @__const._Z3funv.other, i64 16)
40; CHECK-NEXT: #dbg_value(i64 %other.sroa.0.0.copyload, ![[other:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 0, 64),
41; CHECK-NEXT: #dbg_value(i64 %other.sroa.2.0.copyload, ![[other]], !DIExpression(DW_OP_LLVM_fragment, 64, 64),
42; CHECK-NEXT: #dbg_value(i64 %other.sroa.3.0.copyload, ![[other]], !DIExpression(DW_OP_LLVM_fragment, 128, 64),
43
44;; | std::memcpy(&point.y, &other.x, sizeof(long) * 2);
45;;   other is now 3 scalars:
46;;     point.y = other.x
47; CHECK-NEXT: #dbg_value(i64 %other.sroa.0.0.copyload, ![[point]], !DIExpression(DW_OP_LLVM_fragment, 64, 64),
48;;
49;;     point.z = other.y
50; CHECK-NEXT: #dbg_value(i64 %other.sroa.2.0.copyload, ![[point]], !DIExpression(DW_OP_LLVM_fragment, 128, 64),
51
52; CHECK: ![[point]] = !DILocalVariable(name: "point",
53; CHECK: ![[other]] = !DILocalVariable(name: "other",
54
55source_filename = "test.cpp"
56target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
57target triple = "x86_64-unknown-linux-gnu"
58
59%struct.V3i = type { i64, i64, i64 }
60
61@__const._Z3funv.other = private unnamed_addr constant %struct.V3i { i64 10, i64 9, i64 8 }, align 8
62
63; Function Attrs: nounwind uwtable mustprogress
64define dso_local void @_Z3funv() !dbg !100 {
65entry:
66  %point = alloca %struct.V3i, align 8, !DIAssignID !112
67  call void @llvm.dbg.assign(metadata i1 undef, metadata !104, metadata !DIExpression(), metadata !112, metadata ptr %point, metadata !DIExpression()), !dbg !113
68  %other = alloca %struct.V3i, align 8, !DIAssignID !114
69  call void @llvm.dbg.assign(metadata i1 undef, metadata !111, metadata !DIExpression(), metadata !114, metadata ptr %other, metadata !DIExpression()), !dbg !113
70  %0 = bitcast ptr %point to ptr, !dbg !115
71  %1 = bitcast ptr %point to ptr, !dbg !116
72  call void @llvm.memset.p0.i64(ptr align 8 %1, i8 0, i64 24, i1 false), !dbg !116, !DIAssignID !117
73  call void @llvm.dbg.assign(metadata i8 0, metadata !104, metadata !DIExpression(), metadata !117, metadata ptr %1, metadata !DIExpression()), !dbg !116
74  %z = getelementptr inbounds %struct.V3i, ptr %point, i32 0, i32 2, !dbg !118
75  store i64 5000, ptr %z, align 8, !dbg !119, !DIAssignID !125
76  call void @llvm.dbg.assign(metadata i64 5000, metadata !104, metadata !DIExpression(DW_OP_LLVM_fragment, 128, 64), metadata !125, metadata ptr %z, metadata !DIExpression()), !dbg !119
77  %2 = bitcast ptr %other to ptr, !dbg !126
78  %3 = bitcast ptr %other to ptr, !dbg !127
79  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 @__const._Z3funv.other, i64 24, i1 false), !dbg !127, !DIAssignID !128
80  call void @llvm.dbg.assign(metadata i1 undef, metadata !111, metadata !DIExpression(), metadata !128, metadata ptr %3, metadata !DIExpression()), !dbg !127
81  %y = getelementptr inbounds %struct.V3i, ptr %point, i32 0, i32 1, !dbg !129
82  %4 = bitcast ptr %y to ptr, !dbg !130
83  %x = getelementptr inbounds %struct.V3i, ptr %other, i32 0, i32 0, !dbg !131
84  %5 = bitcast ptr %x to ptr, !dbg !130
85  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %5, i64 16, i1 false), !dbg !130, !DIAssignID !132
86  call void @llvm.dbg.assign(metadata i1 undef, metadata !104, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 128), metadata !132, metadata ptr %4, metadata !DIExpression()), !dbg !130
87  %6 = bitcast ptr %other to ptr, !dbg !133
88  %7 = bitcast ptr %point to ptr, !dbg !133
89  ret void, !dbg !133
90}
91
92declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)
93declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg)
94declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
95
96!llvm.dbg.cu = !{!0}
97!llvm.module.flags = !{!96, !97, !98, !1000}
98!llvm.ident = !{!99}
99
100!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, imports: !3, splitDebugInlining: false, nameTableKind: None)
101!1 = !DIFile(filename: "test.cpp", directory: "/")
102!2 = !{}
103!3 = !{!4, !18, !22, !28, !32, !36, !46, !50, !52, !54, !58, !62, !66, !70, !74, !76, !78, !80, !84, !88, !92, !94}
104!4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !6, file: !17, line: 75)
105!5 = !DINamespace(name: "std", scope: null)
106!6 = !DISubprogram(name: "memchr", scope: !7, file: !7, line: 90, type: !8, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
107!7 = !DIFile(filename: "/usr/include/string.h", directory: "")
108!8 = !DISubroutineType(types: !9)
109!9 = !{!10, !11, !13, !14}
110!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
111!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
112!12 = !DIDerivedType(tag: DW_TAG_const_type, baseType: null)
113!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
114!14 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !15, line: 46, baseType: !16)
115!15 = !DIFile(filename: "lib/clang/12.0.0/include/stddef.h", directory: "/")
116!16 = !DIBasicType(name: "long unsigned int", size: 64, encoding: DW_ATE_unsigned)
117!17 = !DIFile(filename: "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/cstring", directory: "")
118!18 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !19, file: !17, line: 76)
119!19 = !DISubprogram(name: "memcmp", scope: !7, file: !7, line: 63, type: !20, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
120!20 = !DISubroutineType(types: !21)
121!21 = !{!13, !11, !11, !14}
122!22 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !23, file: !17, line: 77)
123!23 = !DISubprogram(name: "memcpy", scope: !7, file: !7, line: 42, type: !24, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
124!24 = !DISubroutineType(types: !25)
125!25 = !{!10, !26, !27, !14}
126!26 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !10)
127!27 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !11)
128!28 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !29, file: !17, line: 78)
129!29 = !DISubprogram(name: "memmove", scope: !7, file: !7, line: 46, type: !30, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
130!30 = !DISubroutineType(types: !31)
131!31 = !{!10, !10, !11, !14}
132!32 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !33, file: !17, line: 79)
133!33 = !DISubprogram(name: "memset", scope: !7, file: !7, line: 60, type: !34, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
134!34 = !DISubroutineType(types: !35)
135!35 = !{!10, !10, !13, !14}
136!36 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !37, file: !17, line: 80)
137!37 = !DISubprogram(name: "strcat", scope: !7, file: !7, line: 129, type: !38, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
138!38 = !DISubroutineType(types: !39)
139!39 = !{!40, !42, !43}
140!40 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !41, size: 64)
141!41 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
142!42 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !40)
143!43 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !44)
144!44 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !45, size: 64)
145!45 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !41)
146!46 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !47, file: !17, line: 81)
147!47 = !DISubprogram(name: "strcmp", scope: !7, file: !7, line: 136, type: !48, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
148!48 = !DISubroutineType(types: !49)
149!49 = !{!13, !44, !44}
150!50 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !51, file: !17, line: 82)
151!51 = !DISubprogram(name: "strcoll", scope: !7, file: !7, line: 143, type: !48, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
152!52 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !53, file: !17, line: 83)
153!53 = !DISubprogram(name: "strcpy", scope: !7, file: !7, line: 121, type: !38, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
154!54 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !55, file: !17, line: 84)
155!55 = !DISubprogram(name: "strcspn", scope: !7, file: !7, line: 272, type: !56, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
156!56 = !DISubroutineType(types: !57)
157!57 = !{!14, !44, !44}
158!58 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !59, file: !17, line: 85)
159!59 = !DISubprogram(name: "strerror", scope: !7, file: !7, line: 396, type: !60, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
160!60 = !DISubroutineType(types: !61)
161!61 = !{!40, !13}
162!62 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !63, file: !17, line: 86)
163!63 = !DISubprogram(name: "strlen", scope: !7, file: !7, line: 384, type: !64, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
164!64 = !DISubroutineType(types: !65)
165!65 = !{!14, !44}
166!66 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !67, file: !17, line: 87)
167!67 = !DISubprogram(name: "strncat", scope: !7, file: !7, line: 132, type: !68, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
168!68 = !DISubroutineType(types: !69)
169!69 = !{!40, !42, !43, !14}
170!70 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !71, file: !17, line: 88)
171!71 = !DISubprogram(name: "strncmp", scope: !7, file: !7, line: 139, type: !72, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
172!72 = !DISubroutineType(types: !73)
173!73 = !{!13, !44, !44, !14}
174!74 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !75, file: !17, line: 89)
175!75 = !DISubprogram(name: "strncpy", scope: !7, file: !7, line: 124, type: !68, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
176!76 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !77, file: !17, line: 90)
177!77 = !DISubprogram(name: "strspn", scope: !7, file: !7, line: 276, type: !56, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
178!78 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !79, file: !17, line: 91)
179!79 = !DISubprogram(name: "strtok", scope: !7, file: !7, line: 335, type: !38, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
180!80 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !81, file: !17, line: 92)
181!81 = !DISubprogram(name: "strxfrm", scope: !7, file: !7, line: 146, type: !82, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
182!82 = !DISubroutineType(types: !83)
183!83 = !{!14, !42, !43, !14}
184!84 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !85, file: !17, line: 93)
185!85 = !DISubprogram(name: "strchr", scope: !7, file: !7, line: 225, type: !86, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
186!86 = !DISubroutineType(types: !87)
187!87 = !{!40, !44, !13}
188!88 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !89, file: !17, line: 94)
189!89 = !DISubprogram(name: "strpbrk", scope: !7, file: !7, line: 302, type: !90, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
190!90 = !DISubroutineType(types: !91)
191!91 = !{!40, !44, !44}
192!92 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !93, file: !17, line: 95)
193!93 = !DISubprogram(name: "strrchr", scope: !7, file: !7, line: 252, type: !86, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
194!94 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !95, file: !17, line: 96)
195!95 = !DISubprogram(name: "strstr", scope: !7, file: !7, line: 329, type: !90, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
196!96 = !{i32 7, !"Dwarf Version", i32 4}
197!97 = !{i32 2, !"Debug Info Version", i32 3}
198!98 = !{i32 1, !"wchar_size", i32 4}
199!99 = !{!"clang version 12.0.0"}
200!100 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !1, file: !1, line: 4, type: !101, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !103)
201!101 = !DISubroutineType(types: !102)
202!102 = !{null}
203!103 = !{!104, !111}
204!104 = !DILocalVariable(name: "point", scope: !100, file: !1, line: 5, type: !105)
205!105 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "V3i", file: !1, line: 3, size: 192, flags: DIFlagTypePassByValue, elements: !106, identifier: "_ZTS3V3i")
206!106 = !{!107, !109, !110}
207!107 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !105, file: !1, line: 3, baseType: !108, size: 64)
208!108 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
209!109 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !105, file: !1, line: 3, baseType: !108, size: 64, offset: 64)
210!110 = !DIDerivedType(tag: DW_TAG_member, name: "z", scope: !105, file: !1, line: 3, baseType: !108, size: 64, offset: 128)
211!111 = !DILocalVariable(name: "other", scope: !100, file: !1, line: 7, type: !105)
212!112 = distinct !DIAssignID()
213!113 = !DILocation(line: 0, scope: !100)
214!114 = distinct !DIAssignID()
215!115 = !DILocation(line: 5, column: 3, scope: !100)
216!116 = !DILocation(line: 5, column: 7, scope: !100)
217!117 = distinct !DIAssignID()
218!118 = !DILocation(line: 6, column: 9, scope: !100)
219!119 = !DILocation(line: 6, column: 11, scope: !100)
220!125 = distinct !DIAssignID()
221!126 = !DILocation(line: 7, column: 3, scope: !100)
222!127 = !DILocation(line: 7, column: 7, scope: !100)
223!128 = distinct !DIAssignID()
224!129 = !DILocation(line: 8, column: 22, scope: !100)
225!130 = !DILocation(line: 8, column: 3, scope: !100)
226!131 = !DILocation(line: 8, column: 32, scope: !100)
227!132 = distinct !DIAssignID()
228!133 = !DILocation(line: 9, column: 1, scope: !100)
229!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
230