[PATCH] D76137: [MLIR] Add support for signed / unsigned operands for IntArithmeticOp
Andi Drebes via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 13 09:06:50 PDT 2020
andidr created this revision.
andidr added reviewers: antiagainst, rriddle, ftynse, nicolasvasilache.
Herald added subscribers: llvm-commits, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, shauheen, burmako, jpienaar, mehdi_amini.
Herald added 1 blocking reviewer(s): rriddle.
Herald added a project: LLVM.
Currently, only signless integer operands are allowed for arithmetic integer operations. This commit additionally allows for explicitly signed and explicitly unsigned integer operands.
Minimal testing on std.addi is provided.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D76137
Files:
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
mlir/include/mlir/IR/OpBase.td
mlir/test/IR/core-ops.mlir
mlir/test/IR/invalid-ops.mlir
Index: mlir/test/IR/invalid-ops.mlir
===================================================================
--- mlir/test/IR/invalid-ops.mlir
+++ mlir/test/IR/invalid-ops.mlir
@@ -186,7 +186,7 @@
func @func_with_ops(f32) {
^bb0(%a : f32):
- // expected-error at +1 {{'std.addi' op operand #0 must be signless-integer-like}}
+ // expected-error at +1 {{'std.addi' op operand #0 must be integer-like}}
%sf = addi %a, %a : f32
}
Index: mlir/test/IR/core-ops.mlir
===================================================================
--- mlir/test/IR/core-ops.mlir
+++ mlir/test/IR/core-ops.mlir
@@ -41,9 +41,9 @@
return
}
-// CHECK-LABEL: func @standard_instrs(%arg0: tensor<4x4x?xf32>, %arg1: f32, %arg2: i32, %arg3: index, %arg4: i64, %arg5: f16) {
-func @standard_instrs(tensor<4x4x?xf32>, f32, i32, index, i64, f16) {
-^bb42(%t: tensor<4x4x?xf32>, %f: f32, %i: i32, %idx : index, %j: i64, %half: f16):
+// CHECK-LABEL: func @standard_instrs(%arg0: tensor<4x4x?xf32>, %arg1: f32, %arg2: i32, %arg3: index, %arg4: i64, %arg5: f16, %arg6: si32, %arg7: ui32) {
+func @standard_instrs(tensor<4x4x?xf32>, f32, i32, index, i64, f16, si32, ui32) {
+^bb42(%t: tensor<4x4x?xf32>, %f: f32, %i: i32, %idx : index, %j: i64, %half: f16, %si: si32, %ui: ui32):
// CHECK: %0 = dim %arg0, 2 : tensor<4x4x?xf32>
%a = "std.dim"(%t){index = 2} : (tensor<4x4x?xf32>) -> index
@@ -515,6 +515,18 @@
// CHECK: %{{[0-9]+}} = rsqrt %arg1 : f32
%145 = rsqrt %f : f32
+ // CHECK: %{{[0-9]+}} = addi %arg6, %arg6 : si32
+ %146 = "std.addi"(%si, %si) : (si32,si32) -> si32
+
+ // CHECK: %{{[0-9]+}} = addi %{{[0-9]+}}, %{{[0-9]+}} : si32
+ %147 = addi %146, %146 : si32
+
+ // CHECK: %{{[0-9]+}} = addi %arg7, %arg7 : ui32
+ %148 = "std.addi"(%ui, %ui) : (ui32,ui32) -> ui32
+
+ // CHECK: %{{[0-9]+}} = addi %{{[0-9]+}}, %{{[0-9]+}} : ui32
+ %149 = addi %148, %148 : ui32
+
return
}
Index: mlir/include/mlir/IR/OpBase.td
===================================================================
--- mlir/include/mlir/IR/OpBase.td
+++ mlir/include/mlir/IR/OpBase.td
@@ -678,6 +678,14 @@
TensorOf<[I1]>.predicate]>,
"bool-like">;
+// Type constraint for integer-like types: integers, indices, vectors of
+// integers, tensors of integers.
+def IntegerLike : TypeConstraint<Or<[
+ AnyInteger.predicate, Index.predicate,
+ VectorOf<[AnyInteger]>.predicate,
+ TensorOf<[AnyInteger]>.predicate]>,
+ "integer-like">;
+
// Type constraint for signless-integer-like types: signless integers, indices,
// vectors of signless integers, tensors of signless integers.
def SignlessIntegerLike : TypeConstraint<Or<[
Index: mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
===================================================================
--- mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
+++ mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
@@ -109,7 +109,7 @@
// <op>i %0, %1 : i32
class IntArithmeticOp<string mnemonic, list<OpTrait> traits = []> :
ArithmeticOp<mnemonic, traits>,
- Arguments<(ins SignlessIntegerLike:$lhs, SignlessIntegerLike:$rhs)>;
+ Arguments<(ins IntegerLike:$lhs, IntegerLike:$rhs)>;
// Base class for standard arithmetic binary operations on floats, vectors and
// tensors thereof. This operation has two operands and returns one result,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76137.250223.patch
Type: text/x-patch
Size: 3344 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200313/3e35f843/attachment.bin>
More information about the llvm-commits
mailing list