Skip to content

Commit 9786198

Browse files
committed
[LiveDebugVariables] Fix a DBG_VALUE reordering issue (#111124)
LDV could reorder reinserted fragment and non-fragment debug values for the same variable (compared to the input order), potentially resulting in stale values being presented. For example, before: DBG_VALUE 1001, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 0, 16) DBG_VALUE 1002, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 16, 16) DBG_VALUE %0, $noreg, !13, !DIExpression() After (without this patch): DBG_VALUE %stack.0, 0, !13, !DIExpression() DBG_VALUE 1002, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 16, 16) DBG_VALUE 1001, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 0, 16) It would also reorder DBG_VALUEs for different variables. Although that does not matter for the debug information output, it resulted in some noise in before/after pass diffs. This should hopefully align so that instruction referencing and DBG_VALUE emit debug instructions in the same order (see the sdag-salvage-add.ll change).
1 parent f719886 commit 9786198

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

llvm/lib/CodeGen/LiveDebugVariables.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,8 +1625,9 @@ findInsertLocation(MachineBasicBlock *MBB, SlotIndex Idx, LiveIntervals &LIS,
16251625
}
16261626

16271627
// Don't insert anything after the first terminator, though.
1628-
return MI->isTerminator() ? MBB->getFirstTerminator() :
1629-
std::next(MachineBasicBlock::iterator(MI));
1628+
auto It = MI->isTerminator() ? MBB->getFirstTerminator()
1629+
: std::next(MachineBasicBlock::iterator(MI));
1630+
return skipDebugInstructionsForward(It, MBB->end());
16301631
}
16311632

16321633
/// Find an iterator for inserting the next DBG_VALUE instruction

