254 lines · plain
1; RUN: opt %s -S -passes=instcombine -o - | FileCheck %s2 3;; $ cat test.cpp4;; class a {5;; float b;6;; };7;; class c {8;; public:9;; a d();10;; };11;; class e {12;; public:13;; c &f();14;; };15;; class g {16;; public:17;; void h(a &);18;; };19;; class j {20;; g k;21;; e l;22;; e m;23;; bool n;24;; void o();25;; };26;; void j::o() {27;; int i;28;; a p;29;; i = 0;30;; for (; i < 3; i++)31;; if (n)32;; p = l.f().d();33;; else34;; p = m.f().d();35;; k.h(p);36;; }37;;38;; Generated by grabbing IR before instcombine in:39;; $ clang++ -O2 -g -c test.cpp -Xclang -fexperimental-assignment-tracking40 41;; Before instcombine runs we have an unrolled loop (3 iterations). Each42;; unrolled section is an if-diamond with a store in if.then and if.else43;; block. The "same" stores in each unrolled section have the same44;; DIAssignID. Instcombine is going to sink the stores from if.then and if.else45;; into if.end for each unrolled section. This involves merging the DIAssignID46;; of the two stores. Check that each merge updates all linked instructions47;; with the same DIAssignID attachments too.48 49; CHECK: if.then:50; CHECK: #dbg_assign(float %call2, ![[var:[0-9]+]], !DIExpression(), ![[id:[0-9]+]], ptr %p, !DIExpression(),51; CHECK: br label %for.inc52 53; CHECK: if.else:54; CHECK: #dbg_assign(float %call5, ![[var]], !DIExpression(), ![[id]], ptr %p, !DIExpression(),55; CHECK: br label %for.inc56 57; CHECK: for.inc:58; CHECK-NEXT: %storemerge = phi float [ %call2, %if.then ], [ %call5, %if.else ]59; CHECK-NEXT: store float %storemerge, ptr %p, align 4{{.+}}!DIAssignID ![[id]]60 61; CHECK: if.then.1:62; CHECK: #dbg_assign(float %call2.1, ![[var]], !DIExpression(), ![[id]], ptr %p, !DIExpression(),63; CHECK: br label %for.inc.164 65; CHECK: if.else.1:66; CHECK: #dbg_assign(float %call5.1, ![[var]], !DIExpression(), ![[id]], ptr %p, !DIExpression(),67; CHECK: br label %for.inc.168 69; CHECK: for.inc.1:70; CHECK-NEXT: %storemerge1 = phi float [ %call2.1, %if.then.1 ], [ %call5.1, %if.else.1 ]71; CHECK-NEXT: store float %storemerge1, ptr %p, align 4{{.+}}!DIAssignID ![[id]]72 73; CHECK: if.then.2:74; CHECK: #dbg_assign(float %call2.2, ![[var]], !DIExpression(), ![[id]], ptr %p, !DIExpression(),75; CHECK: br label %for.inc.276 77; CHECK: if.else.2:78; CHECK: #dbg_assign(float %call5.2, ![[var]], !DIExpression(), ![[id]], ptr %p, !DIExpression(),79; CHECK: br label %for.inc.280 81; CHECK: for.inc.2:82; CHECK-NEXT: %storemerge2 = phi float [ %call2.2, %if.then.2 ], [ %call5.2, %if.else.2 ]83; CHECK-NEXT: store float %storemerge2, ptr %p, align 4{{.+}}!DIAssignID ![[id]]84 85%class.j = type { %class.g, %class.e, %class.e, i8 }86%class.g = type { i8 }87%class.e = type { i8 }88%class.a = type { float }89%class.c = type { i8 }90 91; Function Attrs: uwtable92define dso_local void @_ZN1j1oEv(ptr %this) local_unnamed_addr #0 align 2 !dbg !7 {93entry:94 %p = alloca %class.a, align 4, !DIAssignID !4995 call void @llvm.dbg.assign(metadata i1 undef, metadata !48, metadata !DIExpression(), metadata !49, metadata ptr %p, metadata !DIExpression()), !dbg !5096 %0 = bitcast ptr %p to ptr, !dbg !5197 call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %0) #4, !dbg !5198 %n = getelementptr inbounds %class.j, ptr %this, i64 0, i32 399 %l = getelementptr inbounds %class.j, ptr %this, i64 0, i32 1100 %ref.tmp.sroa.0.0..sroa_idx = getelementptr inbounds %class.a, ptr %p, i64 0, i32 0101 %m = getelementptr inbounds %class.j, ptr %this, i64 0, i32 2102 %1 = load i8, ptr %n, align 1, !dbg !52103 %tobool.not = icmp eq i8 %1, 0, !dbg !52104 br i1 %tobool.not, label %if.else, label %if.then, !dbg !64105 106if.then: ; preds = %entry107 %call = tail call nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr nonnull %l), !dbg !65108 %call2 = tail call float @_ZN1c1dEv(ptr nonnull %call), !dbg !66109 store float %call2, ptr %ref.tmp.sroa.0.0..sroa_idx, align 4, !dbg !67, !DIAssignID !71110 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 !50111 br label %for.inc, !dbg !72112 113if.else: ; preds = %entry114 %call4 = tail call nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr nonnull %m), !dbg !73115 %call5 = tail call float @_ZN1c1dEv(ptr nonnull %call4), !dbg !74116 store float %call5, ptr %ref.tmp.sroa.0.0..sroa_idx, align 4, !dbg !75, !DIAssignID !76117 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 !50118 br label %for.inc119 120for.inc: ; preds = %if.then, %if.else121 %2 = load i8, ptr %n, align 1, !dbg !52122 %tobool.not.1 = icmp eq i8 %2, 0, !dbg !52123 br i1 %tobool.not.1, label %if.else.1, label %if.then.1, !dbg !64124 125if.then.1: ; preds = %for.inc126 %call.1 = tail call nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr nonnull %l), !dbg !65127 %call2.1 = tail call float @_ZN1c1dEv(ptr nonnull %call.1), !dbg !66128 store float %call2.1, ptr %ref.tmp.sroa.0.0..sroa_idx, align 4, !dbg !67, !DIAssignID !71129 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 !50130 br label %for.inc.1, !dbg !72131 132if.else.1: ; preds = %for.inc133 %call4.1 = tail call nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr nonnull %m), !dbg !73134 %call5.1 = tail call float @_ZN1c1dEv(ptr nonnull %call4.1), !dbg !74135 store float %call5.1, ptr %ref.tmp.sroa.0.0..sroa_idx, align 4, !dbg !75, !DIAssignID !76136 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 !50137 br label %for.inc.1138 139for.inc.1: ; preds = %if.else.1, %if.then.1140 %3 = load i8, ptr %n, align 1, !dbg !52141 %tobool.not.2 = icmp eq i8 %3, 0, !dbg !52142 br i1 %tobool.not.2, label %if.else.2, label %if.then.2, !dbg !64143 144if.then.2: ; preds = %for.inc.1145 %call.2 = tail call nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr nonnull %l), !dbg !65146 %call2.2 = tail call float @_ZN1c1dEv(ptr nonnull %call.2), !dbg !66147 store float %call2.2, ptr %ref.tmp.sroa.0.0..sroa_idx, align 4, !dbg !67, !DIAssignID !71148 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 !50149 br label %for.inc.2, !dbg !72150 151if.else.2: ; preds = %for.inc.1152 %call4.2 = tail call nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr nonnull %m), !dbg !73153 %call5.2 = tail call float @_ZN1c1dEv(ptr nonnull %call4.2), !dbg !74154 store float %call5.2, ptr %ref.tmp.sroa.0.0..sroa_idx, align 4, !dbg !75, !DIAssignID !76155 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 !50156 br label %for.inc.2157 158for.inc.2: ; preds = %if.else.2, %if.then.2159 %k = getelementptr inbounds %class.j, ptr %this, i64 0, i32 0, !dbg !77160 call void @_ZN1g1hER1a(ptr %k, ptr nonnull align 4 dereferenceable(4) %p), !dbg !78161 call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %0) #4, !dbg !79162 ret void, !dbg !79163}164 165; Function Attrs: argmemonly nofree nosync nounwind willreturn166declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1167 168declare dso_local nonnull align 1 dereferenceable(1) ptr @_ZN1e1fEv(ptr) local_unnamed_addr #2169 170declare dso_local float @_ZN1c1dEv(ptr) local_unnamed_addr #2171 172; Function Attrs: argmemonly nofree nosync nounwind willreturn173declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1174 175declare dso_local void @_ZN1g1hER1a(ptr, ptr nonnull align 4 dereferenceable(4)) local_unnamed_addr #2176 177; Function Attrs: nofree nosync nounwind readnone speculatable willreturn178declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #3179 180!llvm.dbg.cu = !{!0}181!llvm.module.flags = !{!3, !4, !5, !1000}182!llvm.ident = !{!6}183 184!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)185!1 = !DIFile(filename: "test.cpp", directory: "/")186!2 = !{}187!3 = !{i32 7, !"Dwarf Version", i32 4}188!4 = !{i32 2, !"Debug Info Version", i32 3}189!5 = !{i32 1, !"wchar_size", i32 4}190!6 = !{!"clang version 12.0.0"}191!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)192!8 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "j", file: !1, line: 16, size: 32, flags: DIFlagTypePassByValue, elements: !9, identifier: "_ZTS1j")193!9 = !{!10, !22, !36, !37, !39}194!10 = !DIDerivedType(tag: DW_TAG_member, name: "k", scope: !8, file: !1, line: 17, baseType: !11, size: 8)195!11 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "g", file: !1, line: 12, size: 8, flags: DIFlagTypePassByValue, elements: !12, identifier: "_ZTS1g")196!12 = !{!13}197!13 = !DISubprogram(name: "h", linkageName: "_ZN1g1hER1a", scope: !11, file: !1, line: 14, type: !14, scopeLine: 14, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)198!14 = !DISubroutineType(types: !15)199!15 = !{null, !16, !17}200!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)201!17 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !18, size: 64)202!18 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "a", file: !1, line: 1, size: 32, flags: DIFlagTypePassByValue, elements: !19, identifier: "_ZTS1a")203!19 = !{!20}204!20 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !18, file: !1, line: 2, baseType: !21, size: 32)205!21 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)206!22 = !DIDerivedType(tag: DW_TAG_member, name: "l", scope: !8, file: !1, line: 18, baseType: !23, size: 8, offset: 8)207!23 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "e", file: !1, line: 8, size: 8, flags: DIFlagTypePassByValue, elements: !24, identifier: "_ZTS1e")208!24 = !{!25}209!25 = !DISubprogram(name: "f", linkageName: "_ZN1e1fEv", scope: !23, file: !1, line: 10, type: !26, scopeLine: 10, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)210!26 = !DISubroutineType(types: !27)211!27 = !{!28, !35}212!28 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !29, size: 64)213!29 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "c", file: !1, line: 4, size: 8, flags: DIFlagTypePassByValue, elements: !30, identifier: "_ZTS1c")214!30 = !{!31}215!31 = !DISubprogram(name: "d", linkageName: "_ZN1c1dEv", scope: !29, file: !1, line: 6, type: !32, scopeLine: 6, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)216!32 = !DISubroutineType(types: !33)217!33 = !{!18, !34}218!34 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !29, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)219!35 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !23, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)220!36 = !DIDerivedType(tag: DW_TAG_member, name: "m", scope: !8, file: !1, line: 19, baseType: !23, size: 8, offset: 16)221!37 = !DIDerivedType(tag: DW_TAG_member, name: "n", scope: !8, file: !1, line: 20, baseType: !38, size: 8, offset: 24)222!38 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)223!39 = !DISubprogram(name: "o", linkageName: "_ZN1j1oEv", scope: !8, file: !1, line: 21, type: !40, scopeLine: 21, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)224!40 = !DISubroutineType(types: !41)225!41 = !{null, !42}226!42 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)227!43 = !{!44, !46, !48}228!44 = !DILocalVariable(name: "this", arg: 1, scope: !7, type: !45, flags: DIFlagArtificial | DIFlagObjectPointer)229!45 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)230!46 = !DILocalVariable(name: "i", scope: !7, file: !1, line: 24, type: !47)231!47 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)232!48 = !DILocalVariable(name: "p", scope: !7, file: !1, line: 25, type: !18)233!49 = distinct !DIAssignID()234!50 = !DILocation(line: 0, scope: !7)235!51 = !DILocation(line: 25, column: 3, scope: !7)236!52 = !DILocation(line: 28, column: 9, scope: !53)237!53 = distinct !DILexicalBlock(scope: !54, file: !1, line: 28, column: 9)238!54 = distinct !DILexicalBlock(scope: !55, file: !1, line: 27, column: 3)239!55 = distinct !DILexicalBlock(scope: !7, file: !1, line: 27, column: 3)240!64 = !DILocation(line: 28, column: 9, scope: !54)241!65 = !DILocation(line: 29, column: 13, scope: !53)242!66 = !DILocation(line: 29, column: 17, scope: !53)243!67 = !DILocation(line: 29, column: 9, scope: !53)244!71 = distinct !DIAssignID()245!72 = !DILocation(line: 29, column: 7, scope: !53)246!73 = !DILocation(line: 31, column: 13, scope: !53)247!74 = !DILocation(line: 31, column: 17, scope: !53)248!75 = !DILocation(line: 31, column: 9, scope: !53)249!76 = distinct !DIAssignID()250!77 = !DILocation(line: 32, column: 3, scope: !7)251!78 = !DILocation(line: 32, column: 5, scope: !7)252!79 = !DILocation(line: 33, column: 1, scope: !7)253!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}254