[DebugInfo][InstrRef] Correctly ignore DBG_VALUE_LIST in InstrRef mode

This patch makes InstrRefBasedLDV "safe" to work with DBG_VALUE_LISTs. It
doesn't actually interpret them, but it recognises that they specify
variable locations and avoids propagating false locations, which is better
than the current state. Observe the attached tes

 * We avoid propagating DBG_VALUE_LISTs into successor blocks, as they're
   not "currently" supported,
 * We don't propagate other variable locations across DBG_VALUE_LISTs,
   because we know that the variable location is terminated by the
   DBG_VALUE_LIST.

Differential Revision: https://reviews.llvm.org/D108143
This commit is contained in:
Jeremy Morse 2021-08-20 14:48:45 +01:00
parent 48f73ee666
commit ce8254d096
2 changed files with 85 additions and 0 deletions

View File

@ -1759,6 +1759,17 @@ bool InstrRefBasedLDV::transferDebugValue(const MachineInstr &MI) {
if (Scope == nullptr)
return true; // handled it; by doing nothing
// For now, ignore DBG_VALUE_LISTs when extending ranges. Allow it to
// contribute to locations in this block, but don't propagate further.
// Interpret it like a DBG_VALUE $noreg.
if (MI.isDebugValueList()) {
if (VTracker)
VTracker->defVar(MI, Properties, None);
if (TTracker)
TTracker->redefVar(MI, Properties, None);
return true;
}
const MachineOperand &MO = MI.getOperand(0);
// MLocTracker needs to know that this register is read, even if it's only

View File

@ -0,0 +1,74 @@
# RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \
# RUN: -experimental-debug-variable-locations -run-pass=livedebugvalues\
# RUN: | FileCheck %s --implicit-check-not=DBG_VALUE \
# RUN: --implicit-check-not=DBG_VALUE_LIST
#
# Test that any DBG_VALUE_LISTs observed are interpreted as DBG_VALUE $noreg.
# This is obviously sub-optimal, but avoids false variable locations, for the
# period of time until InstrRefBasedLDV supports these variable locations.
#
--- |
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-unknown-linux-gnu"
define dso_local i32 @foo() !dbg !7 {
entry:
ret i32 0
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "test.c", directory: "/tmp/out.c")
!2 = !{}
!3 = !{i32 7, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{!""}
!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
!8 = !DISubroutineType(types: !9)
!9 = !{!10, !11, !11}
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!11 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
!12 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 3, type: !11)
!13 = !DILocation(line: 0, scope: !7)
!14 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 3, type: !11)
...
---
name: foo
alignment: 16
tracksRegLiveness: true
machineFunctionInfo: {}
body: |
bb.0:
liveins: $rdi, $rsi, $r14, $rbx
; CHECK-LABEL: bb.0:
$rax = MOV64ri 0, debug-location !13
$rbx = MOV64ri 0, debug-location !13
DBG_VALUE_LIST !12, !DIExpression(), $rax, $rbx, debug-location !13
; CHECK: DBG_VALUE_LIST
bb.1:
liveins: $rax
; CHECK-LABEL: bb.1:
; Earlier DBG_VALUE_LIST should not be propagated here, would be caught
; by implicit check not on FileCheck cmdline.
DBG_VALUE $rax, $noreg, !12, !DIExpression(), debug-location !13
; CHECK: DBG_VALUE
$rbx = MOV64ri 0, debug-location !13
DBG_VALUE_LIST !12, !DIExpression(), $rax, $rbx, debug-location !13
; CHECK: DBG_VALUE_LIST
$rbx = COPY killed $rax, debug-location !13
$rax = MOV64ri 0, debug-location !13
; This clobber of $rax might cause LDV to re-issue a DBG_VALUE stating the
; variable location as $rbx. However, the preceeding DBG_VALUE_LIST should
; terminate the earlier location.
RETQ implicit $rbx, debug-location !13
...