1; RUN: llc %s -o - -stop-after=finalize-isel \ 2; RUN: | FileCheck %s --implicit-check-not=DBG_ 3; RUN: llc --try-experimental-debuginfo-iterators %s -o - -stop-after=finalize-isel \ 4; RUN: | FileCheck %s --implicit-check-not=DBG_ 5 6;; Test coalescing of contiguous fragments in adjacent location definitions. 7;; Further details and check directives inline. 8 9target triple = "x86_64-unknown-linux-gnu" 10 11;; The final store and linked dbg.assign indicate the whole variable is located 12;; on the stack. Coalesce the two fragment defs that are generated (0-32, 13;; 32-64) at the final dbg.assign into one (0-64, which covers the whole 14;; variable meaning we don't need a fragment expression). And check the 15;; first two DBG_VALUEs are not coalesced, since they specify different 16;; locations. 17; CHECK: _Z3fun 18; CHECK-LABEL: bb.0.entry: 19; CHECK-NEXT: DBG_VALUE 1, $noreg, ![[#]], !DIExpression(DW_OP_LLVM_fragment, 0, 32) 20; CHECK-NEXT: DBG_VALUE %stack.0.a, $noreg, ![[#]], !DIExpression(DW_OP_plus_uconst, 4, DW_OP_deref, DW_OP_LLVM_fragment, 32, 32) 21; CHECK-NEXT: MOV32mi %stack.0.a, 1, $noreg, 0, $noreg, 5 22; CHECK-NEXT: DBG_VALUE %stack.0.a, $noreg, ![[#]], !DIExpression(DW_OP_deref) 23; CHECK-NEXT: RET 24define dso_local void @_Z3funv() local_unnamed_addr !dbg !16 { 25entry: 26 %a = alloca i64, !DIAssignID !37 27 call void @llvm.dbg.assign(metadata i64 poison, metadata !20, metadata !DIExpression(), metadata !37, metadata ptr %a, metadata !DIExpression()), !dbg !25 28 call void @llvm.dbg.value(metadata i32 1, metadata !20, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !25 29 store i32 5, ptr %a, !DIAssignID !38 30 call void @llvm.dbg.assign(metadata i32 5, metadata !20, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32), metadata !38, metadata ptr %a, metadata !DIExpression()), !dbg !25 31 ret void 32} 33 34;; Similar to the test above except that the variable has been split over two 35;; allocas, so coalescing should not take place (different memory location for 36;; the fragments). 37; CHECK: Z3funv2 38; CHECK-LABEL: bb.0.entry: 39; CHECK-NEXT: DBG_VALUE %stack.0.a, $noreg, ![[#]], !DIExpression(DW_OP_deref, DW_OP_LLVM_fragment, 0, 32) 40; CHECK-NEXT: DBG_VALUE %stack.1.b, $noreg, ![[#]], !DIExpression(DW_OP_deref, DW_OP_LLVM_fragment, 32, 32) 41; CHECK-NEXT: DBG_VALUE 1, $noreg, ![[#]], !DIExpression(DW_OP_LLVM_fragment, 0, 32) 42; CHECK-NEXT: MOV32mi %stack.0.a, 1, $noreg, 0, $noreg, 5 43;; Both fragments 0-32 and 32-64 are in memory now, but located in different stack slots. 44; CHECK-NEXT: DBG_VALUE %stack.0.a, $noreg, ![[#]], !DIExpression(DW_OP_deref, DW_OP_LLVM_fragment, 0, 32) 45; CHECK-NEXT: RET 46define dso_local void @_Z3funv2() local_unnamed_addr !dbg !39 { 47entry: 48 %a = alloca i32, !DIAssignID !42 49 call void @llvm.dbg.assign(metadata i64 poison, metadata !41, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32), metadata !42, metadata ptr %a, metadata !DIExpression()), !dbg !44 50 %b = alloca i32, !DIAssignID !45 51 call void @llvm.dbg.assign(metadata i64 poison, metadata !41, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32), metadata !45, metadata ptr %b, metadata !DIExpression()), !dbg !44 52 call void @llvm.dbg.value(metadata i32 1, metadata !41, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !44 53 store i32 5, ptr %a, !DIAssignID !43 54 call void @llvm.dbg.assign(metadata i32 5, metadata !41, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32), metadata !43, metadata ptr %a, metadata !DIExpression()), !dbg !44 55 ret void 56} 57 58;; Similar to the first test above except the part that it's the slice 16-32 59;; that is "partially promoted". The dbg defs after the alloca cannot be 60;; coalesced (slices 0-16 and 32-64 are in memory but 16-32 isn't). The entire 61;; variable is on the stack after the store. 62; CHECK: _Z2funv3 63; CHECK-LABEL: bb.0.entry: 64; CHECK-NEXT: DBG_VALUE 2, $noreg, ![[#]], !DIExpression(DW_OP_LLVM_fragment, 16, 16) 65; CHECK-NEXT: DBG_VALUE %stack.0.a, $noreg, ![[#]], !DIExpression(DW_OP_deref, DW_OP_LLVM_fragment, 0, 16) 66; CHECK-NEXT: DBG_VALUE %stack.0.a, $noreg, ![[#]], !DIExpression(DW_OP_plus_uconst, 4, DW_OP_deref, DW_OP_LLVM_fragment, 32, 32) 67; CHECK-NEXT: MOV32mi %stack.0.a, 1, $noreg, 0, $noreg, 5 68; CHECK-NEXT: DBG_VALUE %stack.0.a, $noreg, ![[#]], !DIExpression(DW_OP_deref) 69; CHECK-NEXT: RET 70define dso_local void @_Z2funv3() local_unnamed_addr !dbg !46 { 71entry: 72 %a = alloca i64, !DIAssignID !49 73 call void @llvm.dbg.assign(metadata i64 poison, metadata !48, metadata !DIExpression(), metadata !49, metadata ptr %a, metadata !DIExpression()), !dbg !51 74 call void @llvm.dbg.value(metadata i32 2, metadata !48, metadata !DIExpression(DW_OP_LLVM_fragment, 16, 16)), !dbg !51 75 store i32 5, ptr %a, !DIAssignID !50 76 call void @llvm.dbg.assign(metadata i32 5, metadata !48, metadata !DIExpression(DW_OP_LLVM_fragment, 16, 16), metadata !50, metadata ptr %a, metadata !DIExpression(DW_OP_plus_uconst, 2)), !dbg !51 77 ret void 78} 79 80declare void @llvm.dbg.value(metadata, metadata, metadata) 81declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) 82 83!llvm.dbg.cu = !{!2} 84!llvm.module.flags = !{!8, !9, !10, !11, !12, !13, !14} 85!llvm.ident = !{!15} 86 87!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 88!1 = distinct !DIGlobalVariable(name: "G", scope: !2, file: !3, line: 1, type: !7, isLocal: false, isDefinition: true) 89!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 17.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None) 90!3 = !DIFile(filename: "test.cpp", directory: "/") 91!4 = !{!0, !5} 92!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression()) 93!6 = distinct !DIGlobalVariable(name: "F", scope: !2, file: !3, line: 1, type: !7, isLocal: false, isDefinition: true) 94!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 95!8 = !{i32 7, !"Dwarf Version", i32 5} 96!9 = !{i32 2, !"Debug Info Version", i32 3} 97!10 = !{i32 1, !"wchar_size", i32 4} 98!11 = !{i32 8, !"PIC Level", i32 2} 99!12 = !{i32 7, !"PIE Level", i32 2} 100!13 = !{i32 7, !"uwtable", i32 2} 101!14 = !{i32 7, !"debug-info-assignment-tracking", i1 true} 102!15 = !{!"clang version 17.0.0"} 103!16 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !3, file: !3, line: 3, type: !17, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !19) 104!17 = !DISubroutineType(types: !18) 105!18 = !{null} 106!19 = !{!20} 107!20 = !DILocalVariable(name: "X", scope: !16, file: !3, line: 4, type: !21) 108!21 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Pair", file: !3, line: 2, size: 64, flags: DIFlagTypePassByValue, elements: !22, identifier: "_ZTS4Pair") 109!22 = !{} 110!25 = !DILocation(line: 0, scope: !16) 111!26 = !DILocation(line: 7, column: 7, scope: !27) 112!27 = distinct !DILexicalBlock(scope: !16, file: !3, line: 7, column: 7) 113!37 = distinct !DIAssignID() 114!38 = distinct !DIAssignID() 115!39 = distinct !DISubprogram(name: "fun2", linkageName: "_Z3funv2", scope: !3, file: !3, line: 3, type: !17, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !40) 116!40 = !{!41} 117!41 = !DILocalVariable(name: "X", scope: !39, file: !3, line: 10, type: !21) 118!42 = distinct !DIAssignID() 119!43 = distinct !DIAssignID() 120!44 = !DILocation(line: 0, scope: !39) 121!45 = distinct !DIAssignID() 122!46 = distinct !DISubprogram(name: "fun3", linkageName: "_Z3funv3", scope: !3, file: !3, line: 3, type: !17, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !47) 123!47 = !{!48} 124!48 = !DILocalVariable(name: "X", scope: !46, file: !3, line: 10, type: !21) 125!49 = distinct !DIAssignID() 126!50 = distinct !DIAssignID() 127!51 = !DILocation(line: 0, scope: !46) 128