Skip to content

Commit 99420da

Browse files
[Backport] fixed discarding of debug info metadata by SPIRVLowerBool pass (#1418)
SPIRVLowerBool pass silently discards line information producing IR without !dbg nodes arrached. This commit addresses this issue and adds test
1 parent cf681c8 commit 99420da

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

lib/SPIRV/SPIRVLowerBool.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class SPIRVLowerBoolBase : public InstVisitor<SPIRVLowerBoolBase> {
5757
virtual ~SPIRVLowerBoolBase() {}
5858
void replace(Instruction *I, Instruction *NewI) {
5959
NewI->takeName(I);
60+
NewI->setDebugLoc(I->getDebugLoc());
6061
I->replaceAllUsesWith(NewI);
6162
I->dropAllReferences();
6263
I->eraseFromParent();
@@ -73,6 +74,7 @@ class SPIRVLowerBoolBase : public InstVisitor<SPIRVLowerBoolBase> {
7374
auto Op = I.getOperand(0);
7475
auto And = BinaryOperator::CreateAnd(
7576
Op, getScalarOrVectorConstantInt(Op->getType(), 1, false), "", &I);
77+
And->setDebugLoc(I.getDebugLoc());
7678
auto Zero = getScalarOrVectorConstantInt(Op->getType(), 0, false);
7779
auto Cmp = new ICmpInst(&I, CmpInst::ICMP_NE, And, Zero);
7880
replace(&I, Cmp);
@@ -102,6 +104,7 @@ class SPIRVLowerBoolBase : public InstVisitor<SPIRVLowerBoolBase> {
102104
auto One = getScalarOrVectorConstantInt(Ty, 1, false);
103105
assert(Zero && One && "Couldn't create constant int");
104106
auto Sel = SelectInst::Create(Op, One, Zero, "", &I);
107+
Sel->setDebugLoc(I.getDebugLoc());
105108
I.setOperand(0, Sel);
106109
}
107110
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
4+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s
5+
6+
source_filename = "the_file.ll"
7+
target triple = "spir64-unknown-unknown"
8+
9+
; Function Attrs: nounwind
10+
define spir_func i1 @trunc_to_i1(i32 %iarg) #0 !dbg !7 {
11+
; CHECK: @trunc_to_i1(i32 %iarg) #[[#]] !dbg ![[#]] {
12+
; CHECK-NEXT: !dbg ![[#TRUNC_LINE:]]
13+
; CHECK-NEXT: !dbg ![[#TRUNC_LINE]]
14+
; CHECK-NEXT: ret i1 %res, !dbg ![[#TRUNC_RET_LINE:]]
15+
%res = trunc i32 %iarg to i1, !dbg !9
16+
ret i1 %res, !dbg !10
17+
}
18+
19+
; Function Attrs: nounwind
20+
define spir_func i32 @sext_from_i1(i1 %barg) #0 !dbg !11 {
21+
; CHECK: @sext_from_i1(i1 %barg) #[[#]] !dbg ![[#]] {
22+
; CHECK-NEXT: !dbg ![[#SEXT_LINE:]]
23+
; CHECK: ret i32 %res, !dbg ![[#SEXT_RET_LINE:]]
24+
%res = sext i1 %barg to i32, !dbg !12
25+
ret i32 %res, !dbg !13
26+
}
27+
28+
; Function Attrs: nounwind
29+
define spir_func i32 @zext_from_i1(i1 %barg) #0 !dbg !14 {
30+
; CHECK: @zext_from_i1(i1 %barg) #[[#]] !dbg ![[#]] {
31+
; CHECK-NEXT: !dbg ![[#ZEXT_LINE:]]
32+
; CHECK: ret i32 %res, !dbg ![[#ZEXT_RET_LINE:]]
33+
%res = zext i1 %barg to i32, !dbg !15
34+
ret i32 %res, !dbg !16
35+
}
36+
37+
; Function Attrs: nounwind
38+
define spir_func float @sitofp_b(i1 %barg) #0 !dbg !17 {
39+
; CHECK: @sitofp_b(i1 %barg) #[[#]] !dbg ![[#]] {
40+
; CHECK-NEXT: !dbg ![[#SITOFP_LINE:]]
41+
; CHECK-NEXT: !dbg ![[#SITOFP_LINE]]
42+
; CHECK: ret float %res, !dbg ![[#SITOFP_RET_LINE:]]
43+
%res = sitofp i1 %barg to float, !dbg !18
44+
ret float %res, !dbg !19
45+
}
46+
47+
; Function Attrs: nounwind
48+
define spir_func float @uitofp_b(i1 %barg) #0 !dbg !20 {
49+
; CHECK: @uitofp_b(i1 %barg) #[[#]] !dbg ![[#]] {
50+
; CHECK-NEXT: !dbg ![[#UITOFP_LINE:]]
51+
; CHECK-NEXT: !dbg ![[#UITOFP_LINE]]
52+
; CHECK: ret float %res, !dbg ![[#UITOFP_RET_LINE:]]
53+
%res = uitofp i1 %barg to float, !dbg !21
54+
ret float %res, !dbg !22
55+
}
56+
57+
; CHECK-DAG: ![[#TRUNC_LINE]] = !DILocation(line: 1, column: 1
58+
; CHECK-DAG: ![[#TRUNC_RET_LINE]] = !DILocation(line: 2, column: 1
59+
60+
; CHECK-DAG: ![[#SEXT_LINE]] = !DILocation(line: 3, column: 1
61+
; CHECK-DAG: ![[#SEXT_RET_LINE]] = !DILocation(line: 4, column: 1
62+
63+
; CHECK-DAG: ![[#ZEXT_LINE]] = !DILocation(line: 5, column: 1
64+
; CHECK-DAG: ![[#ZEXT_RET_LINE]] = !DILocation(line: 6, column: 1
65+
66+
; CHECK-DAG: ![[#SITOFP_LINE]] = !DILocation(line: 7, column: 1
67+
; CHECK-DAG: ![[#SITOFP_RET_LINE]] = !DILocation(line: 8, column: 1
68+
69+
; CHECK-DAG: ![[#UITOFP_LINE]] = !DILocation(line: 9, column: 1
70+
; CHECK-DAG: ![[#UITOFP_RET_LINE]] = !DILocation(line: 10, column: 1
71+
72+
attributes #0 = { nounwind }
73+
74+
!llvm.dbg.cu = !{!2}
75+
!llvm.debugify = !{!4, !5}
76+
!llvm.module.flags = !{!6}
77+
78+
!0 = !{i32 1, i32 2}
79+
!1 = !{}
80+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
81+
!3 = !DIFile(filename: "the_file.ll", directory: "", checksumkind: CSK_MD5, checksum: "18aa9ce738eaafc7b7b7181c19092815")
82+
!4 = !{i32 10}
83+
!5 = !{i32 0}
84+
!6 = !{i32 2, !"Debug Info Version", i32 3}
85+
!7 = distinct !DISubprogram(name: "trunc_to_i1", scope: !3, file: !3, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !1)
86+
!8 = !DISubroutineType(types: !1)
87+
!9 = !DILocation(line: 1, column: 1, scope: !7)
88+
!10 = !DILocation(line: 2, column: 1, scope: !7)
89+
!11 = distinct !DISubprogram(name: "sext_from_i1", scope: !3, file: !3, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !1)
90+
!12 = !DILocation(line: 3, column: 1, scope: !11)
91+
!13 = !DILocation(line: 4, column: 1, scope: !11)
92+
!14 = distinct !DISubprogram(name: "zext_from_i1", scope: !3, file: !3, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped , spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !1)
93+
!15 = !DILocation(line: 5, column: 1, scope: !14)
94+
!16 = !DILocation(line: 6, column: 1, scope: !14)
95+
!17 = distinct !DISubprogram(name: "sitofp_b", scope: !3, file: !3, line: 7, type: !8, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !1)
96+
!18 = !DILocation(line: 7, column: 1, scope: !17)
97+
!19 = !DILocation(line: 8, column: 1, scope: !17)
98+
!20 = distinct !DISubprogram(name: "uitofp_b", scope: !3, file: !3, line: 9, type: !8, scopeLine: 9, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !1)
99+
!21 = !DILocation(line: 9, column: 1, scope: !20)
100+
!22 = !DILocation(line: 10, column: 1, scope: !20)

0 commit comments

Comments
 (0)