246 lines · plain
1; RUN: opt -passes=sroa -S %s -o - | FileCheck %s2 3;; $ cat test.cpp4;; class a {5;; public:6;; float b[4];7;; void c();8;; };9;; class B {10;; public:11;; B(a d) : e(d) {}12;; a &f() { return e; }13;; B operator*(const B &)const;14;; int g;15;; a e;16;; };17;; B B::operator*(const B &)const { return e; }18;; class h {19;; public:20;; B i();21;; };22;; void j() {23;; h convexbody, k;24;; B l = k.i(), m = convexbody.i(), n = l * m;25;; a o = n.f(); // Looking at this store, o[0, 128] <- n[32, 160].26;; o.c();27;; }28;; Generated by grabbing IR before sroa in:29;; $ clang++ -O2 -g -c test.cpp -Xclang -fexperimental-assignment-tracking30 31;; Check that the store 4xfloat split into 2x store 2xfloat has correct debug32;; info when the source (n, 160 bits of int+5*float) is split beforehand (see33;; comment in test.cpp above). Ensure that only the value-expression gets34;; fragment info; that the address-expression remains untouched.35 36;; Check nearby instructions to make sure we're looking in the right place.37; CHECK: define dso_local void @_Z1jv()38; CHECK: call void @_ZN1h1iEv(ptr nonnull sret(%class.B) align 4 %m,39 40; CHECK: store <2 x float> %agg.tmp.sroa.0.0.copyload.i, ptr %4, align 4,{{.+}}!DIAssignID ![[id1:[0-9]+]]41; CHECK: store <2 x float> %agg.tmp.sroa.2.0.copyload.i, ptr %n.sroa.2.4..sroa_idx, align 4,{{.+}}!DIAssignID ![[id2:[0-9]+]]42; CHECK-NEXT: #dbg_assign(<2 x float> %agg.tmp.sroa.0.0.copyload.i, ![[var:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 0, 64), ![[id1]], ptr %4, !DIExpression(),43; CHECK-NEXT: #dbg_assign(<2 x float> %agg.tmp.sroa.2.0.copyload.i, ![[var]], !DIExpression(DW_OP_LLVM_fragment, 64, 64), ![[id2]], ptr %n.sroa.2.4..sroa_idx, !DIExpression(),44 45; CHECK: ret46 47%class.B = type { i32, %class.a }48%class.a = type { [4 x float] }49%class.h = type { i8 }50 51$_ZN1BC2E1a = comdat any52 53$_ZN1B1fEv = comdat any54 55; Function Attrs: nofree norecurse nounwind uwtable56define dso_local void @_ZNK1BmlERKS_(ptr noalias nocapture sret(%class.B) align 4 %agg.result, ptr nocapture readonly %this, ptr nocapture nonnull readnone align 4 dereferenceable(20) %0) local_unnamed_addr #0 align 2 !dbg !7 {57entry:58 %agg.tmp.sroa.0.0..sroa_idx = getelementptr inbounds %class.B, ptr %this, i64 0, i32 1, !dbg !4259 %agg.tmp.sroa.0.0..sroa_cast = bitcast ptr %agg.tmp.sroa.0.0..sroa_idx to ptr, !dbg !4260 %agg.tmp.sroa.0.0.copyload = load <2 x float>, ptr %agg.tmp.sroa.0.0..sroa_cast, align 4, !dbg !4261 %agg.tmp.sroa.2.0..sroa_idx2 = getelementptr inbounds %class.B, ptr %this, i64 0, i32 1, i32 0, i64 2, !dbg !4262 %agg.tmp.sroa.2.0..sroa_cast = bitcast ptr %agg.tmp.sroa.2.0..sroa_idx2 to ptr, !dbg !4263 %agg.tmp.sroa.2.0.copyload = load <2 x float>, ptr %agg.tmp.sroa.2.0..sroa_cast, align 4, !dbg !4264 %d.sroa.0.0..sroa_idx.i = getelementptr inbounds %class.B, ptr %agg.result, i64 0, i32 1, !dbg !4765 %d.sroa.0.0..sroa_cast.i = bitcast ptr %d.sroa.0.0..sroa_idx.i to ptr, !dbg !4766 store <2 x float> %agg.tmp.sroa.0.0.copyload, ptr %d.sroa.0.0..sroa_cast.i, align 4, !dbg !4767 %d.sroa.2.0..sroa_idx2.i = getelementptr inbounds %class.B, ptr %agg.result, i64 0, i32 1, i32 0, i64 2, !dbg !4768 %d.sroa.2.0..sroa_cast.i = bitcast ptr %d.sroa.2.0..sroa_idx2.i to ptr, !dbg !4769 store <2 x float> %agg.tmp.sroa.2.0.copyload, ptr %d.sroa.2.0..sroa_cast.i, align 4, !dbg !4770 ret void, !dbg !5471}72 73; Function Attrs: argmemonly nofree nosync nounwind willreturn74declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #175 76; Function Attrs: nounwind uwtable77define linkonce_odr dso_local void @_ZN1BC2E1a(ptr %this, <2 x float> %d.coerce0, <2 x float> %d.coerce1) unnamed_addr #2 comdat align 2 !dbg !48 {78entry:79 %d.sroa.0.0..sroa_idx = getelementptr inbounds %class.B, ptr %this, i64 0, i32 1, !dbg !5580 %d.sroa.0.0..sroa_cast = bitcast ptr %d.sroa.0.0..sroa_idx to ptr, !dbg !5581 store <2 x float> %d.coerce0, ptr %d.sroa.0.0..sroa_cast, align 4, !dbg !5582 %d.sroa.2.0..sroa_idx2 = getelementptr inbounds %class.B, ptr %this, i64 0, i32 1, i32 0, i64 2, !dbg !5583 %d.sroa.2.0..sroa_cast = bitcast ptr %d.sroa.2.0..sroa_idx2 to ptr, !dbg !5584 store <2 x float> %d.coerce1, ptr %d.sroa.2.0..sroa_cast, align 4, !dbg !5585 ret void, !dbg !5686}87 88; Function Attrs: nofree nosync nounwind readnone speculatable willreturn89declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #390 91; Function Attrs: uwtable92define dso_local void @_Z1jv() local_unnamed_addr #4 !dbg !57 {93entry:94 %convexbody = alloca %class.h, align 1, !DIAssignID !7395 call void @llvm.dbg.assign(metadata i1 undef, metadata !61, metadata !DIExpression(), metadata !73, metadata ptr %convexbody, metadata !DIExpression()), !dbg !7496 %k = alloca %class.h, align 1, !DIAssignID !7597 call void @llvm.dbg.assign(metadata i1 undef, metadata !68, metadata !DIExpression(), metadata !75, metadata ptr %k, metadata !DIExpression()), !dbg !7498 %l = alloca %class.B, align 4, !DIAssignID !7699 call void @llvm.dbg.assign(metadata i1 undef, metadata !69, metadata !DIExpression(), metadata !76, metadata ptr %l, metadata !DIExpression()), !dbg !74100 %m = alloca %class.B, align 4, !DIAssignID !77101 call void @llvm.dbg.assign(metadata i1 undef, metadata !70, metadata !DIExpression(), metadata !77, metadata ptr %m, metadata !DIExpression()), !dbg !74102 %n = alloca %class.B, align 4, !DIAssignID !78103 call void @llvm.dbg.assign(metadata i1 undef, metadata !71, metadata !DIExpression(), metadata !78, metadata ptr %n, metadata !DIExpression()), !dbg !74104 %o = alloca %class.a, align 4, !DIAssignID !79105 call void @llvm.dbg.assign(metadata i1 undef, metadata !72, metadata !DIExpression(), metadata !79, metadata ptr %o, metadata !DIExpression()), !dbg !74106 %0 = getelementptr inbounds %class.h, ptr %convexbody, i64 0, i32 0, !dbg !80107 %1 = getelementptr inbounds %class.h, ptr %k, i64 0, i32 0, !dbg !80108 %2 = bitcast ptr %l to ptr, !dbg !81109 call void @_ZN1h1iEv(ptr nonnull sret(%class.B) align 4 %l, ptr nonnull %k), !dbg !82110 %3 = bitcast ptr %m to ptr, !dbg !81111 call void @_ZN1h1iEv(ptr nonnull sret(%class.B) align 4 %m, ptr nonnull %convexbody), !dbg !83112 %4 = bitcast ptr %n to ptr, !dbg !81113 %agg.tmp.sroa.0.0..sroa_idx.i = getelementptr inbounds %class.B, ptr %l, i64 0, i32 1, !dbg !84114 %agg.tmp.sroa.0.0..sroa_cast.i = bitcast ptr %agg.tmp.sroa.0.0..sroa_idx.i to ptr, !dbg !84115 %agg.tmp.sroa.0.0.copyload.i = load <2 x float>, ptr %agg.tmp.sroa.0.0..sroa_cast.i, align 4, !dbg !84116 %agg.tmp.sroa.2.0..sroa_idx2.i = getelementptr inbounds %class.B, ptr %l, i64 0, i32 1, i32 0, i64 2, !dbg !84117 %agg.tmp.sroa.2.0..sroa_cast.i = bitcast ptr %agg.tmp.sroa.2.0..sroa_idx2.i to ptr, !dbg !84118 %agg.tmp.sroa.2.0.copyload.i = load <2 x float>, ptr %agg.tmp.sroa.2.0..sroa_cast.i, align 4, !dbg !84119 %d.sroa.0.0..sroa_idx.i.i = getelementptr inbounds %class.B, ptr %n, i64 0, i32 1, !dbg !89120 %d.sroa.0.0..sroa_cast.i.i = bitcast ptr %d.sroa.0.0..sroa_idx.i.i to ptr, !dbg !89121 store <2 x float> %agg.tmp.sroa.0.0.copyload.i, ptr %d.sroa.0.0..sroa_cast.i.i, align 4, !dbg !89122 %d.sroa.2.0..sroa_idx2.i.i = getelementptr inbounds %class.B, ptr %n, i64 0, i32 1, i32 0, i64 2, !dbg !89123 %d.sroa.2.0..sroa_cast.i.i = bitcast ptr %d.sroa.2.0..sroa_idx2.i.i to ptr, !dbg !89124 store <2 x float> %agg.tmp.sroa.2.0.copyload.i, ptr %d.sroa.2.0..sroa_cast.i.i, align 4, !dbg !89125 %5 = bitcast ptr %o to ptr, !dbg !91126 %e.i = getelementptr inbounds %class.B, ptr %n, i64 0, i32 1, !dbg !92127 %6 = bitcast ptr %e.i to ptr, !dbg !97128 call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 dereferenceable(16) %5, ptr nonnull align 4 dereferenceable(16) %6, i64 16, i1 false), !dbg !97, !DIAssignID !98129 call void @llvm.dbg.assign(metadata i1 undef, metadata !72, metadata !DIExpression(), metadata !98, metadata ptr %5, metadata !DIExpression()), !dbg !74130 call void @_ZN1a1cEv(ptr nonnull %o), !dbg !99131 ret void, !dbg !100132}133 134declare dso_local void @_ZN1h1iEv(ptr sret(%class.B) align 4, ptr) local_unnamed_addr #5135 136; Function Attrs: nounwind uwtable137define linkonce_odr dso_local nonnull align 4 dereferenceable(16) ptr @_ZN1B1fEv(ptr %this) local_unnamed_addr #6 comdat align 2 !dbg !93 {138entry:139 %e = getelementptr inbounds %class.B, ptr %this, i64 0, i32 1, !dbg !101140 ret ptr %e, !dbg !102141}142 143declare dso_local void @_ZN1a1cEv(ptr) local_unnamed_addr #5144 145!llvm.dbg.cu = !{!0}146!llvm.module.flags = !{!3, !4, !5, !1000}147!llvm.ident = !{!6}148 149!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)150!1 = !DIFile(filename: "reduce.cpp", directory: "/")151!2 = !{}152!3 = !{i32 7, !"Dwarf Version", i32 4}153!4 = !{i32 2, !"Debug Info Version", i32 3}154!5 = !{i32 1, !"wchar_size", i32 4}155!6 = !{!"clang version 12.0.0"}156!7 = distinct !DISubprogram(name: "operator*", linkageName: "_ZNK1BmlERKS_", scope: !8, file: !1, line: 14, type: !33, scopeLine: 14, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !32, retainedNodes: !38)157!8 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "B", file: !1, line: 6, size: 160, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !9, identifier: "_ZTS1B")158!9 = !{!10, !12, !24, !28, !32}159!10 = !DIDerivedType(tag: DW_TAG_member, name: "g", scope: !8, file: !1, line: 11, baseType: !11, size: 32, flags: DIFlagPublic)160!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)161!12 = !DIDerivedType(tag: DW_TAG_member, name: "e", scope: !8, file: !1, line: 12, baseType: !13, size: 128, offset: 32, flags: DIFlagPublic)162!13 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "a", file: !1, line: 1, size: 128, flags: DIFlagTypePassByValue, elements: !14, identifier: "_ZTS1a")163!14 = !{!15, !20}164!15 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !13, file: !1, line: 3, baseType: !16, size: 128, flags: DIFlagPublic)165!16 = !DICompositeType(tag: DW_TAG_array_type, baseType: !17, size: 128, elements: !18)166!17 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)167!18 = !{!19}168!19 = !DISubrange(count: 4)169!20 = !DISubprogram(name: "c", linkageName: "_ZN1a1cEv", scope: !13, file: !1, line: 4, type: !21, scopeLine: 4, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)170!21 = !DISubroutineType(types: !22)171!22 = !{null, !23}172!23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)173!24 = !DISubprogram(name: "B", scope: !8, file: !1, line: 8, type: !25, scopeLine: 8, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)174!25 = !DISubroutineType(types: !26)175!26 = !{null, !27, !13}176!27 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)177!28 = !DISubprogram(name: "f", linkageName: "_ZN1B1fEv", scope: !8, file: !1, line: 9, type: !29, scopeLine: 9, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)178!29 = !DISubroutineType(types: !30)179!30 = !{!31, !27}180!31 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !13, size: 64)181!32 = !DISubprogram(name: "operator*", linkageName: "_ZNK1BmlERKS_", scope: !8, file: !1, line: 10, type: !33, scopeLine: 10, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)182!33 = !DISubroutineType(types: !34)183!34 = !{!8, !35, !37}184!35 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !36, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)185!36 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !8)186!37 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !36, size: 64)187!38 = !{!39, !41}188!39 = !DILocalVariable(name: "this", arg: 1, scope: !7, type: !40, flags: DIFlagArtificial | DIFlagObjectPointer)189!40 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !36, size: 64)190!41 = !DILocalVariable(arg: 2, scope: !7, file: !1, line: 14, type: !37)191!42 = !DILocation(line: 14, column: 41, scope: !7)192!47 = !DILocation(line: 8, column: 12, scope: !48, inlinedAt: !53)193!48 = distinct !DISubprogram(name: "B", linkageName: "_ZN1BC2E1a", scope: !8, file: !1, line: 8, type: !25, scopeLine: 8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !24, retainedNodes: !49)194!49 = !{!50, !52}195!50 = !DILocalVariable(name: "this", arg: 1, scope: !48, type: !51, flags: DIFlagArtificial | DIFlagObjectPointer)196!51 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)197!52 = !DILocalVariable(name: "d", arg: 2, scope: !48, file: !1, line: 8, type: !13)198!53 = distinct !DILocation(line: 14, column: 41, scope: !7)199!54 = !DILocation(line: 14, column: 34, scope: !7)200!55 = !DILocation(line: 8, column: 12, scope: !48)201!56 = !DILocation(line: 8, column: 18, scope: !48)202!57 = distinct !DISubprogram(name: "j", linkageName: "_Z1jv", scope: !1, file: !1, line: 19, type: !58, scopeLine: 19, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !60)203!58 = !DISubroutineType(types: !59)204!59 = !{null}205!60 = !{!61, !68, !69, !70, !71, !72}206!61 = !DILocalVariable(name: "convexbody", scope: !57, file: !1, line: 20, type: !62)207!62 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "h", file: !1, line: 15, size: 8, flags: DIFlagTypePassByValue, elements: !63, identifier: "_ZTS1h")208!63 = !{!64}209!64 = !DISubprogram(name: "i", linkageName: "_ZN1h1iEv", scope: !62, file: !1, line: 17, type: !65, scopeLine: 17, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)210!65 = !DISubroutineType(types: !66)211!66 = !{!8, !67}212!67 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !62, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)213!68 = !DILocalVariable(name: "k", scope: !57, file: !1, line: 20, type: !62)214!69 = !DILocalVariable(name: "l", scope: !57, file: !1, line: 21, type: !8)215!70 = !DILocalVariable(name: "m", scope: !57, file: !1, line: 21, type: !8)216!71 = !DILocalVariable(name: "n", scope: !57, file: !1, line: 21, type: !8)217!72 = !DILocalVariable(name: "o", scope: !57, file: !1, line: 22, type: !13)218!73 = distinct !DIAssignID()219!74 = !DILocation(line: 0, scope: !57)220!75 = distinct !DIAssignID()221!76 = distinct !DIAssignID()222!77 = distinct !DIAssignID()223!78 = distinct !DIAssignID()224!79 = distinct !DIAssignID()225!80 = !DILocation(line: 20, column: 3, scope: !57)226!81 = !DILocation(line: 21, column: 3, scope: !57)227!82 = !DILocation(line: 21, column: 11, scope: !57)228!83 = !DILocation(line: 21, column: 31, scope: !57)229!84 = !DILocation(line: 14, column: 41, scope: !7, inlinedAt: !85)230!85 = distinct !DILocation(line: 21, column: 42, scope: !57)231!89 = !DILocation(line: 8, column: 12, scope: !48, inlinedAt: !90)232!90 = distinct !DILocation(line: 14, column: 41, scope: !7, inlinedAt: !85)233!91 = !DILocation(line: 22, column: 3, scope: !57)234!92 = !DILocation(line: 9, column: 19, scope: !93, inlinedAt: !96)235!93 = distinct !DISubprogram(name: "f", linkageName: "_ZN1B1fEv", scope: !8, file: !1, line: 9, type: !29, scopeLine: 9, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !28, retainedNodes: !94)236!94 = !{!95}237!95 = !DILocalVariable(name: "this", arg: 1, scope: !93, type: !51, flags: DIFlagArtificial | DIFlagObjectPointer)238!96 = distinct !DILocation(line: 22, column: 11, scope: !57)239!97 = !DILocation(line: 22, column: 9, scope: !57)240!98 = distinct !DIAssignID()241!99 = !DILocation(line: 23, column: 5, scope: !57)242!100 = !DILocation(line: 24, column: 1, scope: !57)243!101 = !DILocation(line: 9, column: 19, scope: !93)244!102 = !DILocation(line: 9, column: 12, scope: !93)245!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}246