Skip to content

Commit 3a1cb68

Browse files
[SPIRV] Porting 4 tests from Translator (#151678)
Tests that checks: - Duplicate alignment - Duplicate types - Non-function storage class for global variable - Generating image instructions from opencl builtins --------- Co-authored-by: Michal Paszkowski <[email protected]>
1 parent 29d9c4a commit 3a1cb68

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; This test case checks that LLVM -> SPIR-V translation produces valid
2+
; SPIR-V module, where a global variable, defined with non-default
3+
; address space, have correct non-function storage class.
4+
;
5+
; No additional checks are needed in addition to simple translation
6+
; to SPIR-V. In case of an error newly produced SPIR-V module validation
7+
; would fail due to spirv-val that detects problematic SPIR-V code from
8+
; translator and reports it as the following error:
9+
;
10+
; "Variables can not have a function[7] storage class outside of a function".
11+
;
12+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
13+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
14+
15+
; CHECK: %[[#Ptr:]] = OpTypePointer CrossWorkgroup %[[#]]
16+
; CHECK: %[[#]] = OpVariable %[[#Ptr]] CrossWorkgroup %[[#]]
17+
18+
@G = addrspace(1) global i1 true
19+
20+
define spir_func i1 @f(i1 %0) {
21+
store i1 %0, ptr addrspace(1) @G, align 1
22+
ret i1 %0
23+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: llc -verify-machineinstrs -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+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
5+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
6+
7+
;CHECK: OpEntryPoint Kernel %[[#KernelId:]]
8+
;CHECK: %[[#image2d_t:]] = OpTypeImage
9+
;CHECK: %[[#sampler_t:]] = OpTypeSampler
10+
;CHECK: %[[#sampled_image_t:]] = OpTypeSampledImage
11+
12+
define spir_func float @test(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %Img, target("spirv.Sampler") %Smp) {
13+
;CHECK-NOT: %[[#KernelId]] = OpFunction %[[#]]
14+
;CHECK: OpFunction
15+
;CHECK: %[[#image:]] = OpFunctionParameter %[[#image2d_t]]
16+
;CHECK: %[[#sampler:]] = OpFunctionParameter %[[#sampler_t]]
17+
entry:
18+
%call = call spir_func <4 x i32> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_i(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %Img, target("spirv.Sampler") %Smp, <2 x i32> zeroinitializer)
19+
;CHECK: %[[#sampled_image:]] = OpSampledImage %[[#sampled_image_t]] %[[#image]] %[[#sampler]]
20+
;CHECK: %[[#]] = OpImageSampleExplicitLod %[[#]] %[[#sampled_image]] %[[#]] Lod %[[#]]
21+
22+
%0 = extractelement <4 x i32> %call, i32 0
23+
%conv = sitofp i32 %0 to float
24+
ret float %conv
25+
}
26+
27+
declare spir_func <4 x i32> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_i(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0), i32, <2 x i32>)
28+
29+
define spir_kernel void @test2(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %Img, target("spirv.Sampler") %Smp, ptr addrspace(1) %result) {
30+
;CHECK: %[[#KernelId]] = OpFunction %[[#]]
31+
entry:
32+
%call = call spir_func float @test(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %Img, target("spirv.Sampler") %Smp)
33+
%0 = load float, ptr addrspace(1) %result, align 4
34+
%add = fadd float %0, %call
35+
store float %add, ptr addrspace(1) %result, align 4
36+
ret void
37+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: llc -verify-machineinstrs -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+
; Test that duplicate align information does not result in SPIR-V validation
5+
; errors due to duplicate Alignment Decorations.
6+
7+
;CHECK: OpDecorate %[[#Var:]] Alignment
8+
;CHECK: %[[#Var]] = OpVariable %[[#]]
9+
10+
define spir_func void @f() {
11+
%res = alloca i16, align 2, !spirv.Decorations !1
12+
ret void
13+
}
14+
15+
!1 = !{!2}
16+
!2 = !{i32 44, i32 2}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; Check that we don't end up with duplicated array types in TypeMap.
2+
; No FileCheck needed, we only want to check the absence of errors.
3+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o -
4+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
5+
6+
; CHECK: %[[#]] = OpTypeArray %[[#]] %[[#]]
7+
; CHECK-NOT: OpTypeArray
8+
9+
%duplicate = type { [2 x ptr addrspace(4)] }
10+
11+
define spir_kernel void @foo() {
12+
entry:
13+
alloca [2 x ptr addrspace(4)], align 8
14+
alloca %duplicate, align 8
15+
ret void
16+
}

0 commit comments

Comments
 (0)