Skip to content

Commit 95bfba6

Browse files
authored
[SYCL] Check debug information integrity in the LowerWGScope pass (#3411)
* Add tests for debug info integrity * Fix pass to skip debug intrinsics when processing the instructions.
1 parent fc30f04 commit 95bfba6

File tree

4 files changed

+178
-1
lines changed

4 files changed

+178
-1
lines changed

llvm/lib/SYCLLowerIR/LowerWGScope.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,8 @@ PreservedAnalyses SYCLLowerWGScopePass::run(Function &F,
786786
Instruction *I = BB.getFirstNonPHI();
787787

788788
for (; I->getOpcode() == Instruction::Alloca ||
789-
I->getOpcode() == Instruction::AddrSpaceCast;
789+
I->getOpcode() == Instruction::AddrSpaceCast ||
790+
I->isDebugOrPseudoInst();
790791
I = I->getNextNode()) {
791792
auto *AllocaI = dyn_cast<AllocaInst>(I);
792793
// Allocas marked with "work_item_scope" are those originating from
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; RUN: opt < %s -debugify -LowerWGScope -S | FileCheck %s
2+
3+
; Check that debug info is not lost after the LowerWGScope pass.
4+
; Typical case of pfwg + pfwi usage.
5+
6+
%struct.bar = type { i8 }
7+
%struct.zot = type { %struct.widget, %struct.widget, %struct.widget, %struct.foo }
8+
%struct.widget = type { %struct.barney }
9+
%struct.barney = type { [3 x i64] }
10+
%struct.foo = type { %struct.barney }
11+
%struct.foo.0 = type { i8 }
12+
13+
define internal spir_func void @wibble(%struct.bar addrspace(4)* %arg, %struct.zot* byval(%struct.zot) align 8 %arg1) align 2 !work_group_scope !0 {
14+
; CHECK-LABEL: define {{[^@]+}}@wibble
15+
; CHECK-SAME: (%struct.bar addrspace(4)* [[ARG:%.*]], %struct.zot* byval(%struct.zot) align 8 [[ARG1:%.*]])
16+
bb:
17+
%tmp = alloca %struct.bar addrspace(4)*, align 8
18+
; CHECK: [[TMP:%.*]] = alloca %struct.bar addrspace(4)*, align 8
19+
; CHECK: call void @llvm.dbg.value(metadata %struct.bar addrspace(4)** [[TMP]], [[META9:metadata !.*]], metadata !DIExpression())
20+
%tmp1 = alloca %struct.foo.0, align 1
21+
; CHECK: [[TMP1:%.*]] = alloca %struct.foo.0, align 1
22+
; CHECK: call void @llvm.dbg.value(metadata %struct.foo.0* [[TMP1]], [[META11:metadata !.*]], metadata !DIExpression())
23+
store %struct.bar addrspace(4)* %arg, %struct.bar addrspace(4)** %tmp, align 8
24+
%tmp3 = load %struct.bar addrspace(4)*, %struct.bar addrspace(4)** %tmp, align 8
25+
; CHECK: [[TMP3:%.*]] = load %struct.bar addrspace(4)*, %struct.bar addrspace(4)** [[TMP]], align 8
26+
; CHECK: call void @llvm.dbg.value(metadata %struct.bar addrspace(4)* [[TMP3]], [[META12:metadata !.*]], metadata !DIExpression())
27+
%tmp4 = addrspacecast %struct.zot* %arg1 to %struct.zot addrspace(4)*
28+
; CHECK: [[TMP4:%.*]] = addrspacecast %struct.zot* [[ARG1]] to %struct.zot addrspace(4)*
29+
; CHECK: call void @llvm.dbg.value(metadata %struct.zot addrspace(4)* [[TMP4]], [[META13:metadata !.*]], metadata !DIExpression())
30+
call spir_func void @bar(%struct.zot addrspace(4)* %tmp4, %struct.foo.0* byval(%struct.foo.0) align 1 %tmp1)
31+
ret void
32+
}
33+
34+
define internal spir_func void @bar(%struct.zot addrspace(4)* %arg, %struct.foo.0* byval(%struct.foo.0) align 1 %arg1) align 2 !work_item_scope !0 !parallel_for_work_item !0 {
35+
; CHECK-LABEL: define {{[^@]+}}@bar
36+
; CHECK: call void @llvm.dbg.value(metadata i32 0, [[META23:metadata !.*]], metadata !DIExpression())
37+
bb:
38+
ret void
39+
}
40+
41+
!0 = !{}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
; RUN: opt < %s -debugify -LowerWGScope -S | FileCheck %s
2+
;
3+
; Check that debug info is not lost after LowerWGScope pass.
4+
; Case with private_mem usage.
5+
6+
%struct.snork = type { i8 }
7+
%struct.wobble = type { %struct.spam, %struct.spam, %struct.spam, %struct.snork.0 }
8+
%struct.spam = type { %struct.foo }
9+
%struct.foo = type { [2 x i64] }
10+
%struct.snork.0 = type { %struct.foo }
11+
%struct.ham = type { %struct.pluto }
12+
%struct.pluto = type { i32, i32 }
13+
%struct.wibble = type { %struct.ham addrspace(4)* }
14+
15+
define internal spir_func void @wibble(%struct.snork addrspace(4)* dereferenceable_or_null(1) %arg, %struct.wobble* byval(%struct.wobble) align 8 %arg1) align 2 !work_group_scope !0 {
16+
; CHECK-LABEL: define {{[^@]+}}@wibble
17+
; CHECK-SAME: (%struct.snork addrspace(4)* dereferenceable_or_null(1) [[ARG:%.*]], %struct.wobble* byval(%struct.wobble) align 8 [[ARG1:%.*]])
18+
;
19+
bb:
20+
%tmp = alloca %struct.snork addrspace(4)*, align 8
21+
; CHECK: [[TMP:%.*]] = alloca %struct.snork addrspace(4)*, align 8
22+
; CHECK: call void @llvm.dbg.value(metadata %struct.snork addrspace(4)** [[TMP]], [[META9:metadata !.*]], metadata !DIExpression())
23+
%tmp2 = addrspacecast %struct.snork addrspace(4)** %tmp to %struct.snork addrspace(4)* addrspace(4)*
24+
; CHECK: [[TMP2:%.*]] = addrspacecast %struct.snork addrspace(4)** [[TMP]] to %struct.snork addrspace(4)* addrspace(4)*
25+
; CHECK: call void @llvm.dbg.value(metadata %struct.snork addrspace(4)* addrspace(4)* [[TMP2]], [[META11:metadata !.*]], metadata !DIExpression())
26+
%tmp3 = alloca %struct.ham, align 4, !work_item_scope !0
27+
; CHECK: [[TMP3:%.*]] = alloca %struct.ham, align 4, [[DBG24:!dbg !.*]], !work_item_scope !2
28+
; CHECK: call void @llvm.dbg.value(metadata %struct.ham* [[TMP3]], [[META12:metadata !.*]], metadata !DIExpression())
29+
%tmp4 = addrspacecast %struct.ham* %tmp3 to %struct.ham addrspace(4)*
30+
; CHECK: [[TMP4:%.*]] = addrspacecast %struct.ham* [[TMP3]] to %struct.ham addrspace(4)*
31+
; CHECK: call void @llvm.dbg.value(metadata %struct.ham addrspace(4)* [[TMP4]], [[META13:metadata !.*]], metadata !DIExpression())
32+
%tmp5 = alloca %struct.spam, align 8
33+
; CHECK: [[TMP5:%.*]] = alloca %struct.spam, align 8
34+
; CHECK: call void @llvm.dbg.value(metadata %struct.spam* [[TMP5]], [[META14:metadata !.*]], metadata !DIExpression())
35+
%tmp6 = addrspacecast %struct.spam* %tmp5 to %struct.spam addrspace(4)*
36+
; CHECK: [[TMP6:%.*]] = addrspacecast %struct.spam* [[TMP5]] to %struct.spam addrspace(4)*
37+
; CHECK: call void @llvm.dbg.value(metadata %struct.spam addrspace(4)* [[TMP6]], [[META15:metadata !.*]], metadata !DIExpression())
38+
%tmp7 = alloca %struct.wibble, align 8
39+
; CHECK: [[TMP7:%.*]] = alloca %struct.wibble, align 8
40+
; CHECK: call void @llvm.dbg.value(metadata %struct.wibble* [[TMP7]], [[META16:metadata !.*]], metadata !DIExpression())
41+
%tmp8 = addrspacecast %struct.wibble* %tmp7 to %struct.wibble addrspace(4)*
42+
; CHECK: [[TMP8:%.*]] = addrspacecast %struct.wibble* [[TMP7]] to %struct.wibble addrspace(4)*
43+
; CHECK: call void @llvm.dbg.value(metadata %struct.wibble addrspace(4)* [[TMP8]], [[META17:metadata !.*]], metadata !DIExpression())
44+
store %struct.snork addrspace(4)* %arg, %struct.snork addrspace(4)* addrspace(4)* %tmp2, align 8
45+
%tmp9 = addrspacecast %struct.wobble* %arg1 to %struct.wobble addrspace(4)*
46+
; CHECK: [[TMP9:%.*]] = addrspacecast %struct.wobble* [[ARG1]] to %struct.wobble addrspace(4)*
47+
; CHECK: call void @llvm.dbg.value(metadata %struct.wobble addrspace(4)* [[TMP9]], [[META18:metadata !.*]], metadata !DIExpression())
48+
call spir_func void @eggs(%struct.ham addrspace(4)* dereferenceable_or_null(8) %tmp4, %struct.wobble addrspace(4)* align 8 dereferenceable(64) %tmp9)
49+
call spir_func void @snork(%struct.spam addrspace(4)* dereferenceable_or_null(16) %tmp6, i64 7, i64 3)
50+
%tmp10 = getelementptr inbounds %struct.wibble, %struct.wibble addrspace(4)* %tmp8, i32 0, i32 0
51+
; CHECK: [[TMP10:%.*]] = getelementptr inbounds %struct.wibble, %struct.wibble addrspace(4)* [[TMP8]], i32 0, i32 0
52+
; CHECK: call void @llvm.dbg.value(metadata %struct.ham addrspace(4)* addrspace(4)* [[TMP10]], [[META19:metadata !.*]], metadata !DIExpression())
53+
store %struct.ham addrspace(4)* %tmp4, %struct.ham addrspace(4)* addrspace(4)* %tmp10, align 8
54+
%tmp11 = addrspacecast %struct.spam addrspace(4)* %tmp6 to %struct.spam*
55+
; CHECK: [[TMP11:%.*]] = addrspacecast %struct.spam addrspace(4)* [[TMP6]] to %struct.spam*
56+
; CHECK: call void @llvm.dbg.value(metadata %struct.spam* [[TMP11]], [[META20:metadata !.*]], metadata !DIExpression())
57+
%tmp12 = addrspacecast %struct.wibble addrspace(4)* %tmp8 to %struct.wibble*
58+
call spir_func void @wombat(%struct.wobble addrspace(4)* dereferenceable_or_null(64) %tmp9, %struct.spam* byval(%struct.spam) align 8 %tmp11, %struct.wibble* byval(%struct.wibble) align 8 %tmp12)
59+
; CHECK: [[TMP12:%.*]] = addrspacecast %struct.wibble addrspace(4)* [[TMP8]] to %struct.wibble*
60+
; CHECK: call void @llvm.dbg.value(metadata %struct.wibble* [[TMP12]], [[META21:metadata !.*]], metadata !DIExpression())
61+
ret void
62+
}
63+
64+
define linkonce_odr dso_local spir_func void @eggs(%struct.ham addrspace(4)* dereferenceable_or_null(8) %arg, %struct.wobble addrspace(4)* align 8 dereferenceable(64) %arg1) align 2 {
65+
bb:
66+
ret void
67+
}
68+
69+
define internal spir_func void @wombat(%struct.wobble addrspace(4)* dereferenceable_or_null(64) %arg, %struct.spam* byval(%struct.spam) align 8 %arg1, %struct.wibble* byval(%struct.wibble) align 8 %arg2) align 2 !work_item_scope !0 !parallel_for_work_item !0 {
70+
bb:
71+
; CHECK: call void @llvm.dbg.value(metadata i32 0, [[META42:metadata !.*]], metadata !DIExpression())
72+
ret void
73+
}
74+
75+
define linkonce_odr dso_local spir_func void @snork(%struct.spam addrspace(4)* dereferenceable_or_null(16) %arg, i64 %arg1, i64 %arg2) align 2 {
76+
bb:
77+
ret void
78+
}
79+
80+
!0 = !{}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
; RUN: opt < %s -debugify -LowerWGScope -S | FileCheck %s
2+
;
3+
; Check that debug info is not lost after the LowerWGScope pass.
4+
; Case with additional control flow in pfwg.
5+
6+
7+
%struct.snork = type { i32 }
8+
%struct.eggs = type { i8 }
9+
%struct.snork.0 = type { %struct.widget, %struct.widget, %struct.widget, %struct.ham }
10+
%struct.widget = type { %struct.wibble }
11+
%struct.wibble = type { [3 x i64] }
12+
%struct.ham = type { %struct.wibble }
13+
14+
@global = internal addrspace(3) global [12 x %struct.snork] zeroinitializer, align 4
15+
16+
define internal spir_func void @spam(%struct.eggs addrspace(4)* %arg, %struct.snork.0* byval(%struct.snork.0) align 8 %arg1) align 2 !work_group_scope !0 {
17+
; CHECK-LABEL: define {{[^@]+}}@spam
18+
; CHECK-SAME: (%struct.eggs addrspace(4)* [[ARG:%.*]], %struct.snork.0* byval(%struct.snork.0) align 8 [[ARG1:%.*]])
19+
entry:
20+
%tmp = alloca %struct.eggs addrspace(4)*, align 8
21+
; CHECK: [[TMP:%.*]] = alloca %struct.eggs addrspace(4)*, align 8
22+
; CHECK: call void @llvm.dbg.value(metadata %struct.eggs addrspace(4)** [[TMP]], [[META9:metadata !.*]], metadata !DIExpression())
23+
store %struct.eggs addrspace(4)* %arg, %struct.eggs addrspace(4)** %tmp, align 8
24+
%tmp2 = load %struct.eggs addrspace(4)*, %struct.eggs addrspace(4)** %tmp, align 8
25+
; CHECK: [[TMP2:%.*]] = load %struct.eggs addrspace(4)*, %struct.eggs addrspace(4)** [[TMP]], align 8
26+
; CHECK: call void @llvm.dbg.value(metadata %struct.eggs addrspace(4)* [[TMP2]], [[META11:metadata !.*]], metadata !DIExpression())
27+
br label %arrayctor.loop
28+
arrayctor.loop: ; preds = %arrayctor.loop, %entry
29+
%arrayctor.cur = phi %struct.snork addrspace(4)* [ getelementptr inbounds ([12 x %struct.snork], [12 x %struct.snork] addrspace(4)* addrspacecast ([12 x %struct.snork] addrspace(3)* @global to [12 x %struct.snork] addrspace(4)*), i32 0, i32 0), %entry ], [ %arrayctor.next, %arrayctor.loop ]
30+
; CHECK: [[ARRAYCTOR_CUR:%.*]] = phi [[STRUCT_SNORK:%.*]] addrspace(4)* [ getelementptr inbounds ([12 x %struct.snork], [12 x %struct.snork] addrspace(4)* addrspacecast ([12 x %struct.snork] addrspace(3)* @global to [12 x %struct.snork] addrspace(4)*), i32 0, i32 0), [[ENTRY:%.*]] ], [ [[ARRAYCTOR_NEXT:%.*]], [[ARRAYCTOR_LOOP:%.*]] ]
31+
; CHECK: call void @llvm.dbg.value(metadata %struct.snork addrspace(4)* [[ARRAYCTOR_CUR]], [[META12:metadata !.*]], metadata !DIExpression())
32+
call spir_func void @bar(%struct.snork addrspace(4)* %arrayctor.cur)
33+
%arrayctor.next = getelementptr inbounds %struct.snork, %struct.snork addrspace(4)* %arrayctor.cur, i64 1
34+
; CHECK: [[GEP_VAL:%.*]] = getelementptr inbounds %struct.snork, %struct.snork addrspace(4)* [[ARRAYCTOR_CUR]], i64 1
35+
; CHECK: call void @llvm.dbg.value(metadata %struct.snork addrspace(4)* [[GEP_VAL]], [[META13:metadata !.*]], metadata !DIExpression())
36+
%arrayctor.done = icmp eq %struct.snork addrspace(4)* %arrayctor.next, getelementptr inbounds (%struct.snork, %struct.snork addrspace(4)* getelementptr inbounds ([12 x %struct.snork], [12 x %struct.snork] addrspace(4)* addrspacecast ([12 x %struct.snork] addrspace(3)* @global to [12 x %struct.snork] addrspace(4)*), i32 0, i32 0), i64 12)
37+
; CHECK: [[ARRAYCTOR_DONE:%.*]] = icmp eq %struct.snork addrspace(4)* [[WG_VAL_ARRAYCTOR_NEXT:%.*]], getelementptr inbounds (%struct.snork, %struct.snork addrspace(4)* getelementptr inbounds ([12 x %struct.snork], [12 x %struct.snork] addrspace(4)* addrspacecast ([12 x %struct.snork] addrspace(3)* @global to [12 x %struct.snork] addrspace(4)*), i32 0, i32 0), i64 12)
38+
; CHECK: call void @llvm.dbg.value(metadata i1 [[ARRAYCTOR_DONE]], [[META14:metadata !.*]], metadata !DIExpression())
39+
br i1 %arrayctor.done, label %arrayctor.cont, label %arrayctor.loop
40+
41+
arrayctor.cont: ; preds = %arrayctor.loop
42+
ret void
43+
}
44+
45+
define linkonce_odr dso_local spir_func void @bar(%struct.snork addrspace(4)* %arg) unnamed_addr align 2 {
46+
bb:
47+
%tmp = alloca %struct.snork addrspace(4)*, align 8
48+
store %struct.snork addrspace(4)* %arg, %struct.snork addrspace(4)** %tmp, align 8
49+
%tmp1 = load %struct.snork addrspace(4)*, %struct.snork addrspace(4)** %tmp, align 8
50+
%tmp2 = getelementptr inbounds %struct.snork, %struct.snork addrspace(4)* %tmp1, i32 0, i32 0
51+
store i32 0, i32 addrspace(4)* %tmp2, align 4
52+
ret void
53+
}
54+
55+
!0 = !{}

0 commit comments

Comments
 (0)