1 // RUN: mlir-opt -convert-spirv-to-llvm %s | FileCheck %s
3 //===----------------------------------------------------------------------===//
5 //===----------------------------------------------------------------------===//
7 // CHECK-LABEL: @bitcast_float_to_integer_scalar
8 spirv.func @bitcast_float_to_integer_scalar(%arg0 : f32) "None" {
9 // CHECK: llvm.bitcast {{.*}} : f32 to i32
10 %0 = spirv.Bitcast %arg0: f32 to i32
14 // CHECK-LABEL: @bitcast_float_to_integer_vector
15 spirv.func @bitcast_float_to_integer_vector(%arg0 : vector<3xf32>) "None" {
16 // CHECK: {{.*}} = llvm.bitcast {{.*}} : vector<3xf32> to vector<3xi32>
17 %0 = spirv.Bitcast %arg0: vector<3xf32> to vector<3xi32>
21 // CHECK-LABEL: @bitcast_vector_to_scalar
22 spirv.func @bitcast_vector_to_scalar(%arg0 : vector<2xf32>) "None" {
23 // CHECK: {{.*}} = llvm.bitcast {{.*}} : vector<2xf32> to i64
24 %0 = spirv.Bitcast %arg0: vector<2xf32> to i64
28 // CHECK-LABEL: @bitcast_scalar_to_vector
29 spirv.func @bitcast_scalar_to_vector(%arg0 : f64) "None" {
30 // CHECK: {{.*}} = llvm.bitcast {{.*}} : f64 to vector<2xi32>
31 %0 = spirv.Bitcast %arg0: f64 to vector<2xi32>
35 // CHECK-LABEL: @bitcast_vector_to_vector
36 spirv.func @bitcast_vector_to_vector(%arg0 : vector<4xf32>) "None" {
37 // CHECK: {{.*}} = llvm.bitcast {{.*}} : vector<4xf32> to vector<2xi64>
38 %0 = spirv.Bitcast %arg0: vector<4xf32> to vector<2xi64>
42 // CHECK-LABEL: @bitcast_pointer
43 spirv.func @bitcast_pointer(%arg0: !spirv.ptr<f32, Function>) "None" {
44 // CHECK-NOT: llvm.bitcast
45 %0 = spirv.Bitcast %arg0 : !spirv.ptr<f32, Function> to !spirv.ptr<i32, Function>
49 //===----------------------------------------------------------------------===//
51 //===----------------------------------------------------------------------===//
53 // CHECK-LABEL: @convert_float_to_signed_scalar
54 spirv.func @convert_float_to_signed_scalar(%arg0: f32) "None" {
55 // CHECK: llvm.fptosi %{{.*}} : f32 to i32
56 %0 = spirv.ConvertFToS %arg0: f32 to i32
60 // CHECK-LABEL: @convert_float_to_signed_vector
61 spirv.func @convert_float_to_signed_vector(%arg0: vector<2xf32>) "None" {
62 // CHECK: llvm.fptosi %{{.*}} : vector<2xf32> to vector<2xi32>
63 %0 = spirv.ConvertFToS %arg0: vector<2xf32> to vector<2xi32>
67 //===----------------------------------------------------------------------===//
69 //===----------------------------------------------------------------------===//
71 // CHECK-LABEL: @convert_float_to_unsigned_scalar
72 spirv.func @convert_float_to_unsigned_scalar(%arg0: f32) "None" {
73 // CHECK: llvm.fptoui %{{.*}} : f32 to i32
74 %0 = spirv.ConvertFToU %arg0: f32 to i32
78 // CHECK-LABEL: @convert_float_to_unsigned_vector
79 spirv.func @convert_float_to_unsigned_vector(%arg0: vector<2xf32>) "None" {
80 // CHECK: llvm.fptoui %{{.*}} : vector<2xf32> to vector<2xi32>
81 %0 = spirv.ConvertFToU %arg0: vector<2xf32> to vector<2xi32>
85 //===----------------------------------------------------------------------===//
87 //===----------------------------------------------------------------------===//
89 // CHECK-LABEL: @convert_signed_to_float_scalar
90 spirv.func @convert_signed_to_float_scalar(%arg0: i32) "None" {
91 // CHECK: llvm.sitofp %{{.*}} : i32 to f32
92 %0 = spirv.ConvertSToF %arg0: i32 to f32
96 // CHECK-LABEL: @convert_signed_to_float_vector
97 spirv.func @convert_signed_to_float_vector(%arg0: vector<3xi32>) "None" {
98 // CHECK: llvm.sitofp %{{.*}} : vector<3xi32> to vector<3xf32>
99 %0 = spirv.ConvertSToF %arg0: vector<3xi32> to vector<3xf32>
103 //===----------------------------------------------------------------------===//
105 //===----------------------------------------------------------------------===//
107 // CHECK-LABEL: @convert_unsigned_to_float_scalar
108 spirv.func @convert_unsigned_to_float_scalar(%arg0: i32) "None" {
109 // CHECK: llvm.uitofp %{{.*}} : i32 to f32
110 %0 = spirv.ConvertUToF %arg0: i32 to f32
114 // CHECK-LABEL: @convert_unsigned_to_float_vector
115 spirv.func @convert_unsigned_to_float_vector(%arg0: vector<3xi32>) "None" {
116 // CHECK: llvm.uitofp %{{.*}} : vector<3xi32> to vector<3xf32>
117 %0 = spirv.ConvertUToF %arg0: vector<3xi32> to vector<3xf32>
121 //===----------------------------------------------------------------------===//
123 //===----------------------------------------------------------------------===//
125 // CHECK-LABEL: @fconvert_scalar
126 spirv.func @fconvert_scalar(%arg0: f32, %arg1: f64) "None" {
127 // CHECK: llvm.fpext %{{.*}} : f32 to f64
128 %0 = spirv.FConvert %arg0: f32 to f64
130 // CHECK: llvm.fptrunc %{{.*}} : f64 to f32
131 %1 = spirv.FConvert %arg1: f64 to f32
135 // CHECK-LABEL: @fconvert_vector
136 spirv.func @fconvert_vector(%arg0: vector<2xf32>, %arg1: vector<2xf64>) "None" {
137 // CHECK: llvm.fpext %{{.*}} : vector<2xf32> to vector<2xf64>
138 %0 = spirv.FConvert %arg0: vector<2xf32> to vector<2xf64>
140 // CHECK: llvm.fptrunc %{{.*}} : vector<2xf64> to vector<2xf32>
141 %1 = spirv.FConvert %arg1: vector<2xf64> to vector<2xf32>
145 //===----------------------------------------------------------------------===//
147 //===----------------------------------------------------------------------===//
149 // CHECK-LABEL: @sconvert_scalar
150 spirv.func @sconvert_scalar(%arg0: i32, %arg1: i64) "None" {
151 // CHECK: llvm.sext %{{.*}} : i32 to i64
152 %0 = spirv.SConvert %arg0: i32 to i64
154 // CHECK: llvm.trunc %{{.*}} : i64 to i32
155 %1 = spirv.SConvert %arg1: i64 to i32
159 // CHECK-LABEL: @sconvert_vector
160 spirv.func @sconvert_vector(%arg0: vector<3xi32>, %arg1: vector<3xi64>) "None" {
161 // CHECK: llvm.sext %{{.*}} : vector<3xi32> to vector<3xi64>
162 %0 = spirv.SConvert %arg0: vector<3xi32> to vector<3xi64>
164 // CHECK: llvm.trunc %{{.*}} : vector<3xi64> to vector<3xi32>
165 %1 = spirv.SConvert %arg1: vector<3xi64> to vector<3xi32>
169 //===----------------------------------------------------------------------===//
171 //===----------------------------------------------------------------------===//
173 // CHECK-LABEL: @uconvert_scalar
174 spirv.func @uconvert_scalar(%arg0: i32, %arg1: i64) "None" {
175 // CHECK: llvm.zext %{{.*}} : i32 to i64
176 %0 = spirv.UConvert %arg0: i32 to i64
178 // CHECK: llvm.trunc %{{.*}} : i64 to i32
179 %1 = spirv.UConvert %arg1: i64 to i32
183 // CHECK-LABEL: @uconvert_vector
184 spirv.func @uconvert_vector(%arg0: vector<3xi32>, %arg1: vector<3xi64>) "None" {
185 // CHECK: llvm.zext %{{.*}} : vector<3xi32> to vector<3xi64>
186 %0 = spirv.UConvert %arg0: vector<3xi32> to vector<3xi64>
188 // CHECK: llvm.trunc %{{.*}} : vector<3xi64> to vector<3xi32>
189 %1 = spirv.UConvert %arg1: vector<3xi64> to vector<3xi32>