Skip to content

Commit ea32197

Browse files
authored
[DebugInfo][SelectionDAG] Fix position of salvaged 'dangling' DBG_VALUEs (#94458)
`SelectionDAGBuilder::handleDebugValue` has a parameter `Order` which represents the insert-at position for the new DBG_VALUE. Prior to this patch `SelectionDAGBuilder::SDNodeOrder` is used instead of the `Order` parameter. The only code-paths where `Order != SDNodeOrder` are the two calls calls to `handleDebugValue` from `salvageUnresolvedDbgValue`. `salvageUnresolvedDbgValue` is called from `resolveOrClearDbgInfo` and `dropDanglingDebugInfo`. The former is called after SelectionDAG completes one block. Some dbg.values can't be lowered to DBG_VALUEs right away. These get recorded as 'dangling' - their order-number is saved - and get salvaged later through `dropDanglingDebugInfo`, or if we've still got dangling debug info once the whole block has been emitted, through `resolveOrClearDbgInfo`. Their saved order-number is passed to `handleDebugValue`. Prior to this patch, DBG_VALUEs inserted using these functions are inserted at the "current" `SDNodeOrder` rather than the intended position that is passed to the function. Fix and add test.
1 parent a53ed21 commit ea32197

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ bool SelectionDAGBuilder::handleDebugValue(ArrayRef<const Value *> Values,
16841684
if (!FragmentExpr)
16851685
continue;
16861686
SDDbgValue *SDV = DAG.getVRegDbgValue(
1687-
Var, *FragmentExpr, RegAndSize.first, false, DbgLoc, SDNodeOrder);
1687+
Var, *FragmentExpr, RegAndSize.first, false, DbgLoc, Order);
16881688
DAG.AddDbgValue(SDV, false);
16891689
Offset += RegisterSize;
16901690
}
@@ -1699,11 +1699,10 @@ bool SelectionDAGBuilder::handleDebugValue(ArrayRef<const Value *> Values,
16991699
}
17001700

17011701
// We have created a SDDbgOperand for each Value in Values.
1702-
// Should use Order instead of SDNodeOrder?
17031702
assert(!LocationOps.empty());
1704-
SDDbgValue *SDV = DAG.getDbgValueList(Var, Expr, LocationOps, Dependencies,
1705-
/*IsIndirect=*/false, DbgLoc,
1706-
SDNodeOrder, IsVariadic);
1703+
SDDbgValue *SDV =
1704+
DAG.getDbgValueList(Var, Expr, LocationOps, Dependencies,
1705+
/*IsIndirect=*/false, DbgLoc, Order, IsVariadic);
17071706
DAG.AddDbgValue(SDV, /*isParameter=*/false);
17081707
return true;
17091708
}

llvm/test/DebugInfo/X86/sdag-order.ll

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; RUN: llc %s --stop-after=finalize-isel -o - | FileCheck %s
2+
3+
;; Check the DBG_VALUE which is salvaged from the dbg.value using an otherwised
4+
;; unused value is emitted at the correct position in the function.
5+
;; Prior (-) to patching (+), these DBG_VALUEs would sink to the bottom of the
6+
;; function:
7+
;; │ bb.1.if.then:
8+
;; │- $rax = COPY %1
9+
;; │ DBG_VALUE 0, $noreg, !9, !DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value)
10+
;; │+ $rax = COPY %1
11+
;; │ RET 0, $rax
12+
13+
; CHECK: bb.1.if.then:
14+
; CHECK-NEXT: DBG_VALUE 0, $noreg, ![[#]], !DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value)
15+
16+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
17+
target triple = "x86_64-unknown-linux-gnu"
18+
19+
define void @badger(ptr sret(i64) %sret) !dbg !5 {
20+
entry:
21+
%f.i = getelementptr i8, ptr null, i64 4
22+
br label %if.then
23+
24+
if.then: ; preds = %entry
25+
tail call void @llvm.dbg.value(metadata ptr %f.i, metadata !9, metadata !DIExpression()), !dbg !11
26+
ret void
27+
}
28+
29+
declare void @llvm.dbg.value(metadata, metadata, metadata)
30+
31+
!llvm.dbg.cu = !{!0}
32+
!llvm.debugify = !{!2, !3}
33+
!llvm.module.flags = !{!4}
34+
35+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
36+
!1 = !DIFile(filename: "test.ll", directory: "/")
37+
!2 = !{i32 3}
38+
!3 = !{i32 1}
39+
!4 = !{i32 2, !"Debug Info Version", i32 3}
40+
!5 = distinct !DISubprogram(name: "_ZNK1d1gEv", linkageName: "_ZNK1d1gEv", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
41+
!6 = !DISubroutineType(types: !7)
42+
!7 = !{}
43+
!8 = !{!9}
44+
!9 = !DILocalVariable(name: "1", scope: !5, file: !1, line: 1, type: !10)
45+
!10 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
46+
!11 = !DILocation(line: 5, column: 1, scope: !5)

0 commit comments

Comments
 (0)