xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/dse/dse-after-memcpyopt-merge.ll (revision 2499978aae8398023363a157185c8021c32ea363)
1571eaeadSOCHyams; RUN: opt %s -S -passes=dse -o - | FileCheck %s --implicit-check-not="call void @llvm.dbg"
2632f44e5SStephen Tozer; RUN: opt --try-experimental-debuginfo-iterators %s -S -passes=dse -o - | FileCheck %s --implicit-check-not="call void @llvm.dbg"
3bfa7f624SOCHyams
4b25ad383SRoman Lebedev;; Observed in the wild, but test is created by running memcpyopt on
5bfa7f624SOCHyams;; assignment-tracking/memcpyopt/merge-stores.ll then manually inserting
6bfa7f624SOCHyams;; two stores that overwrite each end of the memset.
7bfa7f624SOCHyams;;
8bfa7f624SOCHyams;; A memory intrinsic (or vector instruction) might have multiple dbg.assigns
9bfa7f624SOCHyams;; linked to it if it has been created as a result of merging scalar stores,
10bfa7f624SOCHyams;; such as in this example. DSE is going to shorten the memset because there's
11571eaeadSOCHyams;; a later store that overwrites part of it. Unlink the dbg.assigns that
12571eaeadSOCHyams;; describe the overlapping fragments.
13bfa7f624SOCHyams
14bfa7f624SOCHyams;; Check that there's an unlinked dbg.assign inserted after each overlapping
15bfa7f624SOCHyams;; fragment of the shortened store.
16bfa7f624SOCHyams;;
1709457270SStephen Tozer; CHECK: #dbg_assign({{.*}}, ptr %g, !DIExpression(),
1809457270SStephen Tozer; CHECK: #dbg_assign(float 0.000000e+00, ![[#]], !DIExpression(DW_OP_LLVM_fragment, 64, 32), ![[ID:[0-9]+]], ptr %arrayidx.i, !DIExpression(),
1909457270SStephen Tozer; CHECK: #dbg_assign(float 0.000000e+00, ![[#]], !DIExpression(DW_OP_LLVM_fragment, 32, 32), ![[ID]], ptr %arrayidx3.i, !DIExpression(),
20*2499978aSNuno Lopes; CHECK: #dbg_assign(float 0.000000e+00, ![[#]], !DIExpression(DW_OP_LLVM_fragment, 0, 32), ![[UniqueID1:[0-9]+]], ptr poison, !DIExpression(),
21*2499978aSNuno Lopes; CHECK: #dbg_assign(float 0.000000e+00, ![[#]], !DIExpression(DW_OP_LLVM_fragment, 96, 32), ![[UniqueID2:[0-9]+]], ptr poison, !DIExpression(),
22bfa7f624SOCHyams; CHECK: call void @llvm.memset{{.*}}, !DIAssignID ![[ID]]
23bfa7f624SOCHyams
24bfa7f624SOCHyams; CHECK-DAG: ![[ID]] = distinct !DIAssignID()
25bfa7f624SOCHyams; CHECK-DAG: ![[UniqueID1]] = distinct !DIAssignID()
26bfa7f624SOCHyams; CHECK-DAG: ![[UniqueID2]] = distinct !DIAssignID()
27bfa7f624SOCHyams
28bfa7f624SOCHyams%struct.v = type { [4 x float] }
29bfa7f624SOCHyams
30bfa7f624SOCHyams$_ZN1vC2Ef = comdat any
31bfa7f624SOCHyams
32bfa7f624SOCHyamsdefine dso_local void @_Z1fv() local_unnamed_addr !dbg !7 {
33bfa7f624SOCHyamsentry:
34bfa7f624SOCHyams  %g = alloca %struct.v, align 4, !DIAssignID !23
35*2499978aSNuno Lopes  call void @llvm.dbg.assign(metadata i1 poison, metadata !11, metadata !DIExpression(), metadata !23, metadata ptr %g, metadata !DIExpression()), !dbg !24
36bfa7f624SOCHyams   %arrayidx.i = getelementptr inbounds %struct.v, ptr %g, i64 0, i32 0, i64 2, !dbg !37
37bfa7f624SOCHyams  call void @llvm.dbg.assign(metadata float 0.000000e+00, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 32), metadata !39, metadata ptr %arrayidx.i, metadata !DIExpression()), !dbg !24
38bfa7f624SOCHyams  %arrayidx3.i = getelementptr inbounds %struct.v, ptr %g, i64 0, i32 0, i64 1, !dbg !40
39bfa7f624SOCHyams  call void @llvm.dbg.assign(metadata float 0.000000e+00, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32), metadata !39, metadata ptr %arrayidx3.i, metadata !DIExpression()), !dbg !24
40bfa7f624SOCHyams  %arrayidx5.i = getelementptr inbounds %struct.v, ptr %g, i64 0, i32 0, i64 0, !dbg !41
41bfa7f624SOCHyams  call void @llvm.dbg.assign(metadata float 0.000000e+00, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32), metadata !39, metadata ptr %arrayidx5.i, metadata !DIExpression()), !dbg !24
42bfa7f624SOCHyams  %arrayidx7.i = getelementptr inbounds %struct.v, ptr %g, i64 0, i32 0, i64 3, !dbg !42
43bfa7f624SOCHyams  call void @llvm.dbg.assign(metadata float 0.000000e+00, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 96, 32), metadata !39, metadata ptr %arrayidx7.i, metadata !DIExpression()), !dbg !24
44bfa7f624SOCHyams  %0 = bitcast ptr %arrayidx5.i to ptr, !dbg !43
453a05e01dSFangrui Song  call void @llvm.memset.p0.i64(ptr align 4 %0, i8 0, i64 16, i1 false), !dbg !44, !DIAssignID !39
46bfa7f624SOCHyams  ;; -- Start modification
47bfa7f624SOCHyams  %arrayidx7 = getelementptr inbounds %struct.v, ptr %g, i64 0, i32 0, i64 3, !dbg !24
48bfa7f624SOCHyams  store float 0.000000e+00, ptr %arrayidx7, align 4, !dbg !24, !DIAssignID !49
49bfa7f624SOCHyams  %arrayidx = getelementptr inbounds %struct.v, ptr %g, i64 0, i32 0, i64 0, !dbg !24
50bfa7f624SOCHyams  store float 0.000000e+00, ptr %arrayidx, align 4, !dbg !24, !DIAssignID !50
51bfa7f624SOCHyams  ;; -- End modification
52bfa7f624SOCHyams  call void @_Z3escP1v(ptr nonnull %g), !dbg !43
53bfa7f624SOCHyams  ret void, !dbg !45
54bfa7f624SOCHyams}
55bfa7f624SOCHyams
56bfa7f624SOCHyamsdeclare !dbg !64 dso_local void @_Z3escP1v(ptr) local_unnamed_addr
57bfa7f624SOCHyamsdeclare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
583a05e01dSFangrui Songdeclare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)
59bfa7f624SOCHyams
60bfa7f624SOCHyams!llvm.dbg.cu = !{!0}
614ece5073SOCHyams!llvm.module.flags = !{!3, !4, !5, !1000}
62bfa7f624SOCHyams!llvm.ident = !{!6}
63bfa7f624SOCHyams
64bfa7f624SOCHyams!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
65bfa7f624SOCHyams!1 = !DIFile(filename: "reduce.cpp", directory: "/")
66bfa7f624SOCHyams!2 = !{}
67bfa7f624SOCHyams!3 = !{i32 7, !"Dwarf Version", i32 4}
68bfa7f624SOCHyams!4 = !{i32 2, !"Debug Info Version", i32 3}
69bfa7f624SOCHyams!5 = !{i32 1, !"wchar_size", i32 4}
70bfa7f624SOCHyams!6 = !{!"clang version 12.0.0"}
71bfa7f624SOCHyams!7 = distinct !DISubprogram(name: "f", linkageName: "_Z1fv", scope: !1, file: !1, line: 12, type: !8, scopeLine: 12, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)
72bfa7f624SOCHyams!8 = !DISubroutineType(types: !9)
73bfa7f624SOCHyams!9 = !{null}
74bfa7f624SOCHyams!10 = !{!11}
75bfa7f624SOCHyams!11 = !DILocalVariable(name: "g", scope: !7, file: !1, line: 13, type: !12)
76bfa7f624SOCHyams!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v", file: !1, line: 1, size: 128, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !13, identifier: "_ZTS1v")
77bfa7f624SOCHyams!13 = !{!14, !19}
78bfa7f624SOCHyams!14 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !12, file: !1, line: 2, baseType: !15, size: 128)
79bfa7f624SOCHyams!15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !16, size: 128, elements: !17)
80bfa7f624SOCHyams!16 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
81bfa7f624SOCHyams!17 = !{!18}
82bfa7f624SOCHyams!18 = !DISubrange(count: 4)
83bfa7f624SOCHyams!19 = !DISubprogram(name: "v", scope: !12, file: !1, line: 4, type: !20, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
84bfa7f624SOCHyams!20 = !DISubroutineType(types: !21)
85bfa7f624SOCHyams!21 = !{null, !22, !16}
86bfa7f624SOCHyams!22 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
87bfa7f624SOCHyams!23 = distinct !DIAssignID()
88bfa7f624SOCHyams!24 = !DILocation(line: 0, scope: !7)
89bfa7f624SOCHyams!25 = !DILocation(line: 13, column: 3, scope: !7)
90bfa7f624SOCHyams!26 = !DILocalVariable(name: "this", arg: 1, scope: !27, type: !30, flags: DIFlagArtificial | DIFlagObjectPointer)
91bfa7f624SOCHyams!27 = distinct !DISubprogram(name: "v", linkageName: "_ZN1vC2Ef", scope: !12, file: !1, line: 4, type: !20, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !19, retainedNodes: !28)
92bfa7f624SOCHyams!28 = !{!26, !29}
93bfa7f624SOCHyams!29 = !DILocalVariable(name: "d", arg: 2, scope: !27, file: !1, line: 4, type: !16)
94bfa7f624SOCHyams!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
95bfa7f624SOCHyams!31 = distinct !DIAssignID()
96bfa7f624SOCHyams!32 = !DILocation(line: 0, scope: !27, inlinedAt: !33)
97bfa7f624SOCHyams!33 = distinct !DILocation(line: 13, column: 5, scope: !7)
98bfa7f624SOCHyams!34 = distinct !DIAssignID()
99bfa7f624SOCHyams!35 = distinct !DIAssignID()
100bfa7f624SOCHyams!36 = distinct !DIAssignID()
101bfa7f624SOCHyams!37 = !DILocation(line: 5, column: 19, scope: !38, inlinedAt: !33)
102bfa7f624SOCHyams!38 = distinct !DILexicalBlock(scope: !27, file: !1, line: 4, column: 14)
103bfa7f624SOCHyams!39 = distinct !DIAssignID()
104bfa7f624SOCHyams!40 = !DILocation(line: 5, column: 12, scope: !38, inlinedAt: !33)
105bfa7f624SOCHyams!41 = !DILocation(line: 5, column: 5, scope: !38, inlinedAt: !33)
106bfa7f624SOCHyams!42 = !DILocation(line: 6, column: 5, scope: !38, inlinedAt: !33)
107bfa7f624SOCHyams!43 = !DILocation(line: 14, column: 3, scope: !7)
108bfa7f624SOCHyams!44 = !DILocation(line: 5, column: 17, scope: !38, inlinedAt: !33)
109bfa7f624SOCHyams!45 = !DILocation(line: 15, column: 1, scope: !7)
110bfa7f624SOCHyams!46 = distinct !DIAssignID()
111bfa7f624SOCHyams!47 = !DILocation(line: 0, scope: !27)
112bfa7f624SOCHyams!48 = distinct !DIAssignID()
113bfa7f624SOCHyams!49 = distinct !DIAssignID()
114bfa7f624SOCHyams!50 = distinct !DIAssignID()
115bfa7f624SOCHyams!51 = !DILocation(line: 5, column: 19, scope: !38)
116bfa7f624SOCHyams!52 = !DILocation(line: 5, column: 24, scope: !38)
117bfa7f624SOCHyams!57 = !DILocation(line: 5, column: 12, scope: !38)
118bfa7f624SOCHyams!58 = !DILocation(line: 5, column: 17, scope: !38)
119bfa7f624SOCHyams!59 = !DILocation(line: 5, column: 5, scope: !38)
120bfa7f624SOCHyams!60 = !DILocation(line: 5, column: 10, scope: !38)
121bfa7f624SOCHyams!61 = !DILocation(line: 6, column: 5, scope: !38)
122bfa7f624SOCHyams!62 = !DILocation(line: 6, column: 10, scope: !38)
123bfa7f624SOCHyams!63 = !DILocation(line: 7, column: 3, scope: !27)
124bfa7f624SOCHyams!64 = !DISubprogram(name: "esc", linkageName: "_Z3escP1v", scope: !1, file: !1, line: 10, type: !65, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
125bfa7f624SOCHyams!65 = !DISubroutineType(types: !66)
126bfa7f624SOCHyams!66 = !{null, !30}
1274ece5073SOCHyams!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
128