Skip to content

Commit 09a6a25

Browse files
authored
[SPIRV] Ported tests to transcoding directory from the translator (#151662)
- Checks for printf calls - Handling of convert_* builtins and fallback - Generation of nan and shuffle OpExtInst
1 parent d7f00a9 commit 09a6a25

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
; This test checks that functions with `convert_` prefix are translated as
2+
; OpenCL builtins only in case they match the specification. Otherwise, we
3+
; expect such functions to be translated to SPIR-V FunctionCall.
4+
5+
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
6+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
7+
8+
; CHECK-SPIRV: OpName %[[#Func:]] "_Z18convert_float_func"
9+
; CHECK-SPIRV: OpName %[[#Func1:]] "_Z20convert_uint_satfunc"
10+
; CHECK-SPIRV: OpName %[[#Func2:]] "_Z21convert_float_rtzfunc"
11+
; CHECK-SPIRV-DAG: %[[#VoidTy:]] = OpTypeVoid
12+
; CHECK-SPIRV-DAG: %[[#CharTy:]] = OpTypeInt 8
13+
; CHECK-SPIRV-DAG: %[[#FloatTy:]] = OpTypeFloat 32
14+
15+
; CHECK-SPIRV: %[[#Func]] = OpFunction %[[#VoidTy]] None %[[#]]
16+
; CHECK-SPIRV: %[[#ConvertId1:]] = OpUConvert %[[#CharTy]] %[[#]]
17+
; CHECK-SPIRV: %[[#ConvertId2:]] = OpConvertSToF %[[#FloatTy]] %[[#]]
18+
; CHECK-SPIRV: %[[#]] = OpFunctionCall %[[#VoidTy]] %[[#Func]] %[[#ConvertId2]]
19+
; CHECK-SPIRV: %[[#]] = OpFunctionCall %[[#VoidTy]] %[[#Func1]] %[[#]]
20+
; CHECK-SPIRV: %[[#]] = OpFunctionCall %[[#VoidTy]] %[[#Func2]] %[[#ConvertId2]]
21+
; CHECK-SPIRV-NOT: OpFConvert
22+
; CHECK-SPIRV-NOT: OpConvertUToF
23+
24+
define dso_local spir_func void @_Z18convert_float_func(float noundef %x) {
25+
entry:
26+
%x.addr = alloca float, align 4
27+
store float %x, ptr %x.addr, align 4
28+
ret void
29+
}
30+
31+
define dso_local spir_func void @_Z20convert_uint_satfunc(i32 noundef %x) {
32+
entry:
33+
ret void
34+
}
35+
36+
define dso_local spir_func void @_Z21convert_float_rtzfunc(float noundef %x) {
37+
entry:
38+
ret void
39+
}
40+
41+
define dso_local spir_func void @convert_int_bf16(i32 noundef %x) {
42+
entry:
43+
%x.addr = alloca i32, align 4
44+
store i32 %x, ptr %x.addr, align 4
45+
%0 = load i32, ptr %x.addr, align 4
46+
call spir_func signext i8 @_Z16convert_char_rtei(i32 noundef %0)
47+
%call = call spir_func float @_Z13convert_floati(i32 noundef %0)
48+
call spir_func void @_Z18convert_float_func(float noundef %call)
49+
call spir_func void @_Z20convert_uint_satfunc(i32 noundef %0)
50+
call spir_func void @_Z21convert_float_rtzfunc(float noundef %call)
51+
ret void
52+
}
53+
54+
declare spir_func signext i8 @_Z16convert_char_rtei(i32 noundef)
55+
56+
declare spir_func float @_Z13convert_floati(i32 noundef)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; Check OpenCL built-in nan translation.
5+
6+
; CHECK-SPIRV: %[[#]] = OpExtInst %[[#]] %[[#]] nan %[[#]]
7+
8+
define dso_local spir_kernel void @test(ptr addrspace(1) align 4 %a, i32 %b) {
9+
entry:
10+
%call = tail call spir_func float @_Z3nanj(i32 %b)
11+
store float %call, ptr addrspace(1) %a, align 4
12+
ret void
13+
}
14+
15+
declare spir_func float @_Z3nanj(i32)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; Check OpenCL built-in shuffle and shuffle2 translation.
5+
6+
; CHECK-SPIRV: %[[#]] = OpExtInst %[[#]] %[[#]] shuffle %[[#]] %[[#]]
7+
; CHECK-SPIRV: %[[#]] = OpExtInst %[[#]] %[[#]] shuffle2 %[[#]] %[[#]] %[[#]]
8+
9+
define spir_kernel void @test() {
10+
entry:
11+
%call = call spir_func <2 x float> @_Z7shuffleDv2_fDv2_j(<2 x float> zeroinitializer, <2 x i32> zeroinitializer)
12+
ret void
13+
}
14+
15+
declare spir_func <2 x float> @_Z7shuffleDv2_fDv2_j(<2 x float>, <2 x i32>)
16+
17+
define spir_kernel void @test2() {
18+
entry:
19+
%call = call spir_func <4 x float> @_Z8shuffle2Dv2_fS_Dv4_j(<2 x float> zeroinitializer, <2 x float> zeroinitializer, <4 x i32> zeroinitializer)
20+
ret void
21+
}
22+
23+
declare spir_func <4 x float> @_Z8shuffle2Dv2_fS_Dv4_j(<2 x float>, <2 x float>, <4 x i32>)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
@.str = private unnamed_addr addrspace(2) constant [12 x i8] c"Hello World\00", align 1
5+
6+
; CHECK-SPIRV: %[[#]] = OpExtInst %[[#]] %[[#]] printf %[[#]]
7+
8+
define dso_local spir_kernel void @BuiltinPrintf() {
9+
entry:
10+
%call = tail call i32 (ptr addrspace(2), ...) @printf(ptr addrspace(2) noundef @.str)
11+
ret void
12+
}
13+
14+
declare noundef i32 @printf(ptr addrspace(2) nocapture noundef readonly, ...)

0 commit comments

Comments
 (0)