1; RUN: opt -S -passes=sroa -sroa-skip-mem2reg %s \ 2; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg" 3; RUN: opt --try-experimental-debuginfo-iterators -S -passes=sroa -sroa-skip-mem2reg %s \ 4; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg" 5 6;; NOTE: This is the same as split-pre-fragmented-store.ll except the base 7;; alloca's dbg.assign has been altered to contain a fragment of the full 8;; variable - the variable's size has been modified from 64 to 96 bits. 9;; This version of the test ensures that the behaviour being tested is still 10;; correct when the base alloca doesn't hold an entire variable. 11 12;; IR hand-modified, originally generated from: 13;; struct Pair { int a; int b; }; 14;; Pair getVar(); 15;; int fun() { 16;; Pair var; 17;; var = getVar(); 18;; return var.b; 19;; } 20;; Modification: split the dbg.assign linked the the memcpy(64 bits) into two, 21;; each describing a 32 bit fragment. 22;; 23;; Check that assignment tracking updates in SROA work when the store being 24;; split is described with one dbg.assign (covering different fragments). The 25;; store may have been already split and then merged again at some point. 26 27;; Alloca for var.a and associated dbg.assign: 28; CHECK: %var.sroa.0 = alloca i32, align 4, !DIAssignID ![[id_1:[0-9]+]] 29; CHECK-NEXT: #dbg_assign(i1 undef, ![[var:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 32, 32), ![[id_1]], ptr %var.sroa.0, !DIExpression(), 30 31;; Alloca for var.b and associated dbg.assign: 32; CHECK-NEXT: %var.sroa.1 = alloca i32, align 4, !DIAssignID ![[id_2:[0-9]+]] 33; CHECK-NEXT: #dbg_assign(i1 undef, ![[var]], !DIExpression(DW_OP_LLVM_fragment, 64, 32), ![[id_2]], ptr %var.sroa.1, !DIExpression(), 34 35;; Store to var.b (split from store to var) and associated dbg.assigns. The 36;; dbg.assign for the fragment covering the (pre-split) assignment to var.a 37;; should not be linked to the store. 38; CHECK: store i32 %[[v:.*]], ptr %var.sroa.1,{{.*}}!DIAssignID ![[id_3:[0-9]+]] 39; CHECK-NEXT: #dbg_assign(i32 %{{.*var\.sroa\.0.*}}, ![[var]], !DIExpression(DW_OP_LLVM_fragment, 32, 32), ![[id_4:[0-9]+]], ptr %var.sroa.0, !DIExpression(), 40; CHECK-NEXT: #dbg_assign(i32 %[[v]], ![[var]], !DIExpression(DW_OP_LLVM_fragment, 64, 32), ![[id_3]], ptr %var.sroa.1, !DIExpression(), 41 42; CHECK-DAG: ![[id_1]] = distinct !DIAssignID() 43; CHECK-DAG: ![[id_2]] = distinct !DIAssignID() 44; CHECK-DAG: ![[id_3]] = distinct !DIAssignID() 45; CHECK-DAG: ![[id_4]] = distinct !DIAssignID() 46 47%struct.Tuple = type { i32, i32, i32 } 48 49define dso_local noundef i32 @_Z3funv() !dbg !9 { 50entry: 51 %var = alloca [2 x i32], align 4, !DIAssignID !19 52 call void @llvm.dbg.assign(metadata i1 undef, metadata !14, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 64), metadata !19, metadata ptr %var, metadata !DIExpression()), !dbg !20 53 %ref.tmp = alloca %struct.Tuple, align 4 54 %call = call i64 @_Z6getVarv(), !dbg !22 55 store i64 %call, ptr %ref.tmp, align 4, !dbg !22 56 call void @llvm.memcpy.p0.p0.i64(ptr align 4 %var, ptr align 4 %ref.tmp, i64 8, i1 false), !dbg !23, !DIAssignID !29 57 call void @llvm.dbg.assign(metadata i1 undef, metadata !14, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32), metadata !29, metadata ptr %var, metadata !DIExpression()), !dbg !20 58 call void @llvm.dbg.assign(metadata i1 undef, metadata !14, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 32), metadata !29, metadata ptr %var, metadata !DIExpression(DW_OP_plus, DW_OP_constu, 4)), !dbg !20 59 %b = getelementptr inbounds %struct.Tuple, ptr %var, i32 0, i32 1, !dbg !31 60 %0 = load i32, ptr %b, align 4, !dbg !31 61 ret i32 %0, !dbg !35 62} 63 64declare !dbg !36 i64 @_Z6getVarv() 65declare void @llvm.dbg.declare(metadata, metadata, metadata) 66declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) 67declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) 68 69!llvm.dbg.cu = !{!0} 70!llvm.module.flags = !{!2, !3, !4, !5, !6, !7} 71!llvm.ident = !{!8} 72 73!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 16.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) 74!1 = !DIFile(filename: "test.cpp", directory: "/") 75!2 = !{i32 7, !"Dwarf Version", i32 5} 76!3 = !{i32 2, !"Debug Info Version", i32 3} 77!4 = !{i32 1, !"wchar_size", i32 4} 78!5 = !{i32 8, !"PIC Level", i32 2} 79!6 = !{i32 7, !"PIE Level", i32 2} 80!7 = !{i32 7, !"uwtable", i32 2} 81!8 = !{!"clang version 16.0.0"} 82!9 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !1, file: !1, line: 3, type: !10, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13) 83!10 = !DISubroutineType(types: !11) 84!11 = !{!12} 85!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 86!13 = !{!14} 87!14 = !DILocalVariable(name: "var", scope: !9, file: !1, line: 4, type: !15) 88!15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Tuple", file: !1, line: 1, size: 96, flags: DIFlagTypePassByValue, elements: !16, identifier: "_ZTS4Pair") 89!16 = !{!17, !18, !40} 90!17 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !15, file: !1, line: 1, baseType: !12, size: 32) 91!18 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !15, file: !1, line: 1, baseType: !12, size: 32, offset: 32) 92!19 = distinct !DIAssignID() 93!20 = !DILocation(line: 0, scope: !9) 94!21 = !DILocation(line: 4, column: 3, scope: !9) 95!22 = !DILocation(line: 5, column: 9, scope: !9) 96!23 = !DILocation(line: 5, column: 7, scope: !9) 97!29 = distinct !DIAssignID() 98!30 = !DILocation(line: 5, column: 3, scope: !9) 99!31 = !DILocation(line: 6, column: 14, scope: !9) 100!34 = !DILocation(line: 7, column: 1, scope: !9) 101!35 = !DILocation(line: 6, column: 3, scope: !9) 102!36 = !DISubprogram(name: "getVar", linkageName: "_Z6getVarv", scope: !1, file: !1, line: 2, type: !37, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !39) 103!37 = !DISubroutineType(types: !38) 104!38 = !{!15} 105!39 = !{} 106!40 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !15, file: !1, line: 1, baseType: !12, size: 32, offset: 64) 107