1; RUN: opt %s -S -passes=memcpyopt -o - | FileCheck %s 2; RUN: opt --try-experimental-debuginfo-iterators %s -S -passes=memcpyopt -o - | FileCheck %s 3 4;; $ cat test.cpp 5;; struct v { 6;; float c[4]; 7;; 8;; v(float d) { 9;; c[0] = c[1] = c[2] = d; 10;; c[3] = 0.f; 11;; } 12;; }; 13;; 14;; void esc(v*); 15;; 16;; v f() { 17;; v g(0); 18;; esc(&g); 19;; } 20;; IR grabbed before memcpyopt in: 21;; clang++ -Xclang -fexperimental-assignment-tracking -g -c -O2 test.cpp 22 23;; Check that the memset that memcpyopt creates to merge 4 stores merges the 24;; DIASsignIDs from the stores. 25 26; CHECK: #dbg_assign(float 0.000000e+00, ![[VAR:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 64, 32), ![[ID:[0-9]+]], ptr %arrayidx.i, !DIExpression(), 27; CHECK: #dbg_assign(float 0.000000e+00, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 32, 32), ![[ID]], ptr %arrayidx3.i, !DIExpression(), 28; CHECK: #dbg_assign(float 0.000000e+00, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 0, 32), ![[ID]], ptr %arrayidx5.i, !DIExpression(), 29; CHECK: #dbg_assign(float 0.000000e+00, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 96, 32), ![[ID]], ptr %arrayidx7.i, !DIExpression(), 30; CHECK: call void @llvm.memset{{.*}}, !DIAssignID ![[ID]] 31 32%struct.v = type { [4 x float] } 33 34$_ZN1vC2Ef = comdat any 35 36; Function Attrs: uwtable 37define dso_local void @_Z1fv() local_unnamed_addr #0 !dbg !7 { 38entry: 39 %g = alloca %struct.v, align 4, !DIAssignID !23 40 call void @llvm.dbg.assign(metadata i1 undef, metadata !11, metadata !DIExpression(), metadata !23, metadata ptr %g, metadata !DIExpression()), !dbg !24 41 call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %g) #5, !dbg !25 42 call void @llvm.dbg.assign(metadata i1 undef, metadata !26, metadata !DIExpression(), metadata !31, metadata ptr undef, metadata !DIExpression()), !dbg !32 43 call void @llvm.dbg.assign(metadata i1 undef, metadata !29, metadata !DIExpression(), metadata !34, metadata ptr undef, metadata !DIExpression()), !dbg !32 44 call void @llvm.dbg.assign(metadata ptr %g, metadata !26, metadata !DIExpression(), metadata !35, metadata ptr undef, metadata !DIExpression()), !dbg !32 45 call void @llvm.dbg.assign(metadata float 0.000000e+00, metadata !29, metadata !DIExpression(), metadata !36, metadata ptr undef, metadata !DIExpression()), !dbg !32 46 %arrayidx.i = getelementptr inbounds %struct.v, ptr %g, i64 0, i32 0, i64 2, !dbg !37 47 store float 0.000000e+00, ptr %arrayidx.i, align 4, !dbg !39, !DIAssignID !44 48 call void @llvm.dbg.assign(metadata float 0.000000e+00, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 32), metadata !44, metadata ptr %arrayidx.i, metadata !DIExpression()), !dbg !24 49 %arrayidx3.i = getelementptr inbounds %struct.v, ptr %g, i64 0, i32 0, i64 1, !dbg !45 50 store float 0.000000e+00, ptr %arrayidx3.i, align 4, !dbg !46, !DIAssignID !47 51 call void @llvm.dbg.assign(metadata float 0.000000e+00, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32), metadata !47, metadata ptr %arrayidx3.i, metadata !DIExpression()), !dbg !24 52 %arrayidx5.i = getelementptr inbounds %struct.v, ptr %g, i64 0, i32 0, i64 0, !dbg !48 53 store float 0.000000e+00, ptr %arrayidx5.i, align 4, !dbg !49, !DIAssignID !50 54 call void @llvm.dbg.assign(metadata float 0.000000e+00, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32), metadata !50, metadata ptr %arrayidx5.i, metadata !DIExpression()), !dbg !24 55 %arrayidx7.i = getelementptr inbounds %struct.v, ptr %g, i64 0, i32 0, i64 3, !dbg !51 56 store float 0.000000e+00, ptr %arrayidx7.i, align 4, !dbg !52, !DIAssignID !53 57 call void @llvm.dbg.assign(metadata float 0.000000e+00, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 96, 32), metadata !53, metadata ptr %arrayidx7.i, metadata !DIExpression()), !dbg !24 58 call void @_Z3escP1v(ptr nonnull %g), !dbg !54 59 call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %g) #5, !dbg !55 60 ret void, !dbg !55 61} 62 63; Function Attrs: argmemonly nofree nosync nounwind willreturn 64declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1 65 66; Function Attrs: nounwind uwtable 67define linkonce_odr dso_local void @_ZN1vC2Ef(ptr %this, float %d) unnamed_addr #2 comdat align 2 !dbg !27 { 68entry: 69 call void @llvm.dbg.assign(metadata i1 undef, metadata !26, metadata !DIExpression(), metadata !56, metadata ptr undef, metadata !DIExpression()), !dbg !57 70 call void @llvm.dbg.assign(metadata i1 undef, metadata !29, metadata !DIExpression(), metadata !58, metadata ptr undef, metadata !DIExpression()), !dbg !57 71 call void @llvm.dbg.assign(metadata ptr %this, metadata !26, metadata !DIExpression(), metadata !59, metadata ptr undef, metadata !DIExpression()), !dbg !57 72 call void @llvm.dbg.assign(metadata float %d, metadata !29, metadata !DIExpression(), metadata !60, metadata ptr undef, metadata !DIExpression()), !dbg !57 73 %arrayidx = getelementptr inbounds %struct.v, ptr %this, i64 0, i32 0, i64 2, !dbg !61 74 store float %d, ptr %arrayidx, align 4, !dbg !62 75 %arrayidx3 = getelementptr inbounds %struct.v, ptr %this, i64 0, i32 0, i64 1, !dbg !63 76 store float %d, ptr %arrayidx3, align 4, !dbg !64 77 %arrayidx5 = getelementptr inbounds %struct.v, ptr %this, i64 0, i32 0, i64 0, !dbg !65 78 store float %d, ptr %arrayidx5, align 4, !dbg !66 79 %arrayidx7 = getelementptr inbounds %struct.v, ptr %this, i64 0, i32 0, i64 3, !dbg !67 80 store float 0.000000e+00, ptr %arrayidx7, align 4, !dbg !68 81 ret void, !dbg !69 82} 83 84declare !dbg !70 dso_local void @_Z3escP1v(ptr) local_unnamed_addr 85declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) 86declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) 87 88!llvm.dbg.cu = !{!0} 89!llvm.module.flags = !{!3, !4, !5, !1000} 90!llvm.ident = !{!6} 91 92!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) 93!1 = !DIFile(filename: "reduce.cpp", directory: "/") 94!2 = !{} 95!3 = !{i32 7, !"Dwarf Version", i32 4} 96!4 = !{i32 2, !"Debug Info Version", i32 3} 97!5 = !{i32 1, !"wchar_size", i32 4} 98!6 = !{!"clang version 12.0.0"} 99!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) 100!8 = !DISubroutineType(types: !9) 101!9 = !{null} 102!10 = !{!11} 103!11 = !DILocalVariable(name: "g", scope: !7, file: !1, line: 13, type: !12) 104!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v", file: !1, line: 1, size: 128, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !13, identifier: "_ZTS1v") 105!13 = !{!14, !19} 106!14 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !12, file: !1, line: 2, baseType: !15, size: 128) 107!15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !16, size: 128, elements: !17) 108!16 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float) 109!17 = !{!18} 110!18 = !DISubrange(count: 4) 111!19 = !DISubprogram(name: "v", scope: !12, file: !1, line: 4, type: !20, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized) 112!20 = !DISubroutineType(types: !21) 113!21 = !{null, !22, !16} 114!22 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) 115!23 = distinct !DIAssignID() 116!24 = !DILocation(line: 0, scope: !7) 117!25 = !DILocation(line: 13, column: 3, scope: !7) 118!26 = !DILocalVariable(name: "this", arg: 1, scope: !27, type: !30, flags: DIFlagArtificial | DIFlagObjectPointer) 119!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) 120!28 = !{!26, !29} 121!29 = !DILocalVariable(name: "d", arg: 2, scope: !27, file: !1, line: 4, type: !16) 122!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64) 123!31 = distinct !DIAssignID() 124!32 = !DILocation(line: 0, scope: !27, inlinedAt: !33) 125!33 = distinct !DILocation(line: 13, column: 5, scope: !7) 126!34 = distinct !DIAssignID() 127!35 = distinct !DIAssignID() 128!36 = distinct !DIAssignID() 129!37 = !DILocation(line: 5, column: 19, scope: !38, inlinedAt: !33) 130!38 = distinct !DILexicalBlock(scope: !27, file: !1, line: 4, column: 14) 131!39 = !DILocation(line: 5, column: 24, scope: !38, inlinedAt: !33) 132!44 = distinct !DIAssignID() 133!45 = !DILocation(line: 5, column: 12, scope: !38, inlinedAt: !33) 134!46 = !DILocation(line: 5, column: 17, scope: !38, inlinedAt: !33) 135!47 = distinct !DIAssignID() 136!48 = !DILocation(line: 5, column: 5, scope: !38, inlinedAt: !33) 137!49 = !DILocation(line: 5, column: 10, scope: !38, inlinedAt: !33) 138!50 = distinct !DIAssignID() 139!51 = !DILocation(line: 6, column: 5, scope: !38, inlinedAt: !33) 140!52 = !DILocation(line: 6, column: 10, scope: !38, inlinedAt: !33) 141!53 = distinct !DIAssignID() 142!54 = !DILocation(line: 14, column: 3, scope: !7) 143!55 = !DILocation(line: 15, column: 1, scope: !7) 144!56 = distinct !DIAssignID() 145!57 = !DILocation(line: 0, scope: !27) 146!58 = distinct !DIAssignID() 147!59 = distinct !DIAssignID() 148!60 = distinct !DIAssignID() 149!61 = !DILocation(line: 5, column: 19, scope: !38) 150!62 = !DILocation(line: 5, column: 24, scope: !38) 151!63 = !DILocation(line: 5, column: 12, scope: !38) 152!64 = !DILocation(line: 5, column: 17, scope: !38) 153!65 = !DILocation(line: 5, column: 5, scope: !38) 154!66 = !DILocation(line: 5, column: 10, scope: !38) 155!67 = !DILocation(line: 6, column: 5, scope: !38) 156!68 = !DILocation(line: 6, column: 10, scope: !38) 157!69 = !DILocation(line: 7, column: 3, scope: !27) 158!70 = !DISubprogram(name: "esc", linkageName: "_Z3escP1v", scope: !1, file: !1, line: 10, type: !71, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2) 159!71 = !DISubroutineType(types: !72) 160!72 = !{null, !30} 161!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true} 162