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