1; RUN: opt -passes=sroa -S %s -o - | FileCheck %s 2; RUN: opt --try-experimental-debuginfo-iterators -passes=sroa -S %s -o - | FileCheck %s 3 4;; Check that multiple dbg.assign intrinsics linked to a store that is getting 5;; split (or at least that is touched by SROA, causing a replacement store to 6;; be generated) are still both linked to the new store(s). 7;; 8;; Additionally, check that SROA inserts new dbg.assign intrinsics by the 9;; originals. 10 11;; $ cat test.cpp 12;; class a { 13;; public: 14;; a(int, float &) {} 15;; }; 16;; float b, d; 17;; int c; 18;; void f() { 19;; float e; 20;; if (c) 21;; e = b; 22;; else 23;; e = b / d; 24;; a(c, e); 25;; } 26;; 27;; Generated by grabbing IR before sroa in: 28;; $ clang++ -O2 -g -c test.cpp -Xclang -fexperimental-assignment-tracking 29 30; CHECK: if.then: 31; CHECK-NEXT: %1 = load float 32; CHECK-NEXT: #dbg_value(float %storemerge, ![[var:[0-9]+]], !DIExpression(), 33 34; CHECK: if.else: 35; CHECK-NEXT: %2 = load float 36; CHECK-NEXT: %3 = load float 37; CHECK-NEXT: %div = fdiv float 38; CHECK: #dbg_value(float %storemerge, ![[var]], !DIExpression(), 39 40%class.a = type { i8 } 41 42$_ZN1aC2EiRf = comdat any 43 44@b = dso_local local_unnamed_addr global float 0.000000e+00, align 4, !dbg !0 45@d = dso_local local_unnamed_addr global float 0.000000e+00, align 4, !dbg !6 46@c = dso_local local_unnamed_addr global i32 0, align 4, !dbg !9 47 48; Function Attrs: nounwind readonly uwtable 49define dso_local void @_Z1fv() local_unnamed_addr #0 !dbg !16 { 50entry: 51 %e = alloca float, align 4, !DIAssignID !21 52 call void @llvm.dbg.assign(metadata i1 undef, metadata !20, metadata !DIExpression(), metadata !21, metadata ptr %e, metadata !DIExpression()), !dbg !22 53 %agg.tmp.ensured = alloca %class.a, align 1 54 %0 = bitcast ptr %e to ptr, !dbg !23 55 call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %0) #4, !dbg !23 56 %1 = load i32, ptr @c, align 4, !dbg !24 57 %tobool.not = icmp eq i32 %1, 0, !dbg !24 58 br i1 %tobool.not, label %if.else, label %if.then, !dbg !30 59 60if.then: ; preds = %entry 61 %2 = load float, ptr @b, align 4, !dbg !31 62 call void @llvm.dbg.assign(metadata float %2, metadata !20, metadata !DIExpression(), metadata !34, metadata ptr %e, metadata !DIExpression()), !dbg !22 63 br label %if.end, !dbg !35 64 65if.else: ; preds = %entry 66 %3 = load float, ptr @b, align 4, !dbg !36 67 %4 = load float, ptr @d, align 4, !dbg !37 68 %div = fdiv float %3, %4, !dbg !38 69 call void @llvm.dbg.assign(metadata float %div, metadata !20, metadata !DIExpression(), metadata !34, metadata ptr %e, metadata !DIExpression()), !dbg !22 70 br label %if.end 71 72if.end: ; preds = %if.else, %if.then 73 %storemerge = phi float [ %div, %if.else ], [ %2, %if.then ], !dbg !39 74 store float %storemerge, ptr %e, align 4, !dbg !39, !DIAssignID !34 75 %5 = load i32, ptr @c, align 4, !dbg !40 76 call void @llvm.dbg.assign(metadata i1 undef, metadata !41, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !55 77 call void @llvm.dbg.assign(metadata i1 undef, metadata !51, metadata !DIExpression(), metadata !57, metadata ptr undef, metadata !DIExpression()), !dbg !55 78 call void @llvm.dbg.assign(metadata i1 undef, metadata !52, metadata !DIExpression(), metadata !58, metadata ptr undef, metadata !DIExpression()), !dbg !55 79 call void @llvm.dbg.assign(metadata ptr %agg.tmp.ensured, metadata !41, metadata !DIExpression(), metadata !59, metadata ptr undef, metadata !DIExpression()), !dbg !55 80 call void @llvm.dbg.assign(metadata i32 %5, metadata !51, metadata !DIExpression(), metadata !60, metadata ptr undef, metadata !DIExpression()), !dbg !55 81 call void @llvm.dbg.assign(metadata ptr %e, metadata !52, metadata !DIExpression(), metadata !61, metadata ptr undef, metadata !DIExpression()), !dbg !55 82 call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %0) #4, !dbg !62 83 ret void, !dbg !62 84} 85 86; Function Attrs: argmemonly nofree nosync nounwind willreturn 87declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1 88 89; Function Attrs: nounwind uwtable 90define linkonce_odr dso_local void @_ZN1aC2EiRf(ptr %this, i32 %0, ptr nonnull align 4 dereferenceable(4) %1) unnamed_addr #2 comdat align 2 !dbg !42 { 91entry: 92 call void @llvm.dbg.assign(metadata i1 undef, metadata !41, metadata !DIExpression(), metadata !63, metadata ptr undef, metadata !DIExpression()), !dbg !64 93 call void @llvm.dbg.assign(metadata i1 undef, metadata !51, metadata !DIExpression(), metadata !65, metadata ptr undef, metadata !DIExpression()), !dbg !64 94 call void @llvm.dbg.assign(metadata i1 undef, metadata !52, metadata !DIExpression(), metadata !66, metadata ptr undef, metadata !DIExpression()), !dbg !64 95 call void @llvm.dbg.assign(metadata ptr %this, metadata !41, metadata !DIExpression(), metadata !67, metadata ptr undef, metadata !DIExpression()), !dbg !64 96 call void @llvm.dbg.assign(metadata i32 %0, metadata !51, metadata !DIExpression(), metadata !68, metadata ptr undef, metadata !DIExpression()), !dbg !64 97 call void @llvm.dbg.assign(metadata ptr %1, metadata !52, metadata !DIExpression(), metadata !69, metadata ptr undef, metadata !DIExpression()), !dbg !64 98 ret void, !dbg !70 99} 100 101; Function Attrs: argmemonly nofree nosync nounwind willreturn 102declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1 103 104; Function Attrs: nofree nosync nounwind readnone speculatable willreturn 105declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #3 106 107!llvm.dbg.cu = !{!2} 108!llvm.module.flags = !{!12, !13, !14, !1000} 109!llvm.ident = !{!15} 110 111!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 112!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 5, type: !8, isLocal: false, isDefinition: true) 113!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) 114!3 = !DIFile(filename: "reduce.cpp", directory: "") 115!4 = !{} 116!5 = !{!0, !6, !9} 117!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) 118!7 = distinct !DIGlobalVariable(name: "d", scope: !2, file: !3, line: 5, type: !8, isLocal: false, isDefinition: true) 119!8 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float) 120!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression()) 121!10 = distinct !DIGlobalVariable(name: "c", scope: !2, file: !3, line: 6, type: !11, isLocal: false, isDefinition: true) 122!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 123!12 = !{i32 7, !"Dwarf Version", i32 4} 124!13 = !{i32 2, !"Debug Info Version", i32 3} 125!14 = !{i32 1, !"wchar_size", i32 4} 126!15 = !{!"clang version 12.0.0"} 127!16 = distinct !DISubprogram(name: "f", linkageName: "_Z1fv", scope: !3, file: !3, line: 7, type: !17, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !19) 128!17 = !DISubroutineType(types: !18) 129!18 = !{null} 130!19 = !{!20} 131!20 = !DILocalVariable(name: "e", scope: !16, file: !3, line: 8, type: !8) 132!21 = distinct !DIAssignID() 133!22 = !DILocation(line: 0, scope: !16) 134!23 = !DILocation(line: 8, column: 3, scope: !16) 135!24 = !DILocation(line: 9, column: 7, scope: !25) 136!25 = distinct !DILexicalBlock(scope: !16, file: !3, line: 9, column: 7) 137!30 = !DILocation(line: 9, column: 7, scope: !16) 138!31 = !DILocation(line: 10, column: 9, scope: !25) 139!34 = distinct !DIAssignID() 140!35 = !DILocation(line: 10, column: 5, scope: !25) 141!36 = !DILocation(line: 12, column: 9, scope: !25) 142!37 = !DILocation(line: 12, column: 13, scope: !25) 143!38 = !DILocation(line: 12, column: 11, scope: !25) 144!39 = !DILocation(line: 0, scope: !25) 145!40 = !DILocation(line: 13, column: 5, scope: !16) 146!41 = !DILocalVariable(name: "this", arg: 1, scope: !42, type: !53, flags: DIFlagArtificial | DIFlagObjectPointer) 147!42 = distinct !DISubprogram(name: "a", linkageName: "_ZN1aC2EiRf", scope: !43, file: !3, line: 3, type: !46, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, declaration: !45, retainedNodes: !50) 148!43 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "a", file: !3, line: 1, size: 8, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !44, identifier: "_ZTS1a") 149!44 = !{!45} 150!45 = !DISubprogram(name: "a", scope: !43, file: !3, line: 3, type: !46, scopeLine: 3, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized) 151!46 = !DISubroutineType(types: !47) 152!47 = !{null, !48, !11, !49} 153!48 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !43, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) 154!49 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !8, size: 64) 155!50 = !{!41, !51, !52} 156!51 = !DILocalVariable(arg: 2, scope: !42, file: !3, line: 3, type: !11) 157!52 = !DILocalVariable(arg: 3, scope: !42, file: !3, line: 3, type: !49) 158!53 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !43, size: 64) 159!54 = distinct !DIAssignID() 160!55 = !DILocation(line: 0, scope: !42, inlinedAt: !56) 161!56 = distinct !DILocation(line: 13, column: 3, scope: !16) 162!57 = distinct !DIAssignID() 163!58 = distinct !DIAssignID() 164!59 = distinct !DIAssignID() 165!60 = distinct !DIAssignID() 166!61 = distinct !DIAssignID() 167!62 = !DILocation(line: 14, column: 1, scope: !16) 168!63 = distinct !DIAssignID() 169!64 = !DILocation(line: 0, scope: !42) 170!65 = distinct !DIAssignID() 171!66 = distinct !DIAssignID() 172!67 = distinct !DIAssignID() 173!68 = distinct !DIAssignID() 174!69 = distinct !DIAssignID() 175!70 = !DILocation(line: 3, column: 20, scope: !42) 176!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true} 177