[llvm] 453dc4d - [OPT-DBG] Teach DbgEntityHistoryCalculator about meta-instructions.

Tom Weaver via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 20 06:03:56 PST 2019


Author: Tom Weaver
Date: 2019-12-20T14:03:34Z
New Revision: 453dc4d7ec5a3c3d8f54fc358bc5673834516d48

URL: https://github.com/llvm/llvm-project/commit/453dc4d7ec5a3c3d8f54fc358bc5673834516d48
DIFF: https://github.com/llvm/llvm-project/commit/453dc4d7ec5a3c3d8f54fc358bc5673834516d48.diff

LOG: [OPT-DBG] Teach DbgEntityHistoryCalculator about meta-instructions.

The calculator was considering instructions such as KILLs as clobbers
of a physical address. This is wrong as meta instructions such as KILLs
produce no output in the final program and thus don't clobber or change
any physical location's value. As a result they're safe to ignore whilst
calculating location list ranges.

reviewers: aprantl, vsk

diff revision: https://reviews.llvm.org/D70497

fixes: https://bugs.llvm.org/show_bug.cgi?id=38753

Added: 
    llvm/test/DebugInfo/X86/dbg_entity_calc_ignores_KILL_instruction_at_return.mir
    llvm/test/DebugInfo/X86/dbg_entity_calc_ignores_KILL_instruction_still_clobbers.mir

Modified: 
    llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp
    llvm/test/DebugInfo/COFF/pieces.ll
    llvm/test/DebugInfo/X86/pieces-3.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp b/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp
index 7f9d6c618ad3..170fc8b6d49f 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp
@@ -262,7 +262,9 @@ void llvm::calculateDbgEntityHistory(const MachineFunction *MF,
         DbgLabels.addInstr(L, MI);
       }
 
-      if (MI.isDebugInstr())
+      // Meta Instructions have no output and do not change any values and so
+      // can be safely ignored.
+      if (MI.isMetaInstruction())
         continue;
 
       // Not a DBG_VALUE instruction. It may clobber registers which describe

diff  --git a/llvm/test/DebugInfo/COFF/pieces.ll b/llvm/test/DebugInfo/COFF/pieces.ll
index 70101b5acc6c..64000301fd84 100644
--- a/llvm/test/DebugInfo/COFF/pieces.ll
+++ b/llvm/test/DebugInfo/COFF/pieces.ll
@@ -76,6 +76,7 @@
 ; ASM: [[pad_right_tmp:\.Ltmp[0-9]+]]:
 ; ASM:         #DEBUG_VALUE: pad_right:o <- [DW_OP_LLVM_fragment 32 32] $eax
 ; ASM:         retq
+; ASM: [[pad_right_end:\.Lfunc_end1]]:
 
 
 ; ASM-LABEL: pad_left: # @pad_left
@@ -84,6 +85,7 @@
 ; ASM: [[pad_left_tmp:\.Ltmp[0-9]+]]:
 ; ASM:         #DEBUG_VALUE: pad_left:o <- [DW_OP_LLVM_fragment 0 32] $eax
 ; ASM:         retq
+; ASM: [[pad_left_end:\.Lfunc_end2]]:
 
 
 ; ASM-LABEL: nested: # @nested
@@ -146,7 +148,7 @@
 ; ASM:        .asciz  "pad_right"             # Function name
 ; ASM:        .short  4414                    # Record kind: S_LOCAL
 ; ASM:        .asciz  "o"
