Skip to content

Commit 4bb5132

Browse files
committed
--Test for verifying emission of correct image type
--Test for verifying that decorations are correctly applied to global variables --Test for signed arithmetic overflow intrinsics, which is for now expectedly failing
1 parent 31387d6 commit 4bb5132

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: llc -O0 -verify-machineinstrs -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+
; Image types may be represented in two ways while translating to SPIR-V:
5+
; - OpenCL form, for example, '%opencl.image2d_ro_t',
6+
; - SPIR-V form, for example, '%spirv.Image._void_1_0_0_0_0_0_0',
7+
; but it is still one type which should be translated to one SPIR-V type.
8+
;
9+
; The test checks that the code below is successfully translated and only one
10+
; SPIR-V type for images is generated.
11+
12+
; CHECK: %[[#]] = OpTypeImage %[[#]] 2D
13+
; CHECK-NOT: %[[#]] = OpTypeImage %[[#]] 2D
14+
15+
declare spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_ff(ptr addrspace(1), ptr addrspace(2), <2 x float>, float)
16+
17+
define spir_kernel void @read_image(ptr addrspace(1) %srcimg, ptr addrspace(2) %sampler){
18+
entry:
19+
%spirvimg.addr = alloca target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0), align 8
20+
%val = call <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_ff(ptr addrspace(1) %srcimg, ptr addrspace(2) %sampler, <2 x float> zeroinitializer, float 0.0)
21+
ret void
22+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -filetype=obj -o - | spirv-val %}
3+
; XFAIL: *
4+
;@llvm.sadd.with.overflow and @llvm.ssub.with.overflow has not been implemented.
5+
6+
define spir_func void @test_sadd_overflow(ptr %out_result, ptr %out_overflow, i32 %a, i32 %b) {
7+
entry:
8+
%res = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
9+
%val = extractvalue { i32, i1 } %res, 0
10+
%ofl = extractvalue { i32, i1 } %res, 1
11+
store i32 %val, ptr %out_result
12+
%zext_ofl = zext i1 %ofl to i8
13+
store i8 %zext_ofl, ptr %out_overflow
14+
ret void
15+
}
16+
17+
declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32)
18+
19+
define spir_func void @test_ssub_overflow(ptr %out_result, ptr %out_overflow, i32 %a, i32 %b) {
20+
entry:
21+
%res = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
22+
%val = extractvalue { i32, i1 } %res, 0
23+
%ofl = extractvalue { i32, i1 } %res, 1
24+
store i32 %val, ptr %out_result
25+
%zext_ofl = zext i1 %ofl to i8
26+
store i8 %zext_ofl, ptr %out_overflow
27+
ret void
28+
}
29+
30+
declare { i32, i1 } @llvm.ssub.with.overflow.i32(i32, i32)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
@v1 = addrspace(1) global i32 42, !spirv.Decorations !2
5+
@v2 = addrspace(1) global float 1.0, !spirv.Decorations !4
6+
7+
define i32 @use_globals() {
8+
entry:
9+
%v1_ptr = addrspacecast i32 addrspace(1)* @v1 to i32*
10+
%v1_val = load i32, i32* %v1_ptr
11+
12+
%v2_ptr = addrspacecast float addrspace(1)* @v2 to float*
13+
%v2_val = load float, float* %v2_ptr
14+
%v2_int = fptosi float %v2_val to i32
15+
16+
%sum = add i32 %v1_val, %v2_int
17+
ret i32 %sum
18+
}
19+
20+
; CHECK: OpDecorate %[[#PId1:]] Constant
21+
; CHECK: OpDecorate %[[#PId2:]] Constant
22+
; CHECK: OpDecorate %[[#PId2]] Binding 1
23+
; CHECK: %[[#PId1]] = OpVariable %[[#]] CrossWorkgroup %[[#]]
24+
; CHECK: %[[#PId2]] = OpVariable %[[#]] CrossWorkgroup %[[#]]
25+
26+
!1 = !{i32 22} ; Constant
27+
!2 = !{!1} ; @v1
28+
!3 = !{i32 33, i32 1} ; Binding 1
29+
!4 = !{!1, !3} ; @v2

0 commit comments

Comments
 (0)