1 // RUN: mlir-opt -split-input-file -verify-diagnostics %s | FileCheck %s
3 //===----------------------------------------------------------------------===//
5 //===----------------------------------------------------------------------===//
7 func.func @iequal_scalar(%arg0: i32, %arg1: i32) -> i1 {
8 // CHECK: spirv.IEqual {{.*}}, {{.*}} : i32
9 %0 = spirv.IEqual %arg0, %arg1 : i32
15 func.func @iequal_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> vector<4xi1> {
16 // CHECK: spirv.IEqual {{.*}}, {{.*}} : vector<4xi32>
17 %0 = spirv.IEqual %arg0, %arg1 : vector<4xi32>
18 return %0 : vector<4xi1>
23 //===----------------------------------------------------------------------===//
25 //===----------------------------------------------------------------------===//
27 func.func @inotequal_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> vector<4xi1> {
28 // CHECK: spirv.INotEqual {{.*}}, {{.*}} : vector<4xi32>
29 %0 = spirv.INotEqual %arg0, %arg1 : vector<4xi32>
30 return %0 : vector<4xi1>
35 //===----------------------------------------------------------------------===//
37 //===----------------------------------------------------------------------===//
39 func.func @isinf_scalar(%arg0: f32) -> i1 {
40 // CHECK: spirv.IsInf {{.*}} : f32
41 %0 = spirv.IsInf %arg0 : f32
45 func.func @isinf_vector(%arg0: vector<2xf32>) -> vector<2xi1> {
46 // CHECK: spirv.IsInf {{.*}} : vector<2xf32>
47 %0 = spirv.IsInf %arg0 : vector<2xf32>
48 return %0 : vector<2xi1>
53 //===----------------------------------------------------------------------===//
55 //===----------------------------------------------------------------------===//
57 func.func @isnan_scalar(%arg0: f32) -> i1 {
58 // CHECK: spirv.IsNan {{.*}} : f32
59 %0 = spirv.IsNan %arg0 : f32
63 func.func @isnan_vector(%arg0: vector<2xf32>) -> vector<2xi1> {
64 // CHECK: spirv.IsNan {{.*}} : vector<2xf32>
65 %0 = spirv.IsNan %arg0 : vector<2xf32>
66 return %0 : vector<2xi1>
69 //===----------------------------------------------------------------------===//
71 //===----------------------------------------------------------------------===//
73 func.func @logicalBinary(%arg0 : i1, %arg1 : i1, %arg2 : i1)
75 // CHECK: [[TMP:%.*]] = spirv.LogicalAnd {{%.*}}, {{%.*}} : i1
76 %0 = spirv.LogicalAnd %arg0, %arg1 : i1
77 // CHECK: {{%.*}} = spirv.LogicalAnd [[TMP]], {{%.*}} : i1
78 %1 = spirv.LogicalAnd %0, %arg2 : i1
82 func.func @logicalBinary2(%arg0 : vector<4xi1>, %arg1 : vector<4xi1>)
84 // CHECK: {{%.*}} = spirv.LogicalAnd {{%.*}}, {{%.*}} : vector<4xi1>
85 %0 = spirv.LogicalAnd %arg0, %arg1 : vector<4xi1>
91 func.func @logicalBinary(%arg0 : i1, %arg1 : i1)
93 // expected-error @+1 {{expected ':'}}
94 %0 = spirv.LogicalAnd %arg0, %arg1
100 func.func @logicalBinary(%arg0 : i1, %arg1 : i1)
102 // expected-error @+1 {{expected non-function type}}
103 %0 = spirv.LogicalAnd %arg0, %arg1 :
109 func.func @logicalBinary(%arg0 : i1, %arg1 : i1)
111 // expected-error @+1 {{expected ','}}
112 %0 = spirv.LogicalAnd %arg0 : i1
118 //===----------------------------------------------------------------------===//
120 //===----------------------------------------------------------------------===//
122 func.func @logicalUnary(%arg0 : i1, %arg1 : i1)
124 // CHECK: [[TMP:%.*]] = spirv.LogicalNot {{%.*}} : i1
125 %0 = spirv.LogicalNot %arg0 : i1
126 // CHECK: {{%.*}} = spirv.LogicalNot [[TMP]] : i1
127 %1 = spirv.LogicalNot %0 : i1
131 func.func @logicalUnary2(%arg0 : vector<4xi1>)
133 // CHECK: {{%.*}} = spirv.LogicalNot {{%.*}} : vector<4xi1>
134 %0 = spirv.LogicalNot %arg0 : vector<4xi1>
140 func.func @logicalUnary(%arg0 : i1)
142 // expected-error @+1 {{expected ':'}}
143 %0 = spirv.LogicalNot %arg0
149 func.func @logicalUnary(%arg0 : i1)
151 // expected-error @+1 {{expected non-function type}}
152 %0 = spirv.LogicalNot %arg0 :
158 func.func @logicalUnary(%arg0 : i1)
160 // expected-error @+1 {{expected SSA operand}}
161 %0 = spirv.LogicalNot : i1
167 func.func @logicalUnary(%arg0 : i32)
169 // expected-error @+1 {{'operand' must be bool or vector of bool values of length 2/3/4/8/16, but got 'i32'}}
170 %0 = spirv.LogicalNot %arg0 : i32
176 //===----------------------------------------------------------------------===//
178 //===----------------------------------------------------------------------===//
180 func.func @select_op_bool(%arg0: i1) -> () {
181 %0 = spirv.Constant true
182 %1 = spirv.Constant false
183 // CHECK: spirv.Select {{%.*}}, {{%.*}}, {{%.*}} : i1, i1
184 %2 = spirv.Select %arg0, %0, %1 : i1, i1
188 func.func @select_op_int(%arg0: i1) -> () {
189 %0 = spirv.Constant 2 : i32
190 %1 = spirv.Constant 3 : i32
191 // CHECK: spirv.Select {{%.*}}, {{%.*}}, {{%.*}} : i1, i32
192 %2 = spirv.Select %arg0, %0, %1 : i1, i32
196 func.func @select_op_float(%arg0: i1) -> () {
197 %0 = spirv.Constant 2.0 : f32
198 %1 = spirv.Constant 3.0 : f32
199 // CHECK: spirv.Select {{%.*}}, {{%.*}}, {{%.*}} : i1, f32
200 %2 = spirv.Select %arg0, %0, %1 : i1, f32
204 func.func @select_op_ptr(%arg0: i1) -> () {
205 %0 = spirv.Variable : !spirv.ptr<f32, Function>
206 %1 = spirv.Variable : !spirv.ptr<f32, Function>
207 // CHECK: spirv.Select {{%.*}}, {{%.*}}, {{%.*}} : i1, !spirv.ptr<f32, Function>
208 %2 = spirv.Select %arg0, %0, %1 : i1, !spirv.ptr<f32, Function>
212 func.func @select_op_vec(%arg0: i1) -> () {
213 %0 = spirv.Constant dense<[2.0, 3.0, 4.0]> : vector<3xf32>
214 %1 = spirv.Constant dense<[5.0, 6.0, 7.0]> : vector<3xf32>
215 // CHECK: spirv.Select {{%.*}}, {{%.*}}, {{%.*}} : i1, vector<3xf32>
216 %2 = spirv.Select %arg0, %0, %1 : i1, vector<3xf32>
220 func.func @select_op_vec_condn_vec(%arg0: vector<3xi1>) -> () {
221 %0 = spirv.Constant dense<[2.0, 3.0, 4.0]> : vector<3xf32>
222 %1 = spirv.Constant dense<[5.0, 6.0, 7.0]> : vector<3xf32>
223 // CHECK: spirv.Select {{%.*}}, {{%.*}}, {{%.*}} : vector<3xi1>, vector<3xf32>
224 %2 = spirv.Select %arg0, %0, %1 : vector<3xi1>, vector<3xf32>
230 func.func @select_op(%arg0: i1) -> () {
231 %0 = spirv.Constant 2 : i32
232 %1 = spirv.Constant 3 : i32
233 // expected-error @+1 {{expected ','}}
234 %2 = spirv.Select %arg0, %0, %1 : i1
240 func.func @select_op(%arg1: vector<3xi1>) -> () {
241 %0 = spirv.Constant 2 : i32
242 %1 = spirv.Constant 3 : i32
243 // expected-error @+1 {{result expected to be of vector type when condition is of vector type}}
244 %2 = spirv.Select %arg1, %0, %1 : vector<3xi1>, i32
250 func.func @select_op(%arg1: vector<4xi1>) -> () {
251 %0 = spirv.Constant dense<[2, 3, 4]> : vector<3xi32>
252 %1 = spirv.Constant dense<[5, 6, 7]> : vector<3xi32>
253 // expected-error @+1 {{result should have the same number of elements as the condition when condition is of vector type}}
254 %2 = spirv.Select %arg1, %0, %1 : vector<4xi1>, vector<3xi32>
260 func.func @select_op(%arg1: vector<4xi1>) -> () {
261 %0 = spirv.Constant dense<[2.0, 3.0, 4.0]> : vector<3xf32>
262 %1 = spirv.Constant dense<[5, 6, 7]> : vector<3xi32>
263 // expected-error @+1 {{all of {true_value, false_value, result} have same type}}
264 %2 = "spirv.Select"(%arg1, %0, %1) : (vector<4xi1>, vector<3xf32>, vector<3xi32>) -> vector<3xi32>
270 func.func @select_op(%arg1: vector<4xi1>) -> () {
271 %0 = spirv.Constant dense<[2.0, 3.0, 4.0]> : vector<3xf32>
272 %1 = spirv.Constant dense<[5, 6, 7]> : vector<3xi32>
273 // TODO: expand post change in verification order. This is currently only
274 // verifying that the type verification is failing but not the specific error
275 // message. In final state the error should refer to mismatch in true_value and
277 // expected-error @+1 {{type}}
278 %2 = "spirv.Select"(%arg1, %1, %0) : (vector<4xi1>, vector<3xi32>, vector<3xf32>) -> vector<3xi32>
284 //===----------------------------------------------------------------------===//
285 // spirv.SGreaterThan
286 //===----------------------------------------------------------------------===//
288 func.func @sgt_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> vector<4xi1> {
289 // CHECK: spirv.SGreaterThan {{.*}}, {{.*}} : vector<4xi32>
290 %0 = spirv.SGreaterThan %arg0, %arg1 : vector<4xi32>
291 return %0 : vector<4xi1>
296 //===----------------------------------------------------------------------===//
297 // spirv.SGreaterThanEqual
298 //===----------------------------------------------------------------------===//
300 func.func @sge_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> vector<4xi1> {
301 // CHECK: spirv.SGreaterThanEqual {{.*}}, {{.*}} : vector<4xi32>
302 %0 = spirv.SGreaterThanEqual %arg0, %arg1 : vector<4xi32>
303 return %0 : vector<4xi1>
308 //===----------------------------------------------------------------------===//
310 //===----------------------------------------------------------------------===//
312 func.func @slt_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> vector<4xi1> {
313 // CHECK: spirv.SLessThan {{.*}}, {{.*}} : vector<4xi32>
314 %0 = spirv.SLessThan %arg0, %arg1 : vector<4xi32>
315 return %0 : vector<4xi1>
320 //===----------------------------------------------------------------------===//
321 // spirv.SLessThanEqual
322 //===----------------------------------------------------------------------===//
324 func.func @slte_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> vector<4xi1> {
325 // CHECK: spirv.SLessThanEqual {{.*}}, {{.*}} : vector<4xi32>
326 %0 = spirv.SLessThanEqual %arg0, %arg1 : vector<4xi32>
327 return %0 : vector<4xi1>
332 //===----------------------------------------------------------------------===//
333 // spirv.UGreaterThan
334 //===----------------------------------------------------------------------===//
336 func.func @ugt_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> vector<4xi1> {
337 // CHECK: spirv.UGreaterThan {{.*}}, {{.*}} : vector<4xi32>
338 %0 = spirv.UGreaterThan %arg0, %arg1 : vector<4xi32>
339 return %0 : vector<4xi1>
344 //===----------------------------------------------------------------------===//
345 // spirv.UGreaterThanEqual
346 //===----------------------------------------------------------------------===//
348 func.func @ugte_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> vector<4xi1> {
349 // CHECK: spirv.UGreaterThanEqual {{.*}}, {{.*}} : vector<4xi32>
350 %0 = spirv.UGreaterThanEqual %arg0, %arg1 : vector<4xi32>
351 return %0 : vector<4xi1>
356 //===----------------------------------------------------------------------===//
358 //===----------------------------------------------------------------------===//
360 func.func @ult_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> vector<4xi1> {
361 // CHECK: spirv.ULessThan {{.*}}, {{.*}} : vector<4xi32>
362 %0 = spirv.ULessThan %arg0, %arg1 : vector<4xi32>
363 return %0 : vector<4xi1>
368 //===----------------------------------------------------------------------===//
369 // spirv.ULessThanEqual
370 //===----------------------------------------------------------------------===//
372 func.func @ulte_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> vector<4xi1> {
373 // CHECK: spirv.ULessThanEqual {{.*}}, {{.*}} : vector<4xi32>
374 %0 = spirv.ULessThanEqual %arg0, %arg1 : vector<4xi32>
375 return %0 : vector<4xi1>