Skip to content

Commit f96da37

Browse files
apeskovIanWood1
authored andcommitted
[DEBUGINFO] Propagate debug metadata for sext SDNode. (llvm#135971)
In some cases of chained `sext` operators the debug metadata can be missed. This patch propagates proper metadata to resulting node. Particular case of issue is NVPTX codegen for function with bool local variable: ``` void test(int i) { bool xyz = i == 0; foo(i); } ``` --------- Signed-off-by: Alexander Peskov <[email protected]>
1 parent 38e98fa commit f96da37

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -6352,7 +6352,9 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
63526352
SDNodeFlags Flags;
63536353
if (OpOpcode == ISD::ZERO_EXTEND)
63546354
Flags.setNonNeg(N1->getFlags().hasNonNeg());
6355-
return getNode(OpOpcode, DL, VT, N1.getOperand(0), Flags);
6355+
SDValue NewVal = getNode(OpOpcode, DL, VT, N1.getOperand(0), Flags);
6356+
transferDbgValues(N1, NewVal);
6357+
return NewVal;
63566358
}
63576359

63586360
if (OpOpcode == ISD::POISON)
@@ -6376,7 +6378,10 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
63766378
if (OpOpcode == ISD::ZERO_EXTEND) { // (zext (zext x)) -> (zext x)
63776379
SDNodeFlags Flags;
63786380
Flags.setNonNeg(N1->getFlags().hasNonNeg());
6379-
return getNode(ISD::ZERO_EXTEND, DL, VT, N1.getOperand(0), Flags);
6381+
SDValue NewVal =
6382+
getNode(ISD::ZERO_EXTEND, DL, VT, N1.getOperand(0), Flags);
6383+
transferDbgValues(N1, NewVal);
6384+
return NewVal;
63806385
}
63816386

63826387
if (OpOpcode == ISD::POISON)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda -print-after=finalize-isel -o /dev/null 2>&1 | FileCheck %s
2+
3+
declare void @foo(i32)
4+
5+
define void @test1(i32 noundef %gid) !dbg !3 {
6+
entry:
7+
;
8+
; Equivalent of code:
9+
; extern void foo(int);
10+
; void test_kernel_bool(int a) {
11+
; bool xyz = a == 0;
12+
; foo(xyz);
13+
; }
14+
;
15+
; CHECK-LABEL: Machine code for function test1
16+
; CHECK: DBG_VALUE %[[#]]:int32regs, $noreg, !"xyz", !DIExpression(), debug-location ![[#]]; test.cu:2 line no:6
17+
;
18+
%cmp = icmp eq i32 %gid, 0, !dbg !12
19+
%conv = zext i1 %cmp to i32, !dbg !12
20+
%conv1 = trunc i32 %conv to i8, !dbg !12
21+
#dbg_value(i8 %conv1, !10, !DIExpression(), !13)
22+
%conv3 = sext i8 %conv1 to i32
23+
call void @foo(i32 %conv3)
24+
ret void
25+
}
26+
27+
define void @test2(i32 noundef %gid) !dbg !14 {
28+
entry:
29+
;
30+
; Equivalent of code:
31+
; extern void foo(int);
32+
; void test_kernel_bool(int a) {
33+
; unsigned char abc = a == 0;
34+
; foo(abc);
35+
; }
36+
;
37+
; CHECK-LABEL: Machine code for function test2
38+
; CHECK: DBG_VALUE %[[#]]:int32regs, $noreg, !"abc", !DIExpression(), debug-location ![[#]]; test.cu:12 line no:11
39+
;
40+
%cmp = icmp eq i32 %gid, 0, !dbg !17
41+
%conv = zext i1 %cmp to i32, !dbg !17
42+
%conv1 = trunc i32 %conv to i8, !dbg !17
43+
#dbg_value(i8 %conv1, !16, !DIExpression(), !18)
44+
%conv3 = zext i8 %conv1 to i32
45+
call void @foo(i32 %conv3)
46+
ret void
47+
}
48+
49+
!llvm.dbg.cu = !{!0}
50+
!llvm.module.flags = !{!2}
51+
52+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
53+
!1 = !DIFile(filename: "test.cu", directory: "/source/dir")
54+
!2 = !{i32 1, !"Debug Info Version", i32 3}
55+
!3 = distinct !DISubprogram(name: "test1", linkageName: "_test1i", scope: !1, file: !1, line: 5, type: !4, scopeLine: 5, unit: !0, retainedNodes: !8)
56+
!4 = !DISubroutineType(types: !5)
57+
!5 = !{!6, !7}
58+
!6 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "void")
59+
!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
60+
!8 = !{}
61+
!9 = distinct !DILexicalBlock(scope: !3, file: !1, line: 5, column: 30)
62+
!10 = !DILocalVariable(name: "xyz", scope: !9, file: !1, line: 6, type: !11)
63+
!11 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
64+
!12 = !DILocation(line: 1, column: 3, scope: !9)
65+
!13 = !DILocation(line: 2, scope: !9)
66+
!14 = distinct !DISubprogram(name: "test2", linkageName: "_test2i", scope: !1, file: !1, line: 10, type: !4, scopeLine: 10, unit: !0, retainedNodes: !8)
67+
!15 = distinct !DILexicalBlock(scope: !14, file: !1, line: 10, column: 30)
68+
!16 = !DILocalVariable(name: "abc", scope: !15, file: !1, line: 11, type: !11)
69+
!17 = !DILocation(line: 11, column: 3, scope: !15)
70+
!18 = !DILocation(line: 12, scope: !15)

0 commit comments

Comments
 (0)