[llvm] [DEBUGINFO] Propagate debug metadata for sext SDNode. (PR #135971)
Alexander Peskov via llvm-commits
llvm-commits at lists.llvm.org
Fri May 2 03:30:30 PDT 2025
https://github.com/apeskov updated https://github.com/llvm/llvm-project/pull/135971
>From d5670ff0c3d39949ad1ed54bb03055f044c9211a Mon Sep 17 00:00:00 2001
From: Alexander Peskov <apeskov at nvidia.com>
Date: Mon, 14 Apr 2025 20:28:13 +0400
Subject: [PATCH 1/6] [DEBUGINFO] Fix missed debug info for bool local var
During type promotion debug info is messed for bool vars.
---
.../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 4 +-
llvm/test/DebugInfo/NVPTX/debug-bool-var.ll | 43 +++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index d9d6d43c42430..b4a4eae491638 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6352,7 +6352,9 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
SDNodeFlags Flags;
if (OpOpcode == ISD::ZERO_EXTEND)
Flags.setNonNeg(N1->getFlags().hasNonNeg());
- return getNode(OpOpcode, DL, VT, N1.getOperand(0), Flags);
+ SDValue NewVal = getNode(OpOpcode, DL, VT, N1.getOperand(0), Flags);
+ transferDbgValues(N1, NewVal);
+ return NewVal;
}
if (OpOpcode == ISD::POISON)
diff --git a/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll b/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
new file mode 100644
index 0000000000000..7e50f1ea18fea
--- /dev/null
+++ b/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
@@ -0,0 +1,43 @@
+; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda | FileCheck %s
+
+declare void @foo(i32)
+
+define void @test1(i32 noundef %gid) !dbg !3 {
+entry:
+ ;
+ ; verify that debug info exists for "xyz" variable
+ ;
+ ; CHECK-LABEL: DW_TAG_variable
+ ; CHECK: .b8 120 // DW_AT_name
+ ; CHECK-NEXT: .b8 121
+ ; CHECK-NEXT: .b8 122
+ ; CHECK-NEXT: .b8 0
+ ; CHECK-NEXT: .b8 1 // DW_AT_decl_file
+ ; CHECK-NEXT: .b8 6 // DW_AT_decl_line
+ ;
+ %cmp = icmp eq i32 %gid, 0, !dbg !12
+ %conv = zext i1 %cmp to i32, !dbg !12
+ %conv1 = trunc i32 %conv to i8, !dbg !12
+ #dbg_value(i8 %conv1, !10, !DIExpression(), !13)
+ %conv3 = sext i8 %conv1 to i32
+ call void @foo(i32 %conv3)
+ ret void
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "test.cu", directory: "/source/dir")
+!2 = !{i32 1, !"Debug Info Version", i32 3}
+!3 = distinct !DISubprogram(name: "test1", linkageName: "_test1i", scope: !1, file: !1, line: 5, type: !4, scopeLine: 5, unit: !0, retainedNodes: !8)
+!4 = !DISubroutineType(types: !5)
+!5 = !{!6, !7}
+!6 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "void")
+!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!8 = !{}
+!9 = distinct !DILexicalBlock(scope: !3, file: !1, line: 5, column: 30)
+!10 = !DILocalVariable(name: "xyz", scope: !9, file: !1, line: 6, type: !11)
+!11 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
+!12 = !DILocation(line: 1, column: 3, scope: !9)
+!13 = !DILocation(line: 2, scope: !9)
>From eb8da2aee2ad67ed4432f35a716a599c4259f73a Mon Sep 17 00:00:00 2001
From: Alexander Peskov <apeskov at nvidia.com>
Date: Thu, 17 Apr 2025 16:46:15 +0400
Subject: [PATCH 2/6] Plus zext-zext case
Signed-off-by: Alexander Peskov <apeskov at nvidia.com>
---
.../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 4 +-
llvm/test/DebugInfo/NVPTX/debug-bool-var.ll | 45 ++++++++++++++++++-
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index b4a4eae491638..de022823b71da 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6378,7 +6378,9 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
if (OpOpcode == ISD::ZERO_EXTEND) { // (zext (zext x)) -> (zext x)
SDNodeFlags Flags;
Flags.setNonNeg(N1->getFlags().hasNonNeg());
- return getNode(ISD::ZERO_EXTEND, DL, VT, N1.getOperand(0), Flags);
+ SDValue NewVal = getNode(ISD::ZERO_EXTEND, DL, VT, N1.getOperand(0), Flags);
+ transferDbgValues(N1, NewVal);
+ return NewVal;
}
if (OpOpcode == ISD::POISON)
diff --git a/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll b/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
index 7e50f1ea18fea..02f68efbaa3b6 100644
--- a/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
+++ b/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
@@ -5,9 +5,16 @@ declare void @foo(i32)
define void @test1(i32 noundef %gid) !dbg !3 {
entry:
;
- ; verify that debug info exists for "xyz" variable
+ ; Equivalent of code:
+ ; extern void foo(int);
+ ; void test_kernel_bool(int a) {
+ ; bool xyz = a == 0;
+ ; foo(xyz);
+ ; }
;
- ; CHECK-LABEL: DW_TAG_variable
+ ; Verify that debug info exists for "xyz" variable
+ ;
+ ; CHECK: DW_TAG_variable
; CHECK: .b8 120 // DW_AT_name
; CHECK-NEXT: .b8 121
; CHECK-NEXT: .b8 122
@@ -24,6 +31,35 @@ entry:
ret void
}
+define void @test2(i32 noundef %gid) !dbg !14 {
+entry:
+ ;
+ ; Equivalent of code:
+ ; extern void foo(int);
+ ; void test_kernel_bool(int a) {
+ ; unsigned char abc = a == 0;
+ ; foo(abc);
+ ; }
+ ;
+ ; Verify that debug info exists for "abc" variable
+ ;
+ ; CHECK: DW_TAG_variable
+ ; CHECK: .b8 97 // DW_AT_name
+ ; CHECK-NEXT: .b8 98
+ ; CHECK-NEXT: .b8 99
+ ; CHECK-NEXT: .b8 0
+ ; CHECK-NEXT: .b8 1 // DW_AT_decl_file
+ ; CHECK-NEXT: .b8 11 // DW_AT_decl_line
+ ;
+ %cmp = icmp eq i32 %gid, 0, !dbg !17
+ %conv = zext i1 %cmp to i32, !dbg !17
+ %conv1 = trunc i32 %conv to i8, !dbg !17
+ #dbg_value(i8 %conv1, !16, !DIExpression(), !18)
+ %conv3 = zext i8 %conv1 to i32
+ call void @foo(i32 %conv3)
+ ret void
+}
+
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2}
@@ -41,3 +77,8 @@ entry:
!11 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
!12 = !DILocation(line: 1, column: 3, scope: !9)
!13 = !DILocation(line: 2, scope: !9)
+!14 = distinct !DISubprogram(name: "test2", linkageName: "_test2i", scope: !1, file: !1, line: 10, type: !4, scopeLine: 10, unit: !0, retainedNodes: !8)
+!15 = distinct !DILexicalBlock(scope: !14, file: !1, line: 10, column: 30)
+!16 = !DILocalVariable(name: "abc", scope: !15, file: !1, line: 11, type: !11)
+!17 = !DILocation(line: 11, column: 3, scope: !15)
+!18 = !DILocation(line: 12, scope: !15)
\ No newline at end of file
>From a6e9bbf05d23bb5d7f8a658a97bb6b52951c2f64 Mon Sep 17 00:00:00 2001
From: Alexander Peskov <apeskov at nvidia.com>
Date: Thu, 17 Apr 2025 16:59:00 +0400
Subject: [PATCH 3/6] fix lint
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index de022823b71da..2a68903c34cef 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6378,7 +6378,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
if (OpOpcode == ISD::ZERO_EXTEND) { // (zext (zext x)) -> (zext x)
SDNodeFlags Flags;
Flags.setNonNeg(N1->getFlags().hasNonNeg());
- SDValue NewVal = getNode(ISD::ZERO_EXTEND, DL, VT, N1.getOperand(0), Flags);
+ SDValue NewVal =
+ getNode(ISD::ZERO_EXTEND, DL, VT, N1.getOperand(0), Flags);
transferDbgValues(N1, NewVal);
return NewVal;
}
>From 72932c8fafbeb7f786f5026bcb49509fc9354e93 Mon Sep 17 00:00:00 2001
From: Alexander Peskov <apeskov at nvidia.com>
Date: Thu, 17 Apr 2025 17:02:12 +0400
Subject: [PATCH 4/6] minor
---
llvm/test/DebugInfo/NVPTX/debug-bool-var.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll b/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
index 02f68efbaa3b6..c878ea1056346 100644
--- a/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
+++ b/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
@@ -81,4 +81,4 @@ entry:
!15 = distinct !DILexicalBlock(scope: !14, file: !1, line: 10, column: 30)
!16 = !DILocalVariable(name: "abc", scope: !15, file: !1, line: 11, type: !11)
!17 = !DILocation(line: 11, column: 3, scope: !15)
-!18 = !DILocation(line: 12, scope: !15)
\ No newline at end of file
+!18 = !DILocation(line: 12, scope: !15)
>From d61d11833be55c7be3c2068094bebe64f0455f9e Mon Sep 17 00:00:00 2001
From: Alexander Peskov <apeskov at nvidia.com>
Date: Wed, 30 Apr 2025 18:06:52 +0400
Subject: [PATCH 5/6] reword test with -print-after=finalize-isel
---
llvm/test/DebugInfo/NVPTX/debug-bool-var.ll | 24 +++++----------------
1 file changed, 5 insertions(+), 19 deletions(-)
diff --git a/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll b/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
index c878ea1056346..51b3fcae95658 100644
--- a/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
+++ b/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
@@ -1,4 +1,4 @@
-; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda | FileCheck %s
+; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda -print-after=finalize-isel -o /dev/null 2>&1 | FileCheck %s
declare void @foo(i32)
@@ -12,15 +12,8 @@ entry:
; foo(xyz);
; }
;
- ; Verify that debug info exists for "xyz" variable
- ;
- ; CHECK: DW_TAG_variable
- ; CHECK: .b8 120 // DW_AT_name
- ; CHECK-NEXT: .b8 121
- ; CHECK-NEXT: .b8 122
- ; CHECK-NEXT: .b8 0
- ; CHECK-NEXT: .b8 1 // DW_AT_decl_file
- ; CHECK-NEXT: .b8 6 // DW_AT_decl_line
+ ; CHECK-LABEL: Machine code for function test1
+ ; CHECK: DBG_VALUE %{{[0-9]+}}:int32regs, $noreg, !"xyz", !DIExpression(), debug-location !13; test.cu:2 line no:6
;
%cmp = icmp eq i32 %gid, 0, !dbg !12
%conv = zext i1 %cmp to i32, !dbg !12
@@ -41,15 +34,8 @@ entry:
; foo(abc);
; }
;
- ; Verify that debug info exists for "abc" variable
- ;
- ; CHECK: DW_TAG_variable
- ; CHECK: .b8 97 // DW_AT_name
- ; CHECK-NEXT: .b8 98
- ; CHECK-NEXT: .b8 99
- ; CHECK-NEXT: .b8 0
- ; CHECK-NEXT: .b8 1 // DW_AT_decl_file
- ; CHECK-NEXT: .b8 11 // DW_AT_decl_line
+ ; CHECK-LABEL: Machine code for function test2
+ ; CHECK: DBG_VALUE %{{[0-9]+}}:int32regs, $noreg, !"abc", !DIExpression(), debug-location !18; test.cu:12 line no:11
;
%cmp = icmp eq i32 %gid, 0, !dbg !17
%conv = zext i1 %cmp to i32, !dbg !17
>From e3adc2b0cfb55d865c2c54e778eb82d12d7c615d Mon Sep 17 00:00:00 2001
From: Alexander Peskov <apeskov at nvidia.com>
Date: Fri, 2 May 2025 14:03:37 +0400
Subject: [PATCH 6/6] min
---
llvm/test/DebugInfo/NVPTX/debug-bool-var.ll | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll b/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
index 51b3fcae95658..7a42268650c63 100644
--- a/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
+++ b/llvm/test/DebugInfo/NVPTX/debug-bool-var.ll
@@ -13,7 +13,7 @@ entry:
; }
;
; CHECK-LABEL: Machine code for function test1
- ; CHECK: DBG_VALUE %{{[0-9]+}}:int32regs, $noreg, !"xyz", !DIExpression(), debug-location !13; test.cu:2 line no:6
+ ; CHECK: DBG_VALUE %[[#]]:int32regs, $noreg, !"xyz", !DIExpression(), debug-location ![[#]]; test.cu:2 line no:6
;
%cmp = icmp eq i32 %gid, 0, !dbg !12
%conv = zext i1 %cmp to i32, !dbg !12
@@ -35,7 +35,7 @@ entry:
; }
;
; CHECK-LABEL: Machine code for function test2
- ; CHECK: DBG_VALUE %{{[0-9]+}}:int32regs, $noreg, !"abc", !DIExpression(), debug-location !18; test.cu:12 line no:11
+ ; CHECK: DBG_VALUE %[[#]]:int32regs, $noreg, !"abc", !DIExpression(), debug-location ![[#]]; test.cu:12 line no:11
;
%cmp = icmp eq i32 %gid, 0, !dbg !17
%conv = zext i1 %cmp to i32, !dbg !17
More information about the llvm-commits
mailing list