-; ASM:        .cv_def_range    [[pad_right_tmp]] [[pad_right_tmp]], subfield_reg, 17, 4
+; ASM:        .cv_def_range    [[pad_right_tmp]] [[pad_right_end]], subfield_reg, 17, 4
 
 ; OBJ-LABEL: GlobalProcIdSym {
 ; OBJ:         Kind: S_GPROC32_ID (0x1147)
@@ -169,7 +171,7 @@
 ; ASM:        .asciz  "pad_left"              # Function name
 ; ASM:        .short  4414                    # Record kind: S_LOCAL
 ; ASM:        .asciz  "o"
-; ASM:        .cv_def_range    [[pad_left_tmp]] [[pad_left_tmp]], subfield_reg, 17, 0
+; ASM:        .cv_def_range    [[pad_left_tmp]] [[pad_left_end]], subfield_reg, 17, 0
 
 ; OBJ-LABEL: GlobalProcIdSym {
 ; OBJ:         Kind: S_GPROC32_ID (0x1147)

diff  --git a/llvm/test/DebugInfo/X86/dbg_entity_calc_ignores_KILL_instruction_at_return.mir b/llvm/test/DebugInfo/X86/dbg_entity_calc_ignores_KILL_instruction_at_return.mir
new file mode 100644
index 000000000000..bfc9df5695e8
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/dbg_entity_calc_ignores_KILL_instruction_at_return.mir
@@ -0,0 +1,76 @@
+--- |
+  ; RUN: llc %s -start-before=cfi-instr-inserter -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
+
+  ; Test that KILL instructions no longer terminate the instruction range of a
+  ; Debug Intrinsic calculated by DbgEntityHistoryCalculator.
+
+  source_filename = ".\\test.cpp"
+  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+  target triple = "x86_64-scei-ps4"
+  
+  define hidden i32 @main(i32 %arg, i8** nocapture readnone %argv) local_unnamed_addr !dbg !8 {
+  entry:
+    call void @llvm.dbg.value(metadata i32 %arg, metadata !19, metadata !DIExpression()), !dbg !22
+    call void @llvm.dbg.value(metadata i8** %argv, metadata !20, metadata !DIExpression()), !dbg !22
+    %add = shl nsw i32 %arg, 1, !dbg !23
+    call void @llvm.dbg.value(metadata i32 %add, metadata !21, metadata !DIExpression()), !dbg !22
+    ret i32 %add, !dbg !24
+  }
+
+  declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+
+  !llvm.dbg.cu = !{!0}
+  !llvm.module.flags = !{!3, !4, !5, !6}
+  !llvm.ident = !{!7}
+
+  !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 10.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, debugInfoForProfiling: true, nameTableKind: None)
+  !1 = !DIFile(filename: "test.cpp", directory: "F:\\test")
+  !2 = !{}
+  !3 = !{i32 2, !"Dwarf Version", i32 4}
+  !4 = !{i32 2, !"Debug Info Version", i32 3}
+  !5 = !{i32 1, !"wchar_size", i32 2}
+  !6 = !{i32 7, !"PIC Level", i32 2}
+  !7 = !{!"clang version 10.0.0"}
+  !8 = distinct !DISubprogram(name: "main", scope: !9, file: !9, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !18)
+  !9 = !DIFile(filename: ".\\test.cpp", directory: "F:\\test")
+  !10 = !DISubroutineType(types: !11)
+  !11 = !{!12, !13, !14}
+  !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+  !13 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !12)
+  !14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64)
+  !15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64)
+  !16 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !17)
+  !17 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+  !18 = !{!19, !20, !21}
+  !19 = !DILocalVariable(name: "arg", arg: 1, scope: !8, file: !9, line: 1, type: !13)
+  !20 = !DILocalVariable(name: "argv", arg: 2, scope: !8, file: !9, line: 1, type: !14)
+  !21 = !DILocalVariable(name: "result", scope: !8, file: !9, line: 2, type: !12)
+  !22 = !DILocation(line: 0, scope: !8)
+  !23 = !DILocation(line: 2, scope: !8)
+  !24 = !DILocation(line: 3, scope: !8)
+
+...
+---
+name:            main
+alignment:       16
+tracksRegLiveness: true
+liveins:
+  - { reg: '$edi', virtual-reg: '' }
+frameInfo:
+  maxAlignment:    1
+body:             |
+  bb.0.entry:
+    liveins: $edi
+
+    renamable $edi = KILL killed $edi, implicit-def $rdi
+    renamable $eax = LEA64_32r killed renamable $rdi, 1, renamable $rdi, 0, $noreg, debug-location !23
+    DBG_VALUE $eax, $noreg, !21, !DIExpression(), debug-location !22
+    ; CHECK-LABEL: DW_TAG_variable
+    ; CHECK: DW_AT_location        (0x00000000:
+    ; CHECK:  [0x0000000000000003,  0x0000000000000004): DW_OP_reg0 RAX)
+    ; CHECK-NEXT: DW_AT_name    ("result")
+    renamable $eax = KILL killed $eax, implicit-def $rax
+    RETQ killed $eax, debug-location !24
+
+...

