1; RUN: opt %s -S -passes=instcombine -o - | FileCheck %s 2; RUN: opt --try-experimental-debuginfo-iterators %s -S -passes=instcombine -o - | FileCheck %s 3 4;; $ cat test.cpp 5;; class a { 6;; float b; 7;; }; 8;; class c { 9;; public: 10;; a d(); 11;; }; 12;; class e { 13;; public: 14;; c &f(); 15;; }; 16;; class g { 17;; public: 18;; void h(a &); 19;; }; 20;; class j { 21;; g k; 22;; e l; 23;; e m; 24;; bool n; 25;; void o(); 26;; }; 27;; void j::o() { 28;; int i; 29;; a p; 30;; i = 0; 31;; for (; i < 3; i++) 32;; if (n) 33;; p = l.f().d(); 34;; else 35;; p = m.f().d(); 36;; k.h(p); 37;; } 38;; 39;; Generated by grabbing IR before instcombine in: 40;; $ clang++ -O2 -g -c test.cpp -Xclang -fexperimental-assignment-tracking 41 42;; Before instcombine runs we have an unrolled loop (3 iterations). Each 43;; unrolled section is an if-diamond with a store in if.then and if.else 44;; block. The "same" stores in each unrolled section have the same 45;; DIAssignID. Instcombine is going to sink the stores from if.then and if.else 46;; into if.end for each unrolled section. This involves merging the DIAssignID 47;; of the two stores. Check that each merge updates all linked instructions 48;; with the same DIAssignID attachments too. 49 50; CHECK: if.then: 51; CHECK: #dbg_assign(float %call2, ![[var:[0-9]+]], !DIExpression(), ![[id:[0-9]+]], ptr %p, !DIExpression(), 52; CHECK: br label %for.inc 53 54; CHECK: if.else: 55; CHECK: #dbg_assign(float %call5, ![[var]], !DIExpression(), ![[id]], ptr %p, !DIExpression(), 56; CHECK: br label %for.inc 57 58; CHECK: for.inc: 59; CHECK-NEXT: %storemerge = phi float [ %call2, %if.then ], [ %call5, %if.else ] 60; CHECK-NEXT: store float %storemerge, ptr %p, align 4{{.+}}!DIAssignID ![[id]] 61 62; CHECK: if.then.1: 63; CHECK: #dbg_assign(float %call2.1, ![[var]], !DIExpression(), ![[id]], ptr %p, !DIExpression(), 64; CHECK: br label %for.inc.1 65 66; CHECK: if.else.1: 67; CHECK: #dbg_assign(float %call5.1, ![[var]], !DIExpression(), ![[id]], ptr %p, !DIExpression(), 68; CHECK: br label %for.inc.1 69 70; CHECK: for.inc.1: 71; CHECK-NEXT: %storemerge1 = phi float [ %call2.1, %if.then.1 ], [ %call5.1, %if.else.1 ] 72; CHECK-NEXT: store float %storemerge1, ptr %p, align 4{{.+}}!DIAssignID ![[id]] 73 74; CHECK: if.then.2: 75; CHECK: #dbg_assign(float %call2.2, ![[var]], !DIExpression(), ![[id]], ptr %p, !DIExpression(), 76; CHECK: br label %for.inc.2 77 78; CHECK: if.else.2: 79; CHECK: #dbg_assign(float %call5.2, ![[var]], !DIExpression(), ![[id]], ptr %p, !DIExpression(), 80; CHECK: br label %for.inc.2 81 82; CHECK: for.inc.2: 83; CHECK-NEXT: %storemerge2 = phi float [ %call2.2, %if.then.2 ], [ %call5.2, %if.else.2 ] 84; CHECK-NEXT: store float %storemerge2, ptr %p, align 4{{.+}}!DIAssignID ![[id]] 85 86%class.j = type { %class.g, %class.e, %class.e, i8 } 87%class.g = type { i8 } 88%class.e = type { i8 } 89%class.a = type { float } 90%class.c = type { i8 } 91 92; Function Attrs: uwtable 93define dso_local void @_ZN1j1oEv(ptr %this) local_unnamed_addr #0 align 2 !dbg !7 { 94entry: 95 %p = alloca %class.a, align 4, !DIAssignID !49 96 call void @llvm.dbg.assign(metadata i1 undef, metadata !48, metadata !DIExpression(), metadata !49, metadata ptr %p, metadata !DIExpression()), !dbg !50 97 %0 = bitcast ptr %p to ptr, !dbg !51 98 call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %0) #4, !dbg !51 99 %n = getelementptr inbounds %class.j, ptr %this, i64 0, i32 3 100 %l = getelementptr inbounds %class.j, ptr %this, i64 0, i32 1 101 %ref.tmp.sroa.0.0..sroa_idx = getelementptr inbounds %class.a, ptr %p, i64 0, i32 0 102 %m = getelementptr inbounds %class.j, ptr %this, i64 0, i32 2 103 %1 = load i8, ptr %n, align 1, !dbg !52 104 %tobool.not = icmp eq i8 %1, 0, !dbg !52 105 br i1 %tobool.not, label %if.else, label %if.then, !dbg !64 106 107if.then: ; preds = %entry 108 %call = tail call nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr nonnull %l), !dbg !65 109 %call2 = tail call float @_ZN1c1dEv(ptr nonnull %call), !dbg !66 110 store float %call2, ptr %ref.tmp.sroa.0.0..sroa_idx, align 4, !dbg !67, !DIAssignID !71 111 call void @llvm.dbg.assign(metadata float %call2, metadata !48, metadata !DIExpression(), metadata !71, metadata ptr %ref.tmp.sroa.0.0..sroa_idx, metadata !DIExpression()), !dbg !50 112 br label %for.inc, !dbg !72 113 114if.else: ; preds = %entry 115 %call4 = tail call nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr nonnull %m), !dbg !73 116 %call5 = tail call float @_ZN1c1dEv(ptr nonnull %call4), !dbg !74 117 store float %call5, ptr %ref.tmp.sroa.0.0..sroa_idx, align 4, !dbg !75, !DIAssignID !76 118 call void @llvm.dbg.assign(metadata float %call5, metadata !48, metadata !DIExpression(), metadata !76, metadata ptr %ref.tmp.sroa.0.0..sroa_idx, metadata !DIExpression()), !dbg !50 119 br label %for.inc 120 121for.inc: ; preds = %if.then, %if.else 122 %2 = load i8, ptr %n, align 1, !dbg !52 123 %tobool.not.1 = icmp eq i8 %2, 0, !dbg !52 124 br i1 %tobool.not.1, label %if.else.1, label %if.then.1, !dbg !64 125 126if.then.1: ; preds = %for.inc 127 %call.1 = tail call nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr nonnull %l), !dbg !65 128 %call2.1 = tail call float @_ZN1c1dEv(ptr nonnull %call.1), !dbg !66 129 store float %call2.1, ptr %ref.tmp.sroa.0.0..sroa_idx, align 4, !dbg !67, !DIAssignID !71 130 call void @llvm.dbg.assign(metadata float %call2.1, metadata !48, metadata !DIExpression(), metadata !71, metadata ptr %ref.tmp.sroa.0.0..sroa_idx, metadata !DIExpression()), !dbg !50 131 br label %for.inc.1, !dbg !72 132 133if.else.1: ; preds = %for.inc 134 %call4.1 = tail call nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr nonnull %m), !dbg !73 135 %call5.1 = tail call float @_ZN1c1dEv(ptr nonnull %call4.1), !dbg !74 136 store float %call5.1, ptr %ref.tmp.sroa.0.0..sroa_idx, align 4, !dbg !75, !DIAssignID !76 137 call void @llvm.dbg.assign(metadata float %call5.1, metadata !48, metadata !DIExpression(), metadata !76, metadata ptr %ref.tmp.sroa.0.0..sroa_idx, metadata !DIExpression()), !dbg !50 138 br label %for.inc.1 139 140for.inc.1: ; preds = %if.else.1, %if.then.1 141 %3 = load i8, ptr %n, align 1, !dbg !52 142 %tobool.not.2 = icmp eq i8 %3, 0, !dbg !52 143 br i1 %tobool.not.2, label %if.else.2, label %if.then.2, !dbg !64 144 145if.then.2: ; preds = %for.inc.1 146 %call.2 = tail call nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr nonnull %l), !dbg !65 147 %call2.2 = tail call float @_ZN1c1dEv(ptr nonnull %call.2), !dbg !66 148 store float %call2.2, ptr %ref.tmp.sroa.0.0..sroa_idx, align 4, !dbg !67, !DIAssignID !71 149 call void @llvm.dbg.assign(metadata float %call2.2, metadata !48, metadata !DIExpression(), metadata !71, metadata ptr %ref.tmp.sroa.0.0..sroa_idx, metadata !DIExpression()), !dbg !50 150 br label %for.inc.2, !dbg !72 151 152if.else.2: ; preds = %for.inc.1 153 %call4.2 = tail call nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr nonnull %m), !dbg !73 154 %call5.2 = tail call float @_ZN1c1dEv(ptr nonnull %call4.2), !dbg !74 155 store float %call5.2, ptr %ref.tmp.sroa.0.0..sroa_idx, align 4, !dbg !75, !DIAssignID !76 156 call void @llvm.dbg.assign(metadata float %call5.2, metadata !48, metadata !DIExpression(), metadata !76, metadata ptr %ref.tmp.sroa.0.0..sroa_idx, metadata !DIExpression()), !dbg !50 157 br label %for.inc.2 158 159for.inc.2: ; preds = %if.else.2, %if.then.2 160 %k = getelementptr inbounds %class.j, ptr %this, i64 0, i32 0, !dbg !77 161 call void @_ZN1g1hER1a(ptr %k, ptr nonnull align 4 dereferenceable(4) %p), !dbg !78 162 call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %0) #4, !dbg !79 163 ret void, !dbg !79 164} 165 166; Function Attrs: argmemonly nofree nosync nounwind willreturn 167declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1 168 169declare dso_local nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr) local_unnamed_addr #2 170 171declare dso_local float @_ZN1c1dEv(ptr) local_unnamed_addr #2 172 173; Function Attrs: argmemonly nofree nosync nounwind willreturn 174declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1 175 176declare dso_local void @_ZN1g1hER1a(ptr, ptr nonnull align 4 dereferenceable(4)) local_unnamed_addr #2 177 178; Function Attrs: nofree nosync nounwind readnone speculatable willreturn 179declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #3 180 181!llvm.dbg.cu = !{!0} 182!llvm.module.flags = !{!3, !4, !5, !1000} 183!llvm.ident = !{!6} 184 185!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) 186!1 = !DIFile(filename: "test.cpp", directory: "/") 187!2 = !{} 188!3 = !{i32 7, !"Dwarf Version", i32 4} 189!4 = !{i32 2, !"Debug Info Version", i32 3} 190!5 = !{i32 1, !"wchar_size", i32 4} 191!6 = !{!"clang version 12.0.0"} 192!7 = distinct !DISubprogram(name: "o", linkageName: "_ZN1j1oEv", scope: !8, file: !1, line: 23, type: !40, scopeLine: 23, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !39, retainedNodes: !43) 193!8 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "j", file: !1, line: 16, size: 32, flags: DIFlagTypePassByValue, elements: !9, identifier: "_ZTS1j") 194!9 = !{!10, !22, !36, !37, !39} 195!10 = !DIDerivedType(tag: DW_TAG_member, name: "k", scope: !8, file: !1, line: 17, baseType: !11, size: 8) 196!11 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "g", file: !1, line: 12, size: 8, flags: DIFlagTypePassByValue, elements: !12, identifier: "_ZTS1g") 197!12 = !{!13} 198!13 = !DISubprogram(name: "h", linkageName: "_ZN1g1hER1a", scope: !11, file: !1, line: 14, type: !14, scopeLine: 14, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized) 199!14 = !DISubroutineType(types: !15) 200!15 = !{null, !16, !17} 201!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) 202!17 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !18, size: 64) 203!18 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "a", file: !1, line: 1, size: 32, flags: DIFlagTypePassByValue, elements: !19, identifier: "_ZTS1a") 204!19 = !{!20} 205!20 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !18, file: !1, line: 2, baseType: !21, size: 32) 206!21 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float) 207!22 = !DIDerivedType(tag: DW_TAG_member, name: "l", scope: !8, file: !1, line: 18, baseType: !23, size: 8, offset: 8) 208!23 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "e", file: !1, line: 8, size: 8, flags: DIFlagTypePassByValue, elements: !24, identifier: "_ZTS1e") 209!24 = !{!25} 210!25 = !DISubprogram(name: "f", linkageName: "_ZN1e1fEv", scope: !23, file: !1, line: 10, type: !26, scopeLine: 10, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized) 211!26 = !DISubroutineType(types: !27) 212!27 = !{!28, !35} 213!28 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !29, size: 64) 214!29 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "c", file: !1, line: 4, size: 8, flags: DIFlagTypePassByValue, elements: !30, identifier: "_ZTS1c") 215!30 = !{!31} 216!31 = !DISubprogram(name: "d", linkageName: "_ZN1c1dEv", scope: !29, file: !1, line: 6, type: !32, scopeLine: 6, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized) 217!32 = !DISubroutineType(types: !33) 218!33 = !{!18, !34} 219!34 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !29, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) 220!35 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !23, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) 221!36 = !DIDerivedType(tag: DW_TAG_member, name: "m", scope: !8, file: !1, line: 19, baseType: !23, size: 8, offset: 16) 222!37 = !DIDerivedType(tag: DW_TAG_member, name: "n", scope: !8, file: !1, line: 20, baseType: !38, size: 8, offset: 24) 223!38 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean) 224!39 = !DISubprogram(name: "o", linkageName: "_ZN1j1oEv", scope: !8, file: !1, line: 21, type: !40, scopeLine: 21, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized) 225!40 = !DISubroutineType(types: !41) 226!41 = !{null, !42} 227!42 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) 228!43 = !{!44, !46, !48} 229!44 = !DILocalVariable(name: "this", arg: 1, scope: !7, type: !45, flags: DIFlagArtificial | DIFlagObjectPointer) 230!45 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64) 231!46 = !DILocalVariable(name: "i", scope: !7, file: !1, line: 24, type: !47) 232!47 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 233!48 = !DILocalVariable(name: "p", scope: !7, file: !1, line: 25, type: !18) 234!49 = distinct !DIAssignID() 235!50 = !DILocation(line: 0, scope: !7) 236!51 = !DILocation(line: 25, column: 3, scope: !7) 237!52 = !DILocation(line: 28, column: 9, scope: !53) 238!53 = distinct !DILexicalBlock(scope: !54, file: !1, line: 28, column: 9) 239!54 = distinct !DILexicalBlock(scope: !55, file: !1, line: 27, column: 3) 240!55 = distinct !DILexicalBlock(scope: !7, file: !1, line: 27, column: 3) 241!64 = !DILocation(line: 28, column: 9, scope: !54) 242!65 = !DILocation(line: 29, column: 13, scope: !53) 243!66 = !DILocation(line: 29, column: 17, scope: !53) 244!67 = !DILocation(line: 29, column: 9, scope: !53) 245!71 = distinct !DIAssignID() 246!72 = !DILocation(line: 29, column: 7, scope: !53) 247!73 = !DILocation(line: 31, column: 13, scope: !53) 248!74 = !DILocation(line: 31, column: 17, scope: !53) 249!75 = !DILocation(line: 31, column: 9, scope: !53) 250!76 = distinct !DIAssignID() 251!77 = !DILocation(line: 32, column: 3, scope: !7) 252!78 = !DILocation(line: 32, column: 5, scope: !7) 253!79 = !DILocation(line: 33, column: 1, scope: !7) 254!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true} 255