1 // RUN: mlir-translate -no-implicit-module -test-spirv-roundtrip -split-input-file %s | FileCheck %s
3 spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
4 spirv.func @bit_cast(%arg0 : f32) "None" {
5 // CHECK: {{%.*}} = spirv.Bitcast {{%.*}} : f32 to i32
6 %0 = spirv.Bitcast %arg0 : f32 to i32
7 // CHECK: {{%.*}} = spirv.Bitcast {{%.*}} : i32 to si32
8 %1 = spirv.Bitcast %0 : i32 to si32
9 // CHECK: {{%.*}} = spirv.Bitcast {{%.*}} : si32 to i32
10 %2 = spirv.Bitcast %1 : si32 to ui32
17 spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
18 spirv.func @convert_f_to_s(%arg0 : f32) -> i32 "None" {
19 // CHECK: {{%.*}} = spirv.ConvertFToS {{%.*}} : f32 to i32
20 %0 = spirv.ConvertFToS %arg0 : f32 to i32
21 spirv.ReturnValue %0 : i32
23 spirv.func @convert_f64_to_s32(%arg0 : f64) -> i32 "None" {
24 // CHECK: {{%.*}} = spirv.ConvertFToS {{%.*}} : f64 to i32
25 %0 = spirv.ConvertFToS %arg0 : f64 to i32
26 spirv.ReturnValue %0 : i32
28 spirv.func @convert_f_to_u(%arg0 : f32) -> i32 "None" {
29 // CHECK: {{%.*}} = spirv.ConvertFToU {{%.*}} : f32 to i32
30 %0 = spirv.ConvertFToU %arg0 : f32 to i32
31 spirv.ReturnValue %0 : i32
33 spirv.func @convert_f64_to_u32(%arg0 : f64) -> i32 "None" {
34 // CHECK: {{%.*}} = spirv.ConvertFToU {{%.*}} : f64 to i32
35 %0 = spirv.ConvertFToU %arg0 : f64 to i32
36 spirv.ReturnValue %0 : i32
38 spirv.func @convert_s_to_f(%arg0 : i32) -> f32 "None" {
39 // CHECK: {{%.*}} = spirv.ConvertSToF {{%.*}} : i32 to f32
40 %0 = spirv.ConvertSToF %arg0 : i32 to f32
41 spirv.ReturnValue %0 : f32
43 spirv.func @convert_s64_to_f32(%arg0 : i64) -> f32 "None" {
44 // CHECK: {{%.*}} = spirv.ConvertSToF {{%.*}} : i64 to f32
45 %0 = spirv.ConvertSToF %arg0 : i64 to f32
46 spirv.ReturnValue %0 : f32
48 spirv.func @convert_u_to_f(%arg0 : i32) -> f32 "None" {
49 // CHECK: {{%.*}} = spirv.ConvertUToF {{%.*}} : i32 to f32
50 %0 = spirv.ConvertUToF %arg0 : i32 to f32
51 spirv.ReturnValue %0 : f32
53 spirv.func @convert_u64_to_f32(%arg0 : i64) -> f32 "None" {
54 // CHECK: {{%.*}} = spirv.ConvertUToF {{%.*}} : i64 to f32
55 %0 = spirv.ConvertUToF %arg0 : i64 to f32
56 spirv.ReturnValue %0 : f32
58 spirv.func @f_convert(%arg0 : f32) -> f64 "None" {
59 // CHECK: {{%.*}} = spirv.FConvert {{%.*}} : f32 to f64
60 %0 = spirv.FConvert %arg0 : f32 to f64
61 spirv.ReturnValue %0 : f64
63 spirv.func @s_convert(%arg0 : i32) -> i64 "None" {
64 // CHECK: {{%.*}} = spirv.SConvert {{%.*}} : i32 to i64
65 %0 = spirv.SConvert %arg0 : i32 to i64
66 spirv.ReturnValue %0 : i64
68 spirv.func @u_convert(%arg0 : i32) -> i64 "None" {
69 // CHECK: {{%.*}} = spirv.UConvert {{%.*}} : i32 to i64
70 %0 = spirv.UConvert %arg0 : i32 to i64
71 spirv.ReturnValue %0 : i64
77 spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Kernel], []> {
78 spirv.func @ptr_cast_to_generic(%arg0 : !spirv.ptr<f32, CrossWorkgroup>) "None" {
79 // CHECK: {{%.*}} = spirv.PtrCastToGeneric {{%.*}} : !spirv.ptr<f32, CrossWorkgroup> to !spirv.ptr<f32, Generic>
80 %0 = spirv.PtrCastToGeneric %arg0 : !spirv.ptr<f32, CrossWorkgroup> to !spirv.ptr<f32, Generic>
83 spirv.func @generic_cast_to_ptr(%arg0 : !spirv.ptr<vector<2xi32>, Generic>) "None" {
84 // CHECK: {{%.*}} = spirv.GenericCastToPtr {{%.*}} : !spirv.ptr<vector<2xi32>, Generic> to !spirv.ptr<vector<2xi32>, CrossWorkgroup>
85 %0 = spirv.GenericCastToPtr %arg0 : !spirv.ptr<vector<2xi32>, Generic> to !spirv.ptr<vector<2xi32>, CrossWorkgroup>
88 spirv.func @generic_cast_to_ptr_explicit(%arg0 : !spirv.ptr<vector<2xi32>, Generic>) "None" {
89 // CHECK: {{%.*}} = spirv.GenericCastToPtrExplicit {{%.*}} : !spirv.ptr<vector<2xi32>, Generic> to !spirv.ptr<vector<2xi32>, CrossWorkgroup>
90 %0 = spirv.GenericCastToPtrExplicit %arg0 : !spirv.ptr<vector<2xi32>, Generic> to !spirv.ptr<vector<2xi32>, CrossWorkgroup>
97 spirv.module Physical64 OpenCL requires #spirv.vce<v1.0, [Kernel, Addresses], []> {
98 spirv.func @covert_ptr_to_u(%arg0 : !spirv.ptr<i32, Generic>) "None" {
99 // CHECK: {{%.*}} = spirv.ConvertPtrToU {{%.*}} : !spirv.ptr<i32, Generic> to i32
100 %0 = spirv.ConvertPtrToU %arg0 : !spirv.ptr<i32, Generic> to i32
103 spirv.func @covert_ptr_to_u_truncate(%arg0 : !spirv.ptr<i64, Generic>) "None" {
104 // CHECK: {{%.*}} = spirv.ConvertPtrToU {{%.*}} : !spirv.ptr<i64, Generic> to i32
105 %0 = spirv.ConvertPtrToU %arg0 : !spirv.ptr<i64, Generic> to i32
108 spirv.func @covert_ptr_to_u_extend(%arg0 : !spirv.ptr<i32, Generic>) "None" {
109 // CHECK: {{%.*}} = spirv.ConvertPtrToU {{%.*}} : !spirv.ptr<i32, Generic> to i64
110 %0 = spirv.ConvertPtrToU %arg0 : !spirv.ptr<i32, Generic> to i64
117 spirv.module PhysicalStorageBuffer64 OpenCL requires #spirv.vce<v1.0, [Kernel, Addresses, PhysicalStorageBufferAddresses], []> {
118 spirv.func @covert_ptr_to_u_PhysicalStorageBuffer(%arg0 : !spirv.ptr<i32, PhysicalStorageBuffer> { spirv.decoration = #spirv.decoration<Aliased>} ) "None" {
119 // CHECK: {{%.*}} = spirv.ConvertPtrToU {{%.*}} : !spirv.ptr<i32, PhysicalStorageBuffer> to i32
120 %0 = spirv.ConvertPtrToU %arg0 : !spirv.ptr<i32, PhysicalStorageBuffer> to i32
127 spirv.module Physical64 OpenCL requires #spirv.vce<v1.0, [Kernel, Addresses], []> {
128 spirv.func @covert_u_to_ptr(%arg0 : i32) "None" {
129 // CHECK: {{%.*}} = spirv.ConvertUToPtr {{%.*}} : i32 to !spirv.ptr<i32, Generic>
130 %0 = spirv.ConvertUToPtr %arg0 : i32 to !spirv.ptr<i32, Generic>
133 spirv.func @covert_u_to_ptr_truncate(%arg0 : i64) "None" {
134 // CHECK: {{%.*}} = spirv.ConvertUToPtr {{%.*}} : i64 to !spirv.ptr<i32, Generic>
135 %0 = spirv.ConvertUToPtr %arg0 : i64 to !spirv.ptr<i32, Generic>
138 spirv.func @covert_u_to_ptr_extend(%arg0 : i32) "None" {
139 // CHECK: {{%.*}} = spirv.ConvertUToPtr {{%.*}} : i32 to !spirv.ptr<i64, Generic>
140 %0 = spirv.ConvertUToPtr %arg0 : i32 to !spirv.ptr<i64, Generic>
147 spirv.module PhysicalStorageBuffer64 OpenCL requires #spirv.vce<v1.0, [Kernel, Addresses, PhysicalStorageBufferAddresses], []> {
148 spirv.func @covert_u_to_ptr_PhysicalStorageBuffer(%arg0 : i32) "None" {
149 // CHECK: {{%.*}} = spirv.ConvertUToPtr {{%.*}} : i32 to !spirv.ptr<i32, PhysicalStorageBuffer>
150 %0 = spirv.ConvertUToPtr %arg0 : i32 to !spirv.ptr<i32, PhysicalStorageBuffer>