diff  --git a/llvm/test/DebugInfo/X86/dbg_entity_calc_ignores_KILL_instruction_still_clobbers.mir b/llvm/test/DebugInfo/X86/dbg_entity_calc_ignores_KILL_instruction_still_clobbers.mir
new file mode 100644
index 000000000000..0f01a51a482f
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/dbg_entity_calc_ignores_KILL_instruction_still_clobbers.mir
@@ -0,0 +1,79 @@
+--- |
+  ; RUN: llc %s -start-before=cfi-instr-inserter -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
+
+  ; Test that KILL instructions do not interfere with debug entity history
+  ; liveness ranges. Check that a physical address clobber after KILL still
+  ; closes a debug entites range.
+
+  source_filename = ".\\test.cpp"
+  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+  target triple = "x86_64-scei-ps4"
+  
+  define hidden i32 @main(i32 %arg, i8** nocapture readnone %argv) local_unnamed_addr !dbg !8 {
+  entry:
+    call void @llvm.dbg.value(metadata i32 %arg, metadata !19, metadata !DIExpression()), !dbg !22
+    call void @llvm.dbg.value(metadata i8** %argv, metadata !20, metadata !DIExpression()), !dbg !22
+    %add = shl nsw i32 %arg, 1, !dbg !23
+    call void @llvm.dbg.value(metadata i32 %add, metadata !21, metadata !DIExpression()), !dbg !22
+    ret i32 %add, !dbg !24
+  }
+  
+  declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+  !llvm.dbg.cu = !{!0}
+  !llvm.module.flags = !{!3, !4, !5, !6}
+  !llvm.ident = !{!7}
+
+  !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 10.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, debugInfoForProfiling: true, nameTableKind: None)
+  !1 = !DIFile(filename: "test.cpp", directory: "F:\\test")
+  !2 = !{}
+  !3 = !{i32 2, !"Dwarf Version", i32 4}
+  !4 = !{i32 2, !"Debug Info Version", i32 3}
+  !5 = !{i32 1, !"wchar_size", i32 2}
+  !6 = !{i32 7, !"PIC Level", i32 2}
+  !7 = !{!"clang version 10.0.0"}
+  !8 = distinct !DISubprogram(name: "main", scope: !9, file: !9, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !18)
+  !9 = !DIFile(filename: ".\\test.cpp", directory: "F:\\test")
+  !10 = !DISubroutineType(types: !11)
+  !11 = !{!12, !13, !14}
+  !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+  !13 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !12)
+  !14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64)
+  !15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64)
+  !16 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !17)
+  !17 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+  !18 = !{!19, !20, !21}
+  !19 = !DILocalVariable(name: "arg", arg: 1, scope: !8, file: !9, line: 1, type: !13)
+  !20 = !DILocalVariable(name: "argv", arg: 2, scope: !8, file: !9, line: 1, type: !14)
+  !21 = !DILocalVariable(name: "result", scope: !8, file: !9, line: 2, type: !12)
+  !22 = !DILocation(line: 0, scope: !8)
+  !23 = !DILocation(line: 2, scope: !8)
+  !24 = !DILocation(line: 3, scope: !8)
+
+...
+---
+name:            main
+alignment:       16
+tracksRegLiveness: true
+liveins:
+  - { reg: '$edi', virtual-reg: '' }
+frameInfo:
+  maxAlignment:    1
+body:             |
+  bb.0.entry:
+    liveins: $edi
+
+    renamable $edi = KILL killed $edi, implicit-def $rdi
+    renamable $eax = LEA64_32r killed renamable $rdi, 1, renamable $rdi, 0, $noreg, debug-location !23
+    DBG_VALUE $eax, $noreg, !21, !DIExpression(), debug-location !22
+    ; CHECK-LABEL: DW_TAG_variable
+    ; CHECK: DW_AT_location        (0x00000000:
+    ; CHECK:  [0x0000000000000003,  0x0000000000000007): DW_OP_reg0 RAX)
+    ; CHECK-NEXT: DW_AT_name    ("result")
+    renamable $eax = KILL killed $eax, implicit-def $rax
+    $edi = MOV32rr $eax, debug-location !24
+    $eax = MOV32rr $eax, debug-location !24
+    $edi = MOV32rr $eax, debug-location !24
+    RETQ killed $eax, debug-location !24
+
+...

diff  --git a/llvm/test/DebugInfo/X86/pieces-3.ll b/llvm/test/DebugInfo/X86/pieces-3.ll
index 167fb37d1256..6fde29ff36e0 100644
--- a/llvm/test/DebugInfo/X86/pieces-3.ll
+++ b/llvm/test/DebugInfo/X86/pieces-3.ll
@@ -21,8 +21,9 @@
 ; CHECK-NEXT:     [0x0000000000000007, 0x0000000000000009): DW_OP_reg5 RDI, DW_OP_piece 0x8
 ; CHECK-NEXT:   DW_AT_name {{.*}}"outer"
 ; CHECK: DW_TAG_variable
-; CHECK-NEXT:   DW_AT_name {{.*}}"i1"
-; CHECK-NOT:    DW_AT_location
+; CHECK-NEXT:   DW_AT_location [DW_FORM_data4]        (0x00000044
+; CHECK-NEXT:     [0x0000000000000007, 0x0000000000000009): DW_OP_reg0 RAX, DW_OP_piece 0x4)
+; CHECK-NEXT:   "i1"
 
 ; ModuleID = '/Volumes/Data/llvm/test/DebugInfo/X86/sroasplit-2.ll'
 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"


        


More information about the llvm-commits mailing list