xref: /llvm-project/llvm/test/CodeGen/SPIRV/transcoding/explicit-conversions.ll (revision 0a443f13b49b3f392461a0bb60b0146cfc4607c7)
1f20c9c42SAndrey Tretyakov; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2*0a443f13SVyacheslav Levytskyy; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3f20c9c42SAndrey Tretyakov
4f20c9c42SAndrey Tretyakov; CHECK-SPIRV: OpSatConvertSToU
5f20c9c42SAndrey Tretyakov
6f20c9c42SAndrey Tretyakov;; kernel void testSToU(global int2 *a, global uchar2 *res) {
7f20c9c42SAndrey Tretyakov;;   res[0] = convert_uchar2_sat(*a);
8f20c9c42SAndrey Tretyakov;; }
9f20c9c42SAndrey Tretyakov
10f20c9c42SAndrey Tretyakovdefine dso_local spir_kernel void @testSToU(<2 x i32> addrspace(1)* nocapture noundef readonly %a, <2 x i8> addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
11f20c9c42SAndrey Tretyakoventry:
12f20c9c42SAndrey Tretyakov  %0 = load <2 x i32>, <2 x i32> addrspace(1)* %a, align 8
13f20c9c42SAndrey Tretyakov  %call = call spir_func <2 x i8> @_Z18convert_uchar2_satDv2_i(<2 x i32> noundef %0)
14f20c9c42SAndrey Tretyakov  store <2 x i8> %call, <2 x i8> addrspace(1)* %res, align 2
15f20c9c42SAndrey Tretyakov  ret void
16f20c9c42SAndrey Tretyakov}
17f20c9c42SAndrey Tretyakov
18f20c9c42SAndrey Tretyakovdeclare spir_func <2 x i8> @_Z18convert_uchar2_satDv2_i(<2 x i32> noundef) local_unnamed_addr
19f20c9c42SAndrey Tretyakov
20f20c9c42SAndrey Tretyakov; CHECK-SPIRV: OpSatConvertUToS
21f20c9c42SAndrey Tretyakov
22f20c9c42SAndrey Tretyakov;; kernel void testUToS(global uint2 *a, global char2 *res) {
23f20c9c42SAndrey Tretyakov;;   res[0] = convert_char2_sat(*a);
24f20c9c42SAndrey Tretyakov;; }
25f20c9c42SAndrey Tretyakov
26f20c9c42SAndrey Tretyakovdefine dso_local spir_kernel void @testUToS(<2 x i32> addrspace(1)* nocapture noundef readonly %a, <2 x i8> addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
27f20c9c42SAndrey Tretyakoventry:
28f20c9c42SAndrey Tretyakov  %0 = load <2 x i32>, <2 x i32> addrspace(1)* %a, align 8
29f20c9c42SAndrey Tretyakov  %call = call spir_func <2 x i8> @_Z17convert_char2_satDv2_j(<2 x i32> noundef %0)
30f20c9c42SAndrey Tretyakov  store <2 x i8> %call, <2 x i8> addrspace(1)* %res, align 2
31f20c9c42SAndrey Tretyakov  ret void
32f20c9c42SAndrey Tretyakov}
33f20c9c42SAndrey Tretyakov
34f20c9c42SAndrey Tretyakovdeclare spir_func <2 x i8> @_Z17convert_char2_satDv2_j(<2 x i32> noundef) local_unnamed_addr
35f20c9c42SAndrey Tretyakov
36f20c9c42SAndrey Tretyakov; CHECK-SPIRV: OpConvertUToF
37f20c9c42SAndrey Tretyakov
38f20c9c42SAndrey Tretyakov;; kernel void testUToF(global uint2 *a, global float2 *res) {
39f20c9c42SAndrey Tretyakov;;   res[0] = convert_float2_rtz(*a);
40f20c9c42SAndrey Tretyakov;; }
41f20c9c42SAndrey Tretyakov
42f20c9c42SAndrey Tretyakovdefine dso_local spir_kernel void @testUToF(<2 x i32> addrspace(1)* nocapture noundef readonly %a, <2 x float> addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
43f20c9c42SAndrey Tretyakoventry:
44f20c9c42SAndrey Tretyakov  %0 = load <2 x i32>, <2 x i32> addrspace(1)* %a, align 8
45f20c9c42SAndrey Tretyakov  %call = call spir_func <2 x float> @_Z18convert_float2_rtzDv2_j(<2 x i32> noundef %0)
46f20c9c42SAndrey Tretyakov  store <2 x float> %call, <2 x float> addrspace(1)* %res, align 8
47f20c9c42SAndrey Tretyakov  ret void
48f20c9c42SAndrey Tretyakov}
49f20c9c42SAndrey Tretyakov
50f20c9c42SAndrey Tretyakovdeclare spir_func <2 x float> @_Z18convert_float2_rtzDv2_j(<2 x i32> noundef) local_unnamed_addr
51f20c9c42SAndrey Tretyakov
52f20c9c42SAndrey Tretyakov; CHECK-SPIRV: OpConvertFToU
53f20c9c42SAndrey Tretyakov
54f20c9c42SAndrey Tretyakov;; kernel void testFToUSat(global float2 *a, global uint2 *res) {
55f20c9c42SAndrey Tretyakov;;   res[0] = convert_uint2_sat_rtn(*a);
56f20c9c42SAndrey Tretyakov;; }
57f20c9c42SAndrey Tretyakov
58f20c9c42SAndrey Tretyakovdefine dso_local spir_kernel void @testFToUSat(<2 x float> addrspace(1)* nocapture noundef readonly %a, <2 x i32> addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
59f20c9c42SAndrey Tretyakoventry:
60f20c9c42SAndrey Tretyakov  %0 = load <2 x float>, <2 x float> addrspace(1)* %a, align 8
61f20c9c42SAndrey Tretyakov  %call = call spir_func <2 x i32> @_Z21convert_uint2_sat_rtnDv2_f(<2 x float> noundef %0)
62f20c9c42SAndrey Tretyakov  store <2 x i32> %call, <2 x i32> addrspace(1)* %res, align 8
63f20c9c42SAndrey Tretyakov  ret void
64f20c9c42SAndrey Tretyakov}
65f20c9c42SAndrey Tretyakov
66f20c9c42SAndrey Tretyakovdeclare spir_func <2 x i32> @_Z21convert_uint2_sat_rtnDv2_f(<2 x float> noundef) local_unnamed_addr
67f20c9c42SAndrey Tretyakov
68f20c9c42SAndrey Tretyakov; CHECK-SPIRV: OpSatConvertSToU
69f20c9c42SAndrey Tretyakov
70f20c9c42SAndrey Tretyakov;; kernel void testUToUSat(global uchar *a, global uint *res) {
71f20c9c42SAndrey Tretyakov;;   res[0] = convert_uint_sat(*a);
72f20c9c42SAndrey Tretyakov;; }
73f20c9c42SAndrey Tretyakov
74f20c9c42SAndrey Tretyakovdefine dso_local spir_kernel void @testUToUSat(i8 addrspace(1)* nocapture noundef readonly %a, i32 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
75f20c9c42SAndrey Tretyakoventry:
76f20c9c42SAndrey Tretyakov  %0 = load i8, i8 addrspace(1)* %a, align 1
77f20c9c42SAndrey Tretyakov  %call = call spir_func i32 @_Z16convert_uint_sath(i8 noundef zeroext %0)
78f20c9c42SAndrey Tretyakov  store i32 %call, i32 addrspace(1)* %res, align 4
79f20c9c42SAndrey Tretyakov  ret void
80f20c9c42SAndrey Tretyakov}
81f20c9c42SAndrey Tretyakov
82f20c9c42SAndrey Tretyakovdeclare spir_func i32 @_Z16convert_uint_sath(i8 noundef zeroext) local_unnamed_addr
83f20c9c42SAndrey Tretyakov
84f20c9c42SAndrey Tretyakov; CHECK-SPIRV: OpSatConvertSToU
85f20c9c42SAndrey Tretyakov
86f20c9c42SAndrey Tretyakov;; kernel void testUToUSat1(global uint *a, global uchar *res) {
87f20c9c42SAndrey Tretyakov;;   res[0] = convert_uchar_sat(*a);
88f20c9c42SAndrey Tretyakov;; }
89f20c9c42SAndrey Tretyakov
90f20c9c42SAndrey Tretyakovdefine dso_local spir_kernel void @testUToUSat1(i32 addrspace(1)* nocapture noundef readonly %a, i8 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
91f20c9c42SAndrey Tretyakoventry:
92f20c9c42SAndrey Tretyakov  %0 = load i32, i32 addrspace(1)* %a, align 4
93f20c9c42SAndrey Tretyakov  %call = call spir_func zeroext i8 @_Z17convert_uchar_satj(i32 noundef %0)
94f20c9c42SAndrey Tretyakov  store i8 %call, i8 addrspace(1)* %res, align 1
95f20c9c42SAndrey Tretyakov  ret void
96f20c9c42SAndrey Tretyakov}
97f20c9c42SAndrey Tretyakov
98f20c9c42SAndrey Tretyakovdeclare spir_func zeroext i8 @_Z17convert_uchar_satj(i32 noundef) local_unnamed_addr
99f20c9c42SAndrey Tretyakov
100f20c9c42SAndrey Tretyakov; CHECK-SPIRV: OpConvertFToU
101f20c9c42SAndrey Tretyakov
102f20c9c42SAndrey Tretyakov;; kernel void testFToU(global float3 *a, global uint3 *res) {
103f20c9c42SAndrey Tretyakov;;   res[0] = convert_uint3_rtp(*a);
104f20c9c42SAndrey Tretyakov;; }
105f20c9c42SAndrey Tretyakov
106f20c9c42SAndrey Tretyakovdefine dso_local spir_kernel void @testFToU(<3 x float> addrspace(1)* nocapture noundef readonly %a, <3 x i32> addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
107f20c9c42SAndrey Tretyakoventry:
108f20c9c42SAndrey Tretyakov  %castToVec4 = bitcast <3 x float> addrspace(1)* %a to <4 x float> addrspace(1)*
109f20c9c42SAndrey Tretyakov  %loadVec4 = load <4 x float>, <4 x float> addrspace(1)* %castToVec4, align 16
110f20c9c42SAndrey Tretyakov  %extractVec = shufflevector <4 x float> %loadVec4, <4 x float> poison, <3 x i32> <i32 0, i32 1, i32 2>
111f20c9c42SAndrey Tretyakov  %call = call spir_func <3 x i32> @_Z17convert_uint3_rtpDv3_f(<3 x float> noundef %extractVec)
112f20c9c42SAndrey Tretyakov  %extractVec1 = shufflevector <3 x i32> %call, <3 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
113f20c9c42SAndrey Tretyakov  %storetmp = bitcast <3 x i32> addrspace(1)* %res to <4 x i32> addrspace(1)*
114f20c9c42SAndrey Tretyakov  store <4 x i32> %extractVec1, <4 x i32> addrspace(1)* %storetmp, align 16
115f20c9c42SAndrey Tretyakov  ret void
116f20c9c42SAndrey Tretyakov}
117f20c9c42SAndrey Tretyakov
118f20c9c42SAndrey Tretyakovdeclare spir_func <3 x i32> @_Z17convert_uint3_rtpDv3_f(<3 x float> noundef) local_unnamed_addr
119