Skip to content

Commit ee391ea

Browse files
aparshin-intelNikitaRudenkoIntel
authored andcommitted
fixed discarding of debug info metadata by SPIRVLowerBool pass
SPIRVLowerBool pass silently discards line information producing IR without !dbg nodes arrached. This commit addresses this issue and adds test
1 parent f797de2 commit ee391ea

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

lib/SPIRV/SPIRVLowerBool.cpp

+3
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
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
5+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s
6+
7+
source_filename = "/the_file.ll"
8+
target triple = "spir"
9+
10+
; Function Attrs: nounwind
11+
define spir_func i1 @trunc_to_i1(i32 %iarg) #0 !dbg !7 {
12+
; CHECK: @trunc_to_i1(i32 %iarg) #[[#]] !dbg ![[#]] {
13+
; CHECK-NEXT: !dbg ![[#TRUNC_LINE:]]
14+
; CHECK-NEXT: !dbg ![[#TRUNC_LINE]]
15+
; CHECK-NEXT: ret i1 %res, !dbg ![[#TRUNC_RET_LINE:]]
16+
%res = trunc i32 %iarg to i1, !dbg !9
17+
ret i1 %res, !dbg !10
18+
}
19+
20+
; Function Attrs: nounwind
21+
define spir_func i32 @sext_from_i1(i1 %barg) #0 !dbg !11 {
22+
; CHECK: @sext_from_i1(i1 %barg) #[[#]] !dbg ![[#]] {
23+
; CHECK-NEXT: !dbg ![[#SEXT_LINE:]]
24+
; CHECK: ret i32 %res, !dbg ![[#SEXT_RET_LINE:]]
25+
%res = sext i1 %barg to i32, !dbg !12
26+
ret i32 %res, !dbg !13
27+
}
28+
29+
; Function Attrs: nounwind
30+
define spir_func i32 @zext_from_i1(i1 %barg) #0 !dbg !14 {
31+
; CHECK: @zext_from_i1(i1 %barg) #[[#]] !dbg ![[#]] {
32+
; CHECK-NEXT: !dbg ![[#ZEXT_LINE:]]
33+
; CHECK: ret i32 %res, !dbg ![[#ZEXT_RET_LINE:]]
34+
%res = zext i1 %barg to i32, !dbg !15
35+
ret i32 %res, !dbg !16
36+
}
37+
38+
; Function Attrs: nounwind
39+
define spir_func float @sitofp_b(i1 %barg) #0 !dbg !17 {
40+
; CHECK: @sitofp_b(i1 %barg) #[[#]] !dbg ![[#]] {
41+
; CHECK-NEXT: !dbg ![[#SITOFP_LINE:]]
42+
; CHECK-NEXT: !dbg ![[#SITOFP_LINE]]
43+
; CHECK: ret float %res, !dbg ![[#SITOFP_RET_LINE:]]
44+
%res = sitofp i1 %barg to float, !dbg !18
45+
ret float %res, !dbg !19
46+
}
47+
48+
; Function Attrs: nounwind
49+
define spir_func float @uitofp_b(i1 %barg) #0 !dbg !20 {
50+
; CHECK: @uitofp_b(i1 %barg) #[[#]] !dbg ![[#]] {
51+
; CHECK-NEXT: !dbg ![[#UITOFP_LINE:]]
52+
; CHECK-NEXT: !dbg ![[#UITOFP_LINE]]
53+
; CHECK: ret float %res, !dbg ![[#UITOFP_RET_LINE:]]
54+
%res = uitofp i1 %barg to float, !dbg !21
55+
ret float %res, !dbg !22
56+
}
57+
58+
; CHECK-DAG: ![[#TRUNC_LINE]] = !DILocation(line: 1, column: 1
59+
; CHECK-DAG: ![[#TRUNC_RET_LINE]] = !DILocation(line: 2, column: 1
60+
61+
; CHECK-DAG: ![[#SEXT_LINE]] = !DILocation(line: 3, column: 1
62+
; CHECK-DAG: ![[#SEXT_RET_LINE]] = !DILocation(line: 4, column: 1
63+
64+
; CHECK-DAG: ![[#ZEXT_LINE]] = !DILocation(line: 5, column: 1
65+
; CHECK-DAG: ![[#ZEXT_RET_LINE]] = !DILocation(line: 6, column: 1
66+
67+
; CHECK-DAG: ![[#SITOFP_LINE]] = !DILocation(line: 7, column: 1
68+
; CHECK-DAG: ![[#SITOFP_RET_LINE]] = !DILocation(line: 8, column: 1
69+
70+
; CHECK-DAG: ![[#UITOFP_LINE]] = !DILocation(line: 9, column: 1
71+
; CHECK-DAG: ![[#UITOFP_RET_LINE]] = !DILocation(line: 10, column: 1
72+
73+
attributes #0 = { nounwind }
74+
75+
!opencl.enable.FP_CONTRACT = !{}
76+
!opencl.spir.version = !{!0}
77+
!opencl.ocl.version = !{!0}
78+
!opencl.used.extensions = !{!1}
79+
!opencl.used.optional.core.features = !{!1}
80+
!opencl.compiler.options = !{!1}
81+
!llvm.dbg.cu = !{!2}
82+
!llvm.debugify = !{!4, !5}
83+
!llvm.module.flags = !{!6}
84+
85+
!0 = !{i32 1, i32 2}
86+
!1 = !{}
87+
!2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
88+
!3 = !DIFile(filename: "/the_file.ll", directory: "/")
89+
!4 = !{i32 10}
90+
!5 = !{i32 0}
91+
!6 = !{i32 2, !"Debug Info Version", i32 3}
92+
!7 = distinct !DISubprogram(name: "trunc_to_i1", linkageName: "trunc_to_i1", scope: null, file: !3, line: 1, type: !8, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !1)
93+
!8 = !DISubroutineType(types: !1)
94+
!9 = !DILocation(line: 1, column: 1, scope: !7)
95+
!10 = !DILocation(line: 2, column: 1, scope: !7)
96+
!11 = distinct !DISubprogram(name: "sext_from_i1", linkageName: "sext_from_i1", scope: null, file: !3, line: 3, type: !8, scopeLine: 3, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !1)
97+
!12 = !DILocation(line: 3, column: 1, scope: !11)
98+
!13 = !DILocation(line: 4, column: 1, scope: !11)
99+
!14 = distinct !DISubprogram(name: "zext_from_i1", linkageName: "zext_from_i1", scope: null, file: !3, line: 5, type: !8, scopeLine: 5, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !1)
100+
!15 = !DILocation(line: 5, column: 1, scope: !14)
101+
!16 = !DILocation(line: 6, column: 1, scope: !14)
102+
!17 = distinct !DISubprogram(name: "sitofp_b", linkageName: "sitofp_b", scope: null, file: !3, line: 7, type: !8, scopeLine: 7, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !1)
103+
!18 = !DILocation(line: 7, column: 1, scope: !17)
104+
!19 = !DILocation(line: 8, column: 1, scope: !17)
105+
!20 = distinct !DISubprogram(name: "uitofp_b", linkageName: "uitofp_b", scope: null, file: !3, line: 9, type: !8, scopeLine: 9, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !1)
106+
!21 = !DILocation(line: 9, column: 1, scope: !20)
107+
!22 = !DILocation(line: 10, column: 1, scope: !20)

0 commit comments

Comments
 (0)