228 lines · plain
1; RUN: opt -passes=sroa -S %s -o - \2; RUN: | FileCheck %s --implicit-check-not="#dbg_"3 4;; Check that the fragments generated in SROA for a split alloca that has a5;; dbg.assign with non-zero-offset fragment are correct.6 7;; $ cat test.cpp8;; #include <cstring>9;;10;; struct V3i { long x, y, z; };11;; void fun() {12;; V3i point = {0, 0, 0};13;; point.z = 5000;14;; V3i other = {10, 9, 8};15;; std::memcpy(&point.y, &other.x, sizeof(long) * 2);16;; }17;; $ clang++ -c -O2 -g test.cpp -o - -Xclang -disable-llvm-passes -S -emit-llvm \18;; | opt -passes=declare-to-assign -S -o -19 20; CHECK: entry:21;; Allocas have been promoted - the linked dbg.assigns have been removed.22 23;; | V3i point = {0, 0, 0};24; CHECK-NEXT: #dbg_value(i64 0, ![[point:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 0, 64),25; CHECK-NEXT: #dbg_value(i64 0, ![[point]], !DIExpression(DW_OP_LLVM_fragment, 64, 64),26 27;; point.z = 5000;28; CHECK-NEXT: #dbg_value(i64 5000, ![[point]], !DIExpression(DW_OP_LLVM_fragment, 128, 64),29 30;; | V3i other = {10, 9, 8};31;; other is global const:32;; local.other.x = global.other.x33;; local.other.y = global.other.y34;; local.other.z = global.other.z35; CHECK-NEXT: %other.sroa.0.0.copyload = load i64, ptr @__const._Z3funv.other36; CHECK-NEXT: %other.sroa.2.0.copyload = load i64, ptr getelementptr inbounds (i8, ptr @__const._Z3funv.other, i64 8)37; CHECK-NEXT: %other.sroa.3.0.copyload = load i64, ptr getelementptr inbounds (i8, ptr @__const._Z3funv.other, i64 16)38; CHECK-NEXT: #dbg_value(i64 %other.sroa.0.0.copyload, ![[other:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 0, 64),39; CHECK-NEXT: #dbg_value(i64 %other.sroa.2.0.copyload, ![[other]], !DIExpression(DW_OP_LLVM_fragment, 64, 64),40; CHECK-NEXT: #dbg_value(i64 %other.sroa.3.0.copyload, ![[other]], !DIExpression(DW_OP_LLVM_fragment, 128, 64),41 42;; | std::memcpy(&point.y, &other.x, sizeof(long) * 2);43;; other is now 3 scalars:44;; point.y = other.x45; CHECK-NEXT: #dbg_value(i64 %other.sroa.0.0.copyload, ![[point]], !DIExpression(DW_OP_LLVM_fragment, 64, 64),46;;47;; point.z = other.y48; CHECK-NEXT: #dbg_value(i64 %other.sroa.2.0.copyload, ![[point]], !DIExpression(DW_OP_LLVM_fragment, 128, 64),49 50; CHECK: ![[point]] = !DILocalVariable(name: "point",51; CHECK: ![[other]] = !DILocalVariable(name: "other",52 53source_filename = "test.cpp"54target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"55target triple = "x86_64-unknown-linux-gnu"56 57%struct.V3i = type { i64, i64, i64 }58 59@__const._Z3funv.other = private unnamed_addr constant %struct.V3i { i64 10, i64 9, i64 8 }, align 860 61; Function Attrs: nounwind uwtable mustprogress62define dso_local void @_Z3funv() !dbg !100 {63entry:64 %point = alloca %struct.V3i, align 8, !DIAssignID !11265 call void @llvm.dbg.assign(metadata i1 undef, metadata !104, metadata !DIExpression(), metadata !112, metadata ptr %point, metadata !DIExpression()), !dbg !11366 %other = alloca %struct.V3i, align 8, !DIAssignID !11467 call void @llvm.dbg.assign(metadata i1 undef, metadata !111, metadata !DIExpression(), metadata !114, metadata ptr %other, metadata !DIExpression()), !dbg !11368 %0 = bitcast ptr %point to ptr, !dbg !11569 %1 = bitcast ptr %point to ptr, !dbg !11670 call void @llvm.memset.p0.i64(ptr align 8 %1, i8 0, i64 24, i1 false), !dbg !116, !DIAssignID !11771 call void @llvm.dbg.assign(metadata i8 0, metadata !104, metadata !DIExpression(), metadata !117, metadata ptr %1, metadata !DIExpression()), !dbg !11672 %z = getelementptr inbounds %struct.V3i, ptr %point, i32 0, i32 2, !dbg !11873 store i64 5000, ptr %z, align 8, !dbg !119, !DIAssignID !12574 call void @llvm.dbg.assign(metadata i64 5000, metadata !104, metadata !DIExpression(DW_OP_LLVM_fragment, 128, 64), metadata !125, metadata ptr %z, metadata !DIExpression()), !dbg !11975 %2 = bitcast ptr %other to ptr, !dbg !12676 %3 = bitcast ptr %other to ptr, !dbg !12777 call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 @__const._Z3funv.other, i64 24, i1 false), !dbg !127, !DIAssignID !12878 call void @llvm.dbg.assign(metadata i1 undef, metadata !111, metadata !DIExpression(), metadata !128, metadata ptr %3, metadata !DIExpression()), !dbg !12779 %y = getelementptr inbounds %struct.V3i, ptr %point, i32 0, i32 1, !dbg !12980 %4 = bitcast ptr %y to ptr, !dbg !13081 %x = getelementptr inbounds %struct.V3i, ptr %other, i32 0, i32 0, !dbg !13182 %5 = bitcast ptr %x to ptr, !dbg !13083 call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %5, i64 16, i1 false), !dbg !130, !DIAssignID !13284 call void @llvm.dbg.assign(metadata i1 undef, metadata !104, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 128), metadata !132, metadata ptr %4, metadata !DIExpression()), !dbg !13085 %6 = bitcast ptr %other to ptr, !dbg !13386 %7 = bitcast ptr %point to ptr, !dbg !13387 ret void, !dbg !13388}89 90declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)91declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg)92declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)93 94!llvm.dbg.cu = !{!0}95!llvm.module.flags = !{!96, !97, !98, !1000}96!llvm.ident = !{!99}97 98!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, imports: !3, splitDebugInlining: false, nameTableKind: None)99!1 = !DIFile(filename: "test.cpp", directory: "/")100!2 = !{}101!3 = !{!4, !18, !22, !28, !32, !36, !46, !50, !52, !54, !58, !62, !66, !70, !74, !76, !78, !80, !84, !88, !92, !94}102!4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !6, file: !17, line: 75)103!5 = !DINamespace(name: "std", scope: null)104!6 = !DISubprogram(name: "memchr", scope: !7, file: !7, line: 90, type: !8, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)105!7 = !DIFile(filename: "/usr/include/string.h", directory: "")106!8 = !DISubroutineType(types: !9)107!9 = !{!10, !11, !13, !14}108!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)109!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)110!12 = !DIDerivedType(tag: DW_TAG_const_type, baseType: null)111!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)112!14 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !15, line: 46, baseType: !16)113!15 = !DIFile(filename: "lib/clang/12.0.0/include/stddef.h", directory: "/")114!16 = !DIBasicType(name: "long unsigned int", size: 64, encoding: DW_ATE_unsigned)115!17 = !DIFile(filename: "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/cstring", directory: "")116!18 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !19, file: !17, line: 76)117!19 = !DISubprogram(name: "memcmp", scope: !7, file: !7, line: 63, type: !20, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)118!20 = !DISubroutineType(types: !21)119!21 = !{!13, !11, !11, !14}120!22 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !23, file: !17, line: 77)121!23 = !DISubprogram(name: "memcpy", scope: !7, file: !7, line: 42, type: !24, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)122!24 = !DISubroutineType(types: !25)123!25 = !{!10, !26, !27, !14}124!26 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !10)125!27 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !11)126!28 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !29, file: !17, line: 78)127!29 = !DISubprogram(name: "memmove", scope: !7, file: !7, line: 46, type: !30, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)128!30 = !DISubroutineType(types: !31)129!31 = !{!10, !10, !11, !14}130!32 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !33, file: !17, line: 79)131!33 = !DISubprogram(name: "memset", scope: !7, file: !7, line: 60, type: !34, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)132!34 = !DISubroutineType(types: !35)133!35 = !{!10, !10, !13, !14}134!36 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !37, file: !17, line: 80)135!37 = !DISubprogram(name: "strcat", scope: !7, file: !7, line: 129, type: !38, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)136!38 = !DISubroutineType(types: !39)137!39 = !{!40, !42, !43}138!40 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !41, size: 64)139!41 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)140!42 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !40)141!43 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !44)142!44 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !45, size: 64)143!45 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !41)144!46 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !47, file: !17, line: 81)145!47 = !DISubprogram(name: "strcmp", scope: !7, file: !7, line: 136, type: !48, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)146!48 = !DISubroutineType(types: !49)147!49 = !{!13, !44, !44}148!50 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !51, file: !17, line: 82)149!51 = !DISubprogram(name: "strcoll", scope: !7, file: !7, line: 143, type: !48, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)150!52 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !53, file: !17, line: 83)151!53 = !DISubprogram(name: "strcpy", scope: !7, file: !7, line: 121, type: !38, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)152!54 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !55, file: !17, line: 84)153!55 = !DISubprogram(name: "strcspn", scope: !7, file: !7, line: 272, type: !56, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)154!56 = !DISubroutineType(types: !57)155!57 = !{!14, !44, !44}156!58 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !59, file: !17, line: 85)157!59 = !DISubprogram(name: "strerror", scope: !7, file: !7, line: 396, type: !60, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)158!60 = !DISubroutineType(types: !61)159!61 = !{!40, !13}160!62 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !63, file: !17, line: 86)161!63 = !DISubprogram(name: "strlen", scope: !7, file: !7, line: 384, type: !64, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)162!64 = !DISubroutineType(types: !65)163!65 = !{!14, !44}164!66 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !67, file: !17, line: 87)165!67 = !DISubprogram(name: "strncat", scope: !7, file: !7, line: 132, type: !68, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)166!68 = !DISubroutineType(types: !69)167!69 = !{!40, !42, !43, !14}168!70 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !71, file: !17, line: 88)169!71 = !DISubprogram(name: "strncmp", scope: !7, file: !7, line: 139, type: !72, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)170!72 = !DISubroutineType(types: !73)171!73 = !{!13, !44, !44, !14}172!74 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !75, file: !17, line: 89)173!75 = !DISubprogram(name: "strncpy", scope: !7, file: !7, line: 124, type: !68, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)174!76 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !77, file: !17, line: 90)175!77 = !DISubprogram(name: "strspn", scope: !7, file: !7, line: 276, type: !56, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)176!78 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !79, file: !17, line: 91)177!79 = !DISubprogram(name: "strtok", scope: !7, file: !7, line: 335, type: !38, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)178!80 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !81, file: !17, line: 92)179!81 = !DISubprogram(name: "strxfrm", scope: !7, file: !7, line: 146, type: !82, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)180!82 = !DISubroutineType(types: !83)181!83 = !{!14, !42, !43, !14}182!84 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !85, file: !17, line: 93)183!85 = !DISubprogram(name: "strchr", scope: !7, file: !7, line: 225, type: !86, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)184!86 = !DISubroutineType(types: !87)185!87 = !{!40, !44, !13}186!88 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !89, file: !17, line: 94)187!89 = !DISubprogram(name: "strpbrk", scope: !7, file: !7, line: 302, type: !90, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)188!90 = !DISubroutineType(types: !91)189!91 = !{!40, !44, !44}190!92 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !93, file: !17, line: 95)191!93 = !DISubprogram(name: "strrchr", scope: !7, file: !7, line: 252, type: !86, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)192!94 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !95, file: !17, line: 96)193!95 = !DISubprogram(name: "strstr", scope: !7, file: !7, line: 329, type: !90, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)194!96 = !{i32 7, !"Dwarf Version", i32 4}195!97 = !{i32 2, !"Debug Info Version", i32 3}196!98 = !{i32 1, !"wchar_size", i32 4}197!99 = !{!"clang version 12.0.0"}198!100 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !1, file: !1, line: 4, type: !101, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !103)199!101 = !DISubroutineType(types: !102)200!102 = !{null}201!103 = !{!104, !111}202!104 = !DILocalVariable(name: "point", scope: !100, file: !1, line: 5, type: !105)203!105 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "V3i", file: !1, line: 3, size: 192, flags: DIFlagTypePassByValue, elements: !106, identifier: "_ZTS3V3i")204!106 = !{!107, !109, !110}205!107 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !105, file: !1, line: 3, baseType: !108, size: 64)206!108 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)207!109 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !105, file: !1, line: 3, baseType: !108, size: 64, offset: 64)208!110 = !DIDerivedType(tag: DW_TAG_member, name: "z", scope: !105, file: !1, line: 3, baseType: !108, size: 64, offset: 128)209!111 = !DILocalVariable(name: "other", scope: !100, file: !1, line: 7, type: !105)210!112 = distinct !DIAssignID()211!113 = !DILocation(line: 0, scope: !100)212!114 = distinct !DIAssignID()213!115 = !DILocation(line: 5, column: 3, scope: !100)214!116 = !DILocation(line: 5, column: 7, scope: !100)215!117 = distinct !DIAssignID()216!118 = !DILocation(line: 6, column: 9, scope: !100)217!119 = !DILocation(line: 6, column: 11, scope: !100)218!125 = distinct !DIAssignID()219!126 = !DILocation(line: 7, column: 3, scope: !100)220!127 = !DILocation(line: 7, column: 7, scope: !100)221!128 = distinct !DIAssignID()222!129 = !DILocation(line: 8, column: 22, scope: !100)223!130 = !DILocation(line: 8, column: 3, scope: !100)224!131 = !DILocation(line: 8, column: 32, scope: !100)225!132 = distinct !DIAssignID()226!133 = !DILocation(line: 9, column: 1, scope: !100)227!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}228