[llvm] 2b3c13b - [DebugInfo] Treat empty metadata operands the same as undef operands in SelectionDAG
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 26 01:03:44 PDT 2023
Author: OCHyams
Date: 2023-04-26T09:03:07+01:00
New Revision: 2b3c13b7166b479439ac05954b532c44aa3414fc
URL: https://github.com/llvm/llvm-project/commit/2b3c13b7166b479439ac05954b532c44aa3414fc
DIFF: https://github.com/llvm/llvm-project/commit/2b3c13b7166b479439ac05954b532c44aa3414fc.diff
LOG: [DebugInfo] Treat empty metadata operands the same as undef operands in SelectionDAG
Without this patch SelectionDAG silently drops dbg.values using `!{}` operands.
Related to https://discourse.llvm.org/t/auto-undef-debug-uses-of-a-deleted-value
Reviewed By: StephenTozer
Differential Revision: https://reviews.llvm.org/D140990
Added:
llvm/test/DebugInfo/X86/dbg-empty-metadata-lowering.ll
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
llvm/test/CodeGen/AMDGPU/llvm.dbg.value.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 329fde6401818..df6b24f86941b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1405,6 +1405,17 @@ void SelectionDAGBuilder::salvageUnresolvedDbgValue(DanglingDebugInfo &DDI) {
<< "\n");
}
+void SelectionDAGBuilder::handleKillDebugValue(DILocalVariable *Var,
+ DIExpression *Expr,
+ DebugLoc DbgLoc,
+ unsigned Order) {
+ Value *Poison = PoisonValue::get(Type::getInt1Ty(*Context));
+ DIExpression *NewExpr =
+ const_cast<DIExpression *>(DIExpression::convertToUndefExpression(Expr));
+ handleDebugValue(Poison, Var, NewExpr, DbgLoc, Order,
+ /*IsVariadic*/ false);
+}
+
bool SelectionDAGBuilder::handleDebugValue(ArrayRef<const Value *> Values,
DILocalVariable *Var,
DIExpression *Expr, DebugLoc DbgLoc,
@@ -6226,11 +6237,14 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
DILocalVariable *Variable = DI.getVariable();
DIExpression *Expression = DI.getExpression();
dropDanglingDebugInfo(Variable, Expression);
- SmallVector<Value *, 4> Values(DI.getValues());
- if (Values.empty())
+
+ if (DI.isKillLocation()) {
+ handleKillDebugValue(Variable, Expression, DI.getDebugLoc(), SDNodeOrder);
return;
+ }
- if (llvm::is_contained(Values, nullptr))
+ SmallVector<Value *, 4> Values(DI.getValues());
+ if (Values.empty())
return;
bool IsVariadic = DI.hasArgList();
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
index 45685f59e1631..95580b1ccbd10 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
@@ -376,6 +376,10 @@ class SelectionDAGBuilder {
DIExpression *Expr, DebugLoc DbgLoc, unsigned Order,
bool IsVariadic);
+ /// Create a record for a kill location debug intrinsic.
+ void handleKillDebugValue(DILocalVariable *Var, DIExpression *Expr,
+ DebugLoc DbgLoc, unsigned Order);
+
/// Evict any dangling debug information, attempting to salvage it first.
void resolveOrClearDbgInfo();
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.dbg.value.ll b/llvm/test/CodeGen/AMDGPU/llvm.dbg.value.ll
index d8358db7e96b9..5a49314691aaa 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.dbg.value.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.dbg.value.ll
@@ -20,7 +20,7 @@ entry:
; SIOptimizeExecMaskingPreRA (somehow related to undef argument).
; GCN-LABEL: {{^}}only_undef_dbg_value:
-; NOOPT: ;DEBUG_VALUE: test_debug_value:globalptr_arg <- [DW_OP_constu 1, DW_OP_swap, DW_OP_xderef] undef
+; NOOPT: ;DEBUG_VALUE: test_debug_value:globalptr_arg <- undef
; NOOPT-NEXT: s_endpgm
; OPT: s_endpgm
diff --git a/llvm/test/DebugInfo/X86/dbg-empty-metadata-lowering.ll b/llvm/test/DebugInfo/X86/dbg-empty-metadata-lowering.ll
new file mode 100644
index 0000000000000..3e2b957d7f29e
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/dbg-empty-metadata-lowering.ll
@@ -0,0 +1,49 @@
+; RUN: llc %s -stop-after=finalize-isel -o - | FileCheck %s --implicit-check-not=DBG
+
+;; Check that dbg.values with empty metadata are treated as kills (i.e. become
+;; DBG_VALUE $noreg, ...). dbg.declares with empty metadata location operands
+;; should be ignored.
+
+; CHECK: stack: []
+; CHECK: DBG_VALUE float 5.000000e+00
+; CHECK: @ext
+; CHECK: DBG_VALUE $noreg
+; CHECK: @ext
+
+target triple = "x86_64-unknown-linux-gnu"
+
+define dso_local void @fun() local_unnamed_addr #0 !dbg !9 {
+entry:
+ call void @llvm.dbg.declare(metadata !{}, metadata !20, metadata !DIExpression()), !dbg !15
+ call void @llvm.dbg.value(metadata float 5.000000e+00, metadata !13, metadata !DIExpression()), !dbg !15
+ tail call void @ext(), !dbg !16
+ call void @llvm.dbg.value(metadata !{}, metadata !13, metadata !DIExpression()), !dbg !15
+ tail call void @ext(), !dbg !16
+ ret void, !dbg !17
+}
+
+declare !dbg !18 void @ext() local_unnamed_addr
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3}
+!llvm.ident = !{!8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 16.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "test.cpp", directory: "/")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!8 = !{!"clang version 16.0.0"}
+!9 = distinct !DISubprogram(name: "fun", linkageName: "fun", scope: !1, file: !1, line: 2, type: !10, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)
+!10 = !DISubroutineType(types: !11)
+!11 = !{null}
+!12 = !{!13}
+!13 = !DILocalVariable(name: "f", scope: !9, file: !1, line: 3, type: !14)
+!14 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
+!15 = !DILocation(line: 0, scope: !9)
+!16 = !DILocation(line: 4, column: 3, scope: !9)
+!17 = !DILocation(line: 5, column: 1, scope: !9)
+!18 = !DISubprogram(name: "ext", linkageName: "ext", scope: !1, file: !1, line: 1, type: !10, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !19)
+!19 = !{}
+!20 = !DILocalVariable(name: "g", scope: !9, file: !1, line: 3, type: !14)
More information about the llvm-commits
mailing list