[Mlir-commits] [mlir] [mlir][arith] Overflow semantics in documentation for muli, subi, and addi (PR #74346)
Jacob Yu
llvmlistbot at llvm.org
Mon Dec 4 14:24:21 PST 2023
https://github.com/pingshiyu updated https://github.com/llvm/llvm-project/pull/74346
>From c7573a35d447c88474c3b7dbf25cc451db2798b9 Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Mon, 4 Dec 2023 17:31:06 +0000
Subject: [PATCH 1/2] [mlir][arith] arith ops overflow semantics defined for
muli, subi, and addi
---
.../include/mlir/Dialect/Arith/IR/ArithOps.td | 28 +++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index 38cce99679e99..3c2c48180a2a2 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -200,6 +200,12 @@ def Arith_AddIOp : Arith_TotalIntBinaryOp<"addi", [Commutative]> {
a vector whose element type is integer, or a tensor of integers. It has no
standard attributes.
+ The operands are interpreted as unsigned bitvectors. The result is represented by
+ a bitvector containing the mathematical value of the addition modulo 2^n, where
+ `n` is the bitwidth. Because `arith` integers use a two's complement
+ representation, this operation is applicable on both signed and unsigned
+ integer operands.
+
Example:
```mlir
@@ -276,6 +282,17 @@ def Arith_SubIOp : Arith_TotalIntBinaryOp<"subi"> {
let summary = [{
Integer subtraction operation.
}];
+ let description = [{
+ The `subi` operation takes two operands and returns one result, each of
+ these is required to be the same type. This type may be an integer scalar type,
+ a vector whose element type is integer, or a tensor of integers. It has no
+ standard attributes.
+
+ The operands are interpreted as unsigned bitvectors. The result is represented by a
+ bitvector containing the mathematical value of the subtraction modulo 2^n, where `n`
+ is the bitwidth. Because `arith` integers use a two's complement representation, this
+ operation is applicable on both signed and unsigned integer operands.
+ }];
let hasFolder = 1;
let hasCanonicalizer = 1;
}
@@ -288,6 +305,17 @@ def Arith_MulIOp : Arith_TotalIntBinaryOp<"muli", [Commutative]> {
let summary = [{
Integer multiplication operation.
}];
+ let description = [{
+ The `muli` operation takes two operands and returns one result, each of
+ these is required to be the same type. This type may be an integer scalar type,
+ a vector whose element type is integer, or a tensor of integers. It has no
+ standard attributes.
+
+ The operands are interpreted as unsigned bitvectors. The result is represented by a
+ bitvector containing the mathematical value of the multiplication modulo 2^n, where `n`
+ is the bitwidth. Because `arith` integers use a two's complement representation, this
+ operation is applicable on both signed and unsigned integer operands.
+ }];
let hasFolder = 1;
let hasCanonicalizer = 1;
}
>From d3e30dff18802d7d0d194ecfcdcbd8a8eeb3014f Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Mon, 4 Dec 2023 22:24:08 +0000
Subject: [PATCH 2/2] added some phrasing to bring in line with the extended
versions
---
.../include/mlir/Dialect/Arith/IR/ArithOps.td | 40 ++++++++++---------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index 3c2c48180a2a2..72ce9699dddb1 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -195,17 +195,17 @@ def Arith_ConstantOp : Op<Arith_Dialect, "constant",
def Arith_AddIOp : Arith_TotalIntBinaryOp<"addi", [Commutative]> {
let summary = "integer addition operation";
let description = [{
+ Performs N-bit addition on the operands. The operands are interpreted as
+ unsigned bitvectors. The result is represented by a bitvector containing the
+ mathematical value of the addition modulo 2^n, where `n` is the bitwidth.
+ Because `arith` integers use a two's complement representation, this operation
+ is applicable on both signed and unsigned integer operands.
+
The `addi` operation takes two operands and returns one result, each of
these is required to be the same type. This type may be an integer scalar type,
a vector whose element type is integer, or a tensor of integers. It has no
standard attributes.
- The operands are interpreted as unsigned bitvectors. The result is represented by
- a bitvector containing the mathematical value of the addition modulo 2^n, where
- `n` is the bitwidth. Because `arith` integers use a two's complement
- representation, this operation is applicable on both signed and unsigned
- integer operands.
-
Example:
```mlir
@@ -236,7 +236,7 @@ def Arith_AddUIExtendedOp : Arith_Op<"addui_extended", [Pure, Commutative,
let description = [{
Performs (N+1)-bit addition on zero-extended operands. Returns two results:
the N-bit sum (same type as both operands), and the overflow bit
- (boolean-like), where`1` indicates unsigned addition overflow, while `0`
+ (boolean-like), where `1` indicates unsigned addition overflow, while `0`
indicates no overflow.
Example:
@@ -282,16 +282,17 @@ def Arith_SubIOp : Arith_TotalIntBinaryOp<"subi"> {
let summary = [{
Integer subtraction operation.
}];
- let description = [{
+ let description = [{
+ Performs N-bit subtraction on the operands. The operands are interpreted as unsigned
+ bitvectors. The result is represented by a bitvector containing the mathematical
+ value of the subtraction modulo 2^n, where `n` is the bitwidth. Because `arith`
+ integers use a two's complement representation, this operation is applicable on
+ both signed and unsigned integer operands.
+
The `subi` operation takes two operands and returns one result, each of
these is required to be the same type. This type may be an integer scalar type,
a vector whose element type is integer, or a tensor of integers. It has no
standard attributes.
-
- The operands are interpreted as unsigned bitvectors. The result is represented by a
- bitvector containing the mathematical value of the subtraction modulo 2^n, where `n`
- is the bitwidth. Because `arith` integers use a two's complement representation, this
- operation is applicable on both signed and unsigned integer operands.
}];
let hasFolder = 1;
let hasCanonicalizer = 1;
@@ -306,15 +307,16 @@ def Arith_MulIOp : Arith_TotalIntBinaryOp<"muli", [Commutative]> {
Integer multiplication operation.
}];
let description = [{
+ Performs N-bit multiplication on the operands. The operands are interpreted as
+ unsigned bitvectors. The result is represented by a bitvector containing the
+ mathematical value of the multiplication modulo 2^n, where `n` is the bitwidth.
+ Because `arith` integers use a two's complement representation, this operation is
+ applicable on both signed and unsigned integer operands.
+
The `muli` operation takes two operands and returns one result, each of
these is required to be the same type. This type may be an integer scalar type,
a vector whose element type is integer, or a tensor of integers. It has no
- standard attributes.
-
- The operands are interpreted as unsigned bitvectors. The result is represented by a
- bitvector containing the mathematical value of the multiplication modulo 2^n, where `n`
- is the bitwidth. Because `arith` integers use a two's complement representation, this
- operation is applicable on both signed and unsigned integer operands.
+ standard attributes.
}];
let hasFolder = 1;
let hasCanonicalizer = 1;
More information about the Mlir-commits
mailing list