Skip to content

Commit c071c1d

Browse files
[SPIR-V] New validation tests for pointer and primitive types (#89632)
This patch adds new tests mostly checking SPIR-V validation of pointer and primitive types.
1 parent 601d0ca commit c071c1d

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK-DAG: %[[#VOID:]] = OpTypeVoid
5+
; CHECK-DAG: %[[#FLOAT:]] = OpTypeFloat 32
6+
; CHECK-DAG: %[[#UCHAR:]] = OpTypeInt 8 0
7+
; CHECK-DAG: %[[#UINT:]] = OpTypeInt 32 0
8+
; CHECK-DAG: %[[#STRUCT_S:]] = OpTypeStruct %[[#FLOAT]] %[[#UCHAR]] %[[#UINT]]
9+
; CHECK-DAG: %[[#PTR_STRUCT_S:]] = OpTypePointer Function %[[#STRUCT_S]]
10+
; CHECK-DAG: %[[#FUNC_TYPE_K:]] = OpTypeFunction %[[#VOID]] %[[#PTR_STRUCT_S]]
11+
; CHECK-DAG: %[[#FUNC_TYPE_H:]] = OpTypeFunction %[[#UINT]] %[[#PTR_STRUCT_S]]
12+
13+
; CHECK: %[[#]] = OpFunction %[[#VOID]] None %[[#FUNC_TYPE_K]]
14+
; CHECK: %[[#]] = OpFunctionParameter %[[#PTR_STRUCT_S]]
15+
16+
; CHECK: %[[#]] = OpFunction %[[#UINT]] None %[[#FUNC_TYPE_H]]
17+
; CHECK: %[[#]] = OpFunctionParameter %[[#PTR_STRUCT_S]]
18+
19+
%struct.s = type { float, i8, i32 }
20+
21+
define spir_kernel void @k(ptr noundef byval(%struct.s) align 4 %x) {
22+
entry:
23+
%c = getelementptr inbounds %struct.s, ptr %x, i32 0, i32 2
24+
%l = load i32, ptr %c, align 4
25+
%add = add nsw i32 %l, 1
26+
%c1 = getelementptr inbounds %struct.s, ptr %x, i32 0, i32 2
27+
store i32 %add, ptr %c1, align 4
28+
ret void
29+
}
30+
31+
define spir_func i32 @h(ptr noundef byval(%struct.s) align 4 %x) {
32+
entry:
33+
%c = getelementptr inbounds %struct.s, ptr %x, i32 0, i32 2
34+
%l = load i32, ptr %c, align 4
35+
%add = add nsw i32 %l, 1
36+
ret i32 %add
37+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
@Ptr = addrspace(1) global ptr addrspace(1) null
5+
@Init = private addrspace(2) constant i32 123
6+
7+
; CHECK-DAG: %[[#PTR:]] = OpVariable %[[#]] UniformConstant %[[#]]
8+
; CHECK-DAG: %[[#INIT:]] = OpVariable %[[#]] CrossWorkgroup %[[#]]
9+
10+
; CHECK: %[[#]] = OpLoad %[[#]] %[[#INIT]] Aligned 8
11+
; CHECK: OpCopyMemorySized %[[#]] %[[#PTR]] %[[#]] Aligned 4
12+
13+
define spir_kernel void @Foo() {
14+
%l = load ptr addrspace(1), ptr addrspace(1) @Ptr, align 8
15+
call void @llvm.memcpy.p1.p2.i64(ptr addrspace(1) align 4 %l, ptr addrspace(2) align 1 @Init, i64 4, i1 false)
16+
ret void
17+
}
18+
19+
declare void @llvm.memcpy.p1.p2.i64(ptr addrspace(1) noalias nocapture writeonly, ptr addrspace(2) noalias nocapture readonly, i64, i1 immarg)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK-DAG: %[[#BOOL:]] = OpTypeBool
5+
; CHECK: %[[#BOOL:]] = OpLogicalOr %[[#BOOL]] %[[#]] %[[#]]
6+
7+
define spir_kernel void @foo(
8+
ptr addrspace(1) nocapture noundef writeonly %Dst,
9+
i32 %a, i32 %b) local_unnamed_addr #0 {
10+
entry:
11+
%a1 = trunc i32 %a to i1
12+
%b1 = trunc i32 %b to i1
13+
%ab1 = or i1 %a1, %b1
14+
%ab32 = zext i1 %ab1 to i32
15+
store i32 %ab32, ptr addrspace(1) %Dst
16+
ret void
17+
}

0 commit comments

Comments
 (0)