llvm/test/CodeGen/AMDGPU/debug-value2.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ define <4 x float> @Scene_transformT(i32 %subshapeIdx, <4 x float> %v, float %ti
1212
entry:
1313
; CHECK: v_mov_b32_e32 v[[COPIED_ARG_PIECE:[0-9]+]], v9
1414

15-
; CHECK: ;DEBUG_VALUE: Scene_transformT:gScene <- [DW_OP_constu 1, DW_OP_swap, DW_OP_xderef, DW_OP_LLVM_fragment 0 32] $vgpr6
15+
; CHECK: ;DEBUG_VALUE: Scene_transformT:gSceneOffsets <- [DW_OP_constu 1, DW_OP_swap, DW_OP_xderef, DW_OP_LLVM_fragment 32 32] $vgpr[[COPIED_ARG_PIECE]]
16+
; CHECK: ;DEBUG_VALUE: Scene_transformT:gSceneOffsets <- [DW_OP_constu 1, DW_OP_swap, DW_OP_xderef, DW_OP_LLVM_fragment 0 32] $vgpr8
1617
; CHECK: ;DEBUG_VALUE: Scene_transformT:gScene <- [DW_OP_constu 1, DW_OP_swap, DW_OP_xderef, DW_OP_LLVM_fragment 32 32] $vgpr7
18+
; CHECK: ;DEBUG_VALUE: Scene_transformT:gScene <- [DW_OP_constu 1, DW_OP_swap, DW_OP_xderef, DW_OP_LLVM_fragment 0 32] $vgpr6
1719
call void @llvm.dbg.value(metadata ptr addrspace(1) %gScene, metadata !120, metadata !DIExpression(DW_OP_constu, 1, DW_OP_swap, DW_OP_xderef)), !dbg !154
18-
; CHECK: ;DEBUG_VALUE: Scene_transformT:gSceneOffsets <- [DW_OP_constu 1, DW_OP_swap, DW_OP_xderef, DW_OP_LLVM_fragment 0 32] $vgpr8
19-
; CHECK: ;DEBUG_VALUE: Scene_transformT:gSceneOffsets <- [DW_OP_constu 1, DW_OP_swap, DW_OP_xderef, DW_OP_LLVM_fragment 32 32] $vgpr[[COPIED_ARG_PIECE]]
2020
call void @llvm.dbg.value(metadata ptr addrspace(1) %gSceneOffsets, metadata !121, metadata !DIExpression(DW_OP_constu, 1, DW_OP_swap, DW_OP_xderef)), !dbg !155
2121
%call = tail call ptr addrspace(1) @Scene_getSubShapeData(i32 %subshapeIdx, ptr addrspace(1) %gScene, ptr addrspace(1) %gSceneOffsets)
2222
%m_linearMotion = getelementptr inbounds %struct.ShapeData, ptr addrspace(1) %call, i64 0, i32 2

llvm/test/DebugInfo/MIR/Mips/livedebugvars-stop-trimming-loc.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
## This tests that LiveDebugVariables does not trim non-inlined variable
44
## location.
55

6+
# CHECK: ![[VARA:.*]] = !DILocalVariable(name: "a"
67
# CHECK: ![[VARB:.*]] = !DILocalVariable(name: "b"
78
# CHECK: ![[VARC:.*]] = !DILocalVariable(name: "c"
89
# CHECK: $at = COPY $a2
910
# CHECK-NEXT: DBG_VALUE $at, $noreg, ![[VARC]], !DIExpression(), debug-location
1011
# CHECK: $s0 = COPY $a1
12+
# CHECK-NEXT: DBG_VALUE $a0, $noreg, ![[VARA]], !DIExpression(), debug-location
1113
# CHECK-NEXT: DBG_VALUE $s0, $noreg, ![[VARB]], !DIExpression(), debug-location
1214

1315
--- |

llvm/test/DebugInfo/Mips/livedebugvariables-reorder.mir

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# RUN: llc -emit-call-site-info %s -mtriple=mips -start-before=register-coalescer -stop-after=virtregrewriter -o - | FileCheck %s
22

3-
# FIXME: LiveDebugVariables should not reorder the stack location DBG_VALUE and
4-
# the fragmented DBG_VALUEs for aaa, as the latter may represent a stale value.
5-
# It should also not reorder the DBG_VALUEs for the different variables, as
6-
# that results in noise in pass before/after diffs.
3+
# Verify that LiveDebugVariables does not reorder the stack location DBG_VALUE
4+
# and the fragmented DBG_VALUEs for aaa, as the latter may represent a stale
5+
# value. It should also not reorder the DBG_VALUEs for the different variables,
6+
# as that results in noise in pass before/after diffs.
77

88
# CHECK-DAG: ![[aaa:[0-9]+]] = !DILocalVariable(name: "aaa"
99
# CHECK-DAG: ![[bbb:[0-9]+]] = !DILocalVariable(name: "bbb"
1010
# CHECK-DAG: ![[ccc:[0-9]+]] = !DILocalVariable(name: "ccc"
1111
# CHECK-DAG: ![[ddd:[0-9]+]] = !DILocalVariable(name: "ddd"
1212

13-
# CHECK: DBG_VALUE %stack.0, 0, ![[aaa]], !DIExpression()
14-
# CHECK-NEXT: DBG_VALUE 444, $noreg, ![[ddd]], !DIExpression()
15-
# CHECK-NEXT: DBG_VALUE 333, $noreg, ![[ccc]], !DIExpression()
16-
# CHECK-NEXT: DBG_VALUE 222, $noreg, ![[bbb]], !DIExpression()
13+
# CHECK: DBG_VALUE 1001, $noreg, ![[aaa]], !DIExpression(DW_OP_LLVM_fragment, 0, 16)
1714
# CHECK-NEXT: DBG_VALUE 1002, $noreg, ![[aaa]], !DIExpression(DW_OP_LLVM_fragment, 16, 16)
18-
# CHECK-NEXT: DBG_VALUE 1001, $noreg, ![[aaa]], !DIExpression(DW_OP_LLVM_fragment, 0, 16)
15+
# CHECK-NEXT: DBG_VALUE 222, $noreg, ![[bbb]], !DIExpression()
16+
# CHECK-NEXT: DBG_VALUE 333, $noreg, ![[ccc]], !DIExpression()
17+
# CHECK-NEXT: DBG_VALUE 444, $noreg, ![[ddd]], !DIExpression()
18+
# CHECK-NEXT: DBG_VALUE %stack.0, 0, ![[aaa]], !DIExpression()
1919

2020
--- |
2121
target datalayout = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64"

llvm/test/DebugInfo/X86/live-debug-vars-discard-invalid.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ body: |
118118

119119
# CHECK-LABEL: bb.3:
120120
# CHECK: dead renamable $rcx = IMPLICIT_DEF
121-
# CHECK-NEXT: DBG_VALUE 0, $noreg, !23, !DIExpression()
122121
# CHECK-NEXT: DBG_VALUE $rcx, $noreg, !18, !DIExpression()
122+
# CHECK-NEXT: DBG_VALUE 0, $noreg, !23, !DIExpression()
123123

124124
# CHECK-LABEL: bb.4:
125125
# CHECK: liveins: $rax
126126
# CHECK: DBG_VALUE $rax, $noreg, !18, !DIExpression()
127127
# CHECK-NEXT: renamable $rax = BTS64ri8 killed renamable $rax, 0, implicit-def $eflags
128-
# CHECK-NEXT: DBG_VALUE 0, $noreg, !23, !DIExpression()
129128
# CHECK-NEXT: DBG_VALUE $rax, $noreg, !18, !DIExpression()
129+
# CHECK-NEXT: DBG_VALUE 0, $noreg, !23, !DIExpression()
130130
# CHECK-NEXT: renamable $rax = BTS64ri8 killed renamable $rax, 0, implicit-def $eflags
131131
# CHECK-NEXT: DBG_VALUE $rax, $noreg, !18, !DIExpression()
132132
# CHECK-NEXT: dead renamable $rax = BTS64ri8 killed renamable $rax, 0, implicit-def $eflags

llvm/test/DebugInfo/X86/sdag-salvage-add.ll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,18 @@
2727
; instruction selection as it is folded into the load. As a result, we should
2828
; refer to s4 and myVar with complex expressions.
2929
;
30-
; NB: instruction referencing and DBG_VALUE modes produce debug insts in a
31-
; different order.
32-
;
3330
; CHECK: ![[S4:.*]] = !DILocalVariable(name: "s4",
3431
; CHECK: ![[MYVAR:.*]] = !DILocalVariable(name: "myVar",
3532
; CHECK: $rax = MOV64rm
3633
; INSTRREF-SAME: debug-instr-number 2,
3734
; INSTRREF-NEXT: DBG_INSTR_REF ![[S4]],
38-
; DBGVALUE-NEXT: DBG_VALUE $rax, $noreg, ![[MYVAR]],
35+
; DBGVALUE-NEXT: DBG_VALUE $rax, $noreg, ![[S4]],
3936
; DBGVALUE-SAME: !DIExpression(DW_OP_plus_uconst, 4096, DW_OP_stack_value)
4037
; INSTRREF-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_plus_uconst, 4096, DW_OP_stack_value)
4138
; INSTRREF-SAME: dbg-instr-ref(2, 0)
4239

4340
; INSTRREF: DBG_INSTR_REF ![[MYVAR]],
44-
; DBGVALUE: DBG_VALUE $rax, $noreg, ![[S4]],
41+
; DBGVALUE: DBG_VALUE $rax, $noreg, ![[MYVAR]],
4542
; DBGVALUE-SAME: !DIExpression(DW_OP_plus_uconst, 4096, DW_OP_stack_value)
4643
; INSTRREF-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_plus_uconst, 4096, DW_OP_stack_value)
4744
; INSTRREF-SAME: dbg-instr-ref(2, 0)

0 commit comments

Comments
 (0)