1 // RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
3 //===----------------------------------------------------------------------===//
5 //===----------------------------------------------------------------------===//
7 // CHECK-LABEL: @int32_scalar
8 func.func @int32_scalar(%lhs: i32, %rhs: i32) {
9 // CHECK: spirv.IAdd %{{.*}}, %{{.*}}: i32
10 %0 = arith.addi %lhs, %rhs: i32
11 // CHECK: spirv.ISub %{{.*}}, %{{.*}}: i32
12 %1 = arith.subi %lhs, %rhs: i32
13 // CHECK: spirv.IMul %{{.*}}, %{{.*}}: i32
14 %2 = arith.muli %lhs, %rhs: i32
15 // CHECK: spirv.SDiv %{{.*}}, %{{.*}}: i32
16 %3 = arith.divsi %lhs, %rhs: i32
17 // CHECK: spirv.UDiv %{{.*}}, %{{.*}}: i32
18 %4 = arith.divui %lhs, %rhs: i32
19 // CHECK: spirv.UMod %{{.*}}, %{{.*}}: i32
20 %5 = arith.remui %lhs, %rhs: i32
24 // CHECK-LABEL: @int32_scalar_srem
25 // CHECK-SAME: (%[[LHS:.+]]: i32, %[[RHS:.+]]: i32)
26 func.func @int32_scalar_srem(%lhs: i32, %rhs: i32) {
27 // CHECK: %[[LABS:.+]] = spirv.GL.SAbs %[[LHS]] : i32
28 // CHECK: %[[RABS:.+]] = spirv.GL.SAbs %[[RHS]] : i32
29 // CHECK: %[[ABS:.+]] = spirv.UMod %[[LABS]], %[[RABS]] : i32
30 // CHECK: %[[POS:.+]] = spirv.IEqual %[[LHS]], %[[LABS]] : i32
31 // CHECK: %[[NEG:.+]] = spirv.SNegate %[[ABS]] : i32
32 // CHECK: %{{.+}} = spirv.Select %[[POS]], %[[ABS]], %[[NEG]] : i1, i32
33 %0 = arith.remsi %lhs, %rhs: i32
39 //===----------------------------------------------------------------------===//
41 //===----------------------------------------------------------------------===//
43 // CHECK-LABEL: @bitwise_scalar
44 func.func @bitwise_scalar(%arg0 : i32, %arg1 : i32) {
45 // CHECK: spirv.BitwiseAnd
46 %0 = arith.andi %arg0, %arg1 : i32
47 // CHECK: spirv.BitwiseOr
48 %1 = arith.ori %arg0, %arg1 : i32
49 // CHECK: spirv.BitwiseXor
50 %2 = arith.xori %arg0, %arg1 : i32
54 // CHECK-LABEL: @bitwise_vector
55 func.func @bitwise_vector(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) {
56 // CHECK: spirv.BitwiseAnd
57 %0 = arith.andi %arg0, %arg1 : vector<4xi32>
58 // CHECK: spirv.BitwiseOr
59 %1 = arith.ori %arg0, %arg1 : vector<4xi32>
60 // CHECK: spirv.BitwiseXor
61 %2 = arith.xori %arg0, %arg1 : vector<4xi32>
65 // CHECK-LABEL: @logical_scalar
66 func.func @logical_scalar(%arg0 : i1, %arg1 : i1) {
67 // CHECK: spirv.LogicalAnd
68 %0 = arith.andi %arg0, %arg1 : i1
69 // CHECK: spirv.LogicalOr
70 %1 = arith.ori %arg0, %arg1 : i1
71 // CHECK: spirv.LogicalNotEqual
72 %2 = arith.xori %arg0, %arg1 : i1
76 // CHECK-LABEL: @logical_vector
77 func.func @logical_vector(%arg0 : vector<4xi1>, %arg1 : vector<4xi1>) {
78 // CHECK: spirv.LogicalAnd
79 %0 = arith.andi %arg0, %arg1 : vector<4xi1>
80 // CHECK: spirv.LogicalOr
81 %1 = arith.ori %arg0, %arg1 : vector<4xi1>
82 // CHECK: spirv.LogicalNotEqual
83 %2 = arith.xori %arg0, %arg1 : vector<4xi1>
87 // CHECK-LABEL: @shift_scalar
88 func.func @shift_scalar(%arg0 : i32, %arg1 : i32) {
89 // CHECK: spirv.ShiftLeftLogical
90 %0 = arith.shli %arg0, %arg1 : i32
91 // CHECK: spirv.ShiftRightArithmetic
92 %1 = arith.shrsi %arg0, %arg1 : i32
93 // CHECK: spirv.ShiftRightLogical
94 %2 = arith.shrui %arg0, %arg1 : i32
98 // CHECK-LABEL: @shift_vector
99 func.func @shift_vector(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) {
100 // CHECK: spirv.ShiftLeftLogical
101 %0 = arith.shli %arg0, %arg1 : vector<4xi32>
102 // CHECK: spirv.ShiftRightArithmetic
103 %1 = arith.shrsi %arg0, %arg1 : vector<4xi32>
104 // CHECK: spirv.ShiftRightLogical
105 %2 = arith.shrui %arg0, %arg1 : vector<4xi32>
111 //===----------------------------------------------------------------------===//
113 //===----------------------------------------------------------------------===//
115 // CHECK-LABEL: @cmpf
116 func.func @cmpf(%arg0 : f32, %arg1 : f32) {
117 // CHECK: spirv.FOrdEqual
118 %1 = arith.cmpf oeq, %arg0, %arg1 : f32
122 // CHECK-LABEL: @vec1cmpf
123 func.func @vec1cmpf(%arg0 : vector<1xf32>, %arg1 : vector<1xf32>) {
124 // CHECK: spirv.FOrdGreaterThan
125 %0 = arith.cmpf ogt, %arg0, %arg1 : vector<1xf32>
126 // CHECK: spirv.FUnordLessThan
127 %1 = arith.cmpf ult, %arg0, %arg1 : vector<1xf32>
133 //===----------------------------------------------------------------------===//
135 //===----------------------------------------------------------------------===//
137 // CHECK-LABEL: @cmpi
138 func.func @cmpi(%arg0 : i32, %arg1 : i32) {
139 // CHECK: spirv.IEqual
140 %0 = arith.cmpi eq, %arg0, %arg1 : i32
144 // CHECK-LABEL: @indexcmpi
145 func.func @indexcmpi(%arg0 : index, %arg1 : index) {
146 // CHECK: spirv.IEqual
147 %0 = arith.cmpi eq, %arg0, %arg1 : index
151 // CHECK-LABEL: @vec1cmpi
152 func.func @vec1cmpi(%arg0 : vector<1xi32>, %arg1 : vector<1xi32>) {
153 // CHECK: spirv.ULessThan
154 %0 = arith.cmpi ult, %arg0, %arg1 : vector<1xi32>
155 // CHECK: spirv.SGreaterThan
156 %1 = arith.cmpi sgt, %arg0, %arg1 : vector<1xi32>
160 // CHECK-LABEL: @boolcmpi_equality
161 func.func @boolcmpi_equality(%arg0 : i1, %arg1 : i1) {
162 // CHECK: spirv.LogicalEqual
163 %0 = arith.cmpi eq, %arg0, %arg1 : i1
164 // CHECK: spirv.LogicalNotEqual
165 %1 = arith.cmpi ne, %arg0, %arg1 : i1
169 // CHECK-LABEL: @boolcmpi_unsigned
170 func.func @boolcmpi_unsigned(%arg0 : i1, %arg1 : i1) {
171 // CHECK-COUNT-2: spirv.Select
172 // CHECK: spirv.UGreaterThanEqual
173 %0 = arith.cmpi uge, %arg0, %arg1 : i1
174 // CHECK-COUNT-2: spirv.Select
175 // CHECK: spirv.ULessThan
176 %1 = arith.cmpi ult, %arg0, %arg1 : i1
180 // CHECK-LABEL: @vec1boolcmpi_equality
181 func.func @vec1boolcmpi_equality(%arg0 : vector<1xi1>, %arg1 : vector<1xi1>) {
182 // CHECK: spirv.LogicalEqual
183 %0 = arith.cmpi eq, %arg0, %arg1 : vector<1xi1>
184 // CHECK: spirv.LogicalNotEqual
185 %1 = arith.cmpi ne, %arg0, %arg1 : vector<1xi1>
189 // CHECK-LABEL: @vec1boolcmpi_unsigned
190 func.func @vec1boolcmpi_unsigned(%arg0 : vector<1xi1>, %arg1 : vector<1xi1>) {
191 // CHECK-COUNT-2: spirv.Select
192 // CHECK: spirv.UGreaterThanEqual
193 %0 = arith.cmpi uge, %arg0, %arg1 : vector<1xi1>
194 // CHECK-COUNT-2: spirv.Select
195 // CHECK: spirv.ULessThan
196 %1 = arith.cmpi ult, %arg0, %arg1 : vector<1xi1>
200 // CHECK-LABEL: @vecboolcmpi_equality
201 func.func @vecboolcmpi_equality(%arg0 : vector<4xi1>, %arg1 : vector<4xi1>) {
202 // CHECK: spirv.LogicalEqual
203 %0 = arith.cmpi eq, %arg0, %arg1 : vector<4xi1>
204 // CHECK: spirv.LogicalNotEqual
205 %1 = arith.cmpi ne, %arg0, %arg1 : vector<4xi1>
209 // CHECK-LABEL: @vecboolcmpi_unsigned
210 func.func @vecboolcmpi_unsigned(%arg0 : vector<3xi1>, %arg1 : vector<3xi1>) {
211 // CHECK-COUNT-2: spirv.Select
212 // CHECK: spirv.UGreaterThanEqual
213 %0 = arith.cmpi uge, %arg0, %arg1 : vector<3xi1>
214 // CHECK-COUNT-2: spirv.Select
215 // CHECK: spirv.ULessThan
216 %1 = arith.cmpi ult, %arg0, %arg1 : vector<3xi1>