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