Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit adbef70

Browse files
bjopevedantk
authored andcommitted
[LiveDebugVariables] Avoid faulty addDefsFromCopies in computeIntervals
Summary: When computeIntervals is looking through COPY instruction to extend the location mapping for a debug variable it did not handle subregisters correctly. For example DBG_VALUE debug-use %0.sub_8bit_hi, ... %1:gr16 = COPY %0 was transformed into DBG_VALUE debug-use %0.sub_8bit_hi, ... %1:gr16 = COPY %0 DBG_VALUE debug-use %1, ... So the subregister index was missing in the added DBG_VALUE. As long as the subreg refered to the least significant bits of the superreg, then I guess we could get the correct result in a debugger even when referring to the superreg. But as in the example above when the subreg refers to other parts of the superreg, then debuginfo would be incorrect. I'm not sure exactly how to fix this properly, so this patch just avoids looking through the COPY when there is a subreg involved (for more info, see the FIXME added in the code). Reviewers: rnk, aprantl Reviewed By: aprantl Subscribers: JDevlieghere, llvm-commits Tags: #debug-info Differential Revision: https://reviews.llvm.org/D50788 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340679 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit 48bfbb5)
1 parent 1e98371 commit adbef70

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

lib/CodeGen/LiveDebugVariables.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,15 @@ void UserValue::computeIntervals(MachineRegisterInfo &MRI,
752752
}
753753
SmallVector<SlotIndex, 16> Kills;
754754
extendDef(Idx, Loc, LI, VNI, &Kills, LIS);
755-
if (LI)
755+
// FIXME: Handle sub-registers in addDefsFromCopies. The problem is that
756+
// if the original location for example is %vreg0:sub_hi, and we find a
757+
// full register copy in addDefsFromCopies (at the moment it only handles
758+
// full register copies), then we must add the sub1 sub-register index to
759+
// the new location. However, that is only possible if the new virtual
760+
// register is of the same regclass (or if there is an equivalent
761+
// sub-register in that regclass). For now, simply skip handling copies if
762+
// a sub-register is involved.
763+
if (LI && !LocMO.getSubReg())
756764
addDefsFromCopies(LI, Loc.locNo(), Loc.wasIndirect(), Kills, Defs, MRI,
757765
LIS);
758766
continue;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# RUN: llc -O1 -start-after simple-register-coalescing -o - %s | FileCheck %s
2+
3+
--- |
4+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5+
target triple = "x86_64-pc-linux-gnu"
6+
7+
define i16 @foo(i8 %zzz) !dbg !4 {
8+
entry:
9+
ret i16 1
10+
}
11+
12+
; Function Attrs: nounwind readnone speculatable
13+
declare void @llvm.dbg.value(metadata, metadata, metadata)
14+
15+
!llvm.dbg.cu = !{!0}
16+
!llvm.module.flags = !{!3}
17+
18+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2)
19+
!1 = !DIFile(filename: "test.c", directory: "")
20+
!2 = !{}
21+
!3 = !{i32 1, !"Debug Info Version", i32 3}
22+
!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
23+
!5 = !DISubroutineType(types: !6)
24+
!6 = !{null}
25+
!7 = !DILocalVariable(name: "zzz", arg: 1, scope: !4, file: !1, line: 3, type: !8)
26+
!8 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed)
27+
!9 = !DILocation(line: 0, scope: !4)
28+
!10 = !DILocation(line: 4, column: 22, scope: !11)
29+
!11 = distinct !DILexicalBlock(scope: !4, file: !1, line: 3, column: 19)
30+
31+
...
32+
---
33+
name: foo
34+
tracksRegLiveness: true
35+
body: |
36+
bb.0:
37+
%0:gr16_abcd = MOV16ri 1
38+
39+
bb.1:
40+
DBG_VALUE debug-use %0.sub_8bit_hi, debug-use $noreg, !7, !DIExpression(), debug-location !9
41+
%1:gr16 = COPY %0
42+
%2:gr16 = COPY %0
43+
44+
bb.2:
45+
$ax = COPY %1
46+
$dx = COPY %2
47+
RETQ killed $ax, killed $dx
48+
...
49+
50+
# This test case was created as a reproducer for a bug when we got incorrect
51+
# DBG_VALUE instructions after regalloc like this:
52+
#
53+
# movw $1, %cx
54+
# #DEBUG_VALUE: foo:zzz <- $ch
55+
# movl %ecx, %eax
56+
# #DEBUG_VALUE: foo:zzz <- $ax
57+
#
58+
# The above is incorrect since the DBG_VALUE in the input is refering to the
59+
# hi subreg, so after the COPY/movl the value is in $ah and not $ax (nor $al).
60+
#
61+
# We currently only get one DEBUG_VALUE here. In the future we could allow a
62+
# second DEBUG_VALUE, as long as it is mapped to the hi subreg of the movl
63+
# dst.
64+
#
65+
# CHECK-NOT: #DEBUG_VALUE:
66+
# CHECK: #DEBUG_VALUE: foo:zzz <- ${{[abcd]+}}h
67+
# CHECK-NOT: #DEBUG_VALUE:

0 commit comments

Comments
 (0)