1// RUN: mlir-opt -split-input-file -verify-diagnostics %s | FileCheck %s
2
3//===----------------------------------------------------------------------===//
4// spv.BitCount
5//===----------------------------------------------------------------------===//
6
7func @bitcount(%arg: i32) -> i32 {
8  // CHECK: spv.BitCount {{%.*}} : i32
9  %0 = spv.BitCount %arg : i32
10  spv.ReturnValue %0 : i32
11}
12
13// -----
14
15//===----------------------------------------------------------------------===//
16// spv.BitFieldInsert
17//===----------------------------------------------------------------------===//
18
19func @bit_field_insert_vec(%base: vector<3xi32>, %insert: vector<3xi32>, %offset: i32, %count: i16) -> vector<3xi32> {
20  // CHECK: {{%.*}} = spv.BitFieldInsert {{%.*}}, {{%.*}}, {{%.*}}, {{%.*}} : vector<3xi32>, i32, i16
21  %0 = spv.BitFieldInsert %base, %insert, %offset, %count : vector<3xi32>, i32, i16
22  spv.ReturnValue %0 : vector<3xi32>
23}
24
25// -----
26
27func @bit_field_insert_invalid_insert_type(%base: vector<3xi32>, %insert: vector<2xi32>, %offset: i32, %count: i16) -> vector<3xi32> {
28  // expected-error @+1 {{all of {base, insert, result} have same type}}
29  %0 = "spv.BitFieldInsert" (%base, %insert, %offset, %count) : (vector<3xi32>, vector<2xi32>, i32, i16) -> vector<3xi32>
30  spv.ReturnValue %0 : vector<3xi32>
31}
32
33// -----
34
35//===----------------------------------------------------------------------===//
36// spv.BitFieldSExtract
37//===----------------------------------------------------------------------===//
38
39func @bit_field_s_extract_vec(%base: vector<3xi32>, %offset: i8, %count: i8) -> vector<3xi32> {
40  // CHECK: {{%.*}} = spv.BitFieldSExtract {{%.*}}, {{%.*}}, {{%.*}} : vector<3xi32>, i8, i8
41  %0 = spv.BitFieldSExtract %base, %offset, %count : vector<3xi32>, i8, i8
42  spv.ReturnValue %0 : vector<3xi32>
43}
44
45//===----------------------------------------------------------------------===//
46// spv.BitFieldUExtract
47//===----------------------------------------------------------------------===//
48
49func @bit_field_u_extract_vec(%base: vector<3xi32>, %offset: i8, %count: i8) -> vector<3xi32> {
50  // CHECK: {{%.*}} = spv.BitFieldUExtract {{%.*}}, {{%.*}}, {{%.*}} : vector<3xi32>, i8, i8
51  %0 = spv.BitFieldUExtract %base, %offset, %count : vector<3xi32>, i8, i8
52  spv.ReturnValue %0 : vector<3xi32>
53}
54
55// -----
56
57func @bit_field_u_extract_invalid_result_type(%base: vector<3xi32>, %offset: i32, %count: i16) -> vector<4xi32> {
58  // expected-error @+1 {{failed to verify that all of {base, result} have same type}}
59  %0 = "spv.BitFieldUExtract" (%base, %offset, %count) : (vector<3xi32>, i32, i16) -> vector<4xi32>
60  spv.ReturnValue %0 : vector<4xi32>
61}
62
63// -----
64
65//===----------------------------------------------------------------------===//
66// spv.BitReverse
67//===----------------------------------------------------------------------===//
68
69func @bitreverse(%arg: i32) -> i32 {
70  // CHECK: spv.BitReverse {{%.*}} : i32
71  %0 = spv.BitReverse %arg : i32
72  spv.ReturnValue %0 : i32
73}
74
75// -----
76
77//===----------------------------------------------------------------------===//
78// spv.BitwiseOr
79//===----------------------------------------------------------------------===//
80
81func @bitwise_or_scalar(%arg: i32) -> i32 {
82  // CHECK: spv.BitwiseOr
83  %0 = spv.BitwiseOr %arg, %arg : i32
84  return %0 : i32
85}
86
87func @bitwise_or_vector(%arg: vector<4xi32>) -> vector<4xi32> {
88  // CHECK: spv.BitwiseOr
89  %0 = spv.BitwiseOr %arg, %arg : vector<4xi32>
90  return %0 : vector<4xi32>
91}
92
93// -----
94
95func @bitwise_or_float(%arg0: f16, %arg1: f16) -> f16 {
96  // expected-error @+1 {{operand #0 must be 8/16/32/64-bit integer or vector of 8/16/32/64-bit integer values of length 2/3/4}}
97  %0 = spv.BitwiseOr %arg0, %arg1 : f16
98  return %0 : f16
99}
100
101// -----
102
103//===----------------------------------------------------------------------===//
104// spv.BitwiseXor
105//===----------------------------------------------------------------------===//
106
107func @bitwise_xor_scalar(%arg: i32) -> i32 {
108  // CHECK: spv.BitwiseXor
109  %0 = spv.BitwiseXor %arg, %arg : i32
110  return %0 : i32
111}
112
113func @bitwise_xor_vector(%arg: vector<4xi32>) -> vector<4xi32> {
114  // CHECK: spv.BitwiseXor
115  %0 = spv.BitwiseXor %arg, %arg : vector<4xi32>
116  return %0 : vector<4xi32>
117}
118
119// -----
120
121func @bitwise_xor_float(%arg0: f16, %arg1: f16) -> f16 {
122  // expected-error @+1 {{operand #0 must be 8/16/32/64-bit integer or vector of 8/16/32/64-bit integer values of length 2/3/4}}
123  %0 = spv.BitwiseXor %arg0, %arg1 : f16
124  return %0 : f16
125}
126
127// -----
128
129//===----------------------------------------------------------------------===//
130// spv.BitwiseAnd
131//===----------------------------------------------------------------------===//
132
133func @bitwise_and_scalar(%arg: i32) -> i32 {
134  // CHECK: spv.BitwiseAnd
135  %0 = spv.BitwiseAnd %arg, %arg : i32
136  return %0 : i32
137}
138
139func @bitwise_and_vector(%arg: vector<4xi32>) -> vector<4xi32> {
140  // CHECK: spv.BitwiseAnd
141  %0 = spv.BitwiseAnd %arg, %arg : vector<4xi32>
142  return %0 : vector<4xi32>
143}
144
145// -----
146
147func @bitwise_and_float(%arg0: f16, %arg1: f16) -> f16 {
148  // expected-error @+1 {{operand #0 must be 8/16/32/64-bit integer or vector of 8/16/32/64-bit integer values of length 2/3/4}}
149  %0 = spv.BitwiseAnd %arg0, %arg1 : f16
150  return %0 : f16
151}
152
153// -----
154
155//===----------------------------------------------------------------------===//
156// spv.Not
157//===----------------------------------------------------------------------===//
158
159func @not(%arg: i32) -> i32 {
160  // CHECK: spv.Not {{%.*}} : i32
161  %0 = spv.Not %arg : i32
162  spv.ReturnValue %0 : i32
163}
164
165// -----
166
167//===----------------------------------------------------------------------===//
168// spv.ShiftLeftLogical
169//===----------------------------------------------------------------------===//
170
171func @shift_left_logical(%arg0: i32, %arg1 : i16) -> i32 {
172  // CHECK: {{%.*}} = spv.ShiftLeftLogical {{%.*}}, {{%.*}} : i32, i16
173  %0 = spv.ShiftLeftLogical %arg0, %arg1: i32, i16
174  spv.ReturnValue %0 : i32
175}
176
177// -----
178
179func @shift_left_logical_invalid_result_type(%arg0: i32, %arg1 : i16) -> i16 {
180  // expected-error @+1 {{expected the same type for the first operand and result, but provided 'i32' and 'i16'}}
181  %0 = "spv.ShiftLeftLogical" (%arg0, %arg1) : (i32, i16) -> (i16)
182  spv.ReturnValue %0 : i16
183}
184
185// -----
186
187//===----------------------------------------------------------------------===//
188// spv.ShiftRightArithmetic
189//===----------------------------------------------------------------------===//
190
191func @shift_right_arithmetic(%arg0: vector<4xi32>, %arg1 : vector<4xi8>) -> vector<4xi32> {
192  // CHECK: {{%.*}} = spv.ShiftRightArithmetic {{%.*}}, {{%.*}} : vector<4xi32>, vector<4xi8>
193  %0 = spv.ShiftRightArithmetic %arg0, %arg1: vector<4xi32>, vector<4xi8>
194  spv.ReturnValue %0 : vector<4xi32>
195}
196
197// -----
198
199//===----------------------------------------------------------------------===//
200// spv.ShiftRightLogical
201//===----------------------------------------------------------------------===//
202
203func @shift_right_logical(%arg0: vector<2xi32>, %arg1 : vector<2xi8>) -> vector<2xi32> {
204  // CHECK: {{%.*}} = spv.ShiftRightLogical {{%.*}}, {{%.*}} : vector<2xi32>, vector<2xi8>
205  %0 = spv.ShiftRightLogical %arg0, %arg1: vector<2xi32>, vector<2xi8>
206  spv.ReturnValue %0 : vector<2xi32>
207}
208