[Mlir-commits] [mlir] [mlir][arith] doc updates for ub semantics, and int representations (PR #72932)

Jacob Yu llvmlistbot at llvm.org
Tue Nov 21 07:18:10 PST 2023


https://github.com/pingshiyu updated https://github.com/llvm/llvm-project/pull/72932

>From b699c27bf79f52c44060bfdf87e3b0c76fc4c29a Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Mon, 20 Nov 2023 21:22:40 +0000
Subject: [PATCH 01/15] [mlir][arith] doc updates for ub semantics, and int
 representations

---
 .../mlir/Dialect/Arith/IR/ArithBase.td        |  6 +-
 .../include/mlir/Dialect/Arith/IR/ArithOps.td | 75 ++++++++++++-------
 2 files changed, 53 insertions(+), 28 deletions(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
index 133af893e4efa74..240e49cfb13d73b 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
@@ -19,7 +19,11 @@ def Arith_Dialect : Dialect {
     The arith dialect is intended to hold basic integer and floating point
     mathematical operations. This includes unary, binary, and ternary arithmetic
     ops, bitwise and shift ops, cast ops, and compare ops. Operations in this
-    dialect also accept vectors and tensors of integers or floats.
+    dialect also accept vectors and tensors of integers or floats. The dialect
+    assumes unsigned integers are represented by bitvectors, and signed integers 
+    are represented by bitvectors with a two's complement representation. Unless 
+    otherwise stated, the operations within this dialect will propagate poison 
+    values (if any of its inputs are poison, then the output is poison). 
   }];
 
   let hasConstantMaterializer = 1;
diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index 58e5385bf3ff268..836606d62554d89 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -198,7 +198,9 @@ def Arith_AddIOp : Arith_TotalIntBinaryOp<"addi", [Commutative]> {
     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.
+    has no standard attributes. If an overflow occurs, the result is the 
+    mathematical value of the addition modulo 2^n, where `n` is the width of
+    the integer type. 
 
     Example:
 
@@ -273,7 +275,11 @@ def Arith_AddUIExtendedOp : Arith_Op<"addui_extended", [Pure, Commutative,
 //===----------------------------------------------------------------------===//
 
 def Arith_SubIOp : Arith_TotalIntBinaryOp<"subi"> {
-  let summary = "integer subtraction operation";
+  let summary = [{
+    integer subtraction operation. If an overflow occurs, the result is the 
+    mathematical value of the addition modulo 2^n, where `n` is the width of
+    the integer type. 
+  }];
   let hasFolder = 1;
   let hasCanonicalizer = 1;
 }
@@ -283,7 +289,11 @@ def Arith_SubIOp : Arith_TotalIntBinaryOp<"subi"> {
 //===----------------------------------------------------------------------===//
 
 def Arith_MulIOp : Arith_TotalIntBinaryOp<"muli", [Commutative]> {
-  let summary = "integer multiplication operation";
+  let summary = [{
+    integer multiplication operation. If an overflow occurs, the result is the 
+    mathematical value of the addition modulo 2^n, where `n` is the width of
+    the integer type. 
+  }];
   let hasFolder = 1;
   let hasCanonicalizer = 1;
 }
@@ -420,8 +430,8 @@ def Arith_DivSIOp : Arith_IntBinaryOp<"divsi", [ConditionallySpeculatable]> {
     Signed integer division. Rounds towards zero. Treats the leading bit as
     sign, i.e. `6 / -2 = -3`.
 
-    Note: the semantics of division by zero or signed division overflow (minimum
-    value divided by -1) is TBD; do NOT assume any specific behavior.
+    Divison by zero, or signed division overflow (minimum value divided by -1) 
+    is undefined behaviour.
 
     Example:
 
@@ -457,8 +467,7 @@ def Arith_CeilDivUIOp : Arith_IntBinaryOp<"ceildivui",
     leading bit as the most significant, i.e. for `i16` given two's complement
     representation, `6 / -2 = 6 / (2^16 - 2) = 1`.
 
-    Note: the semantics of division by zero is TBD; do NOT assume any specific
-    behavior.
+    Division by zero is undefined behaviour.
 
     Example:
 
@@ -486,8 +495,8 @@ def Arith_CeilDivSIOp : Arith_IntBinaryOp<"ceildivsi",
   let description = [{
     Signed integer division. Rounds towards positive infinity, i.e. `7 / -2 = -3`.
 
-    Note: the semantics of division by zero or signed division overflow (minimum
-    value divided by -1) is TBD; do NOT assume any specific behavior.
+    Divison by zero, or signed division overflow (minimum value divided by -1) 
+    is undefined behaviour.
 
     Example:
 
@@ -514,8 +523,8 @@ def Arith_FloorDivSIOp : Arith_TotalIntBinaryOp<"floordivsi"> {
   let description = [{
     Signed integer division. Rounds towards negative infinity, i.e. `5 / -2 = -3`.
 
-    Note: the semantics of division by zero or signed division overflow (minimum
-    value divided by -1) is TBD; do NOT assume any specific behavior.
+    Divison by zero, or signed division overflow (minimum value divided by -1) 
+    is undefined behaviour.
 
     Example:
 
@@ -538,8 +547,7 @@ def Arith_RemUIOp : Arith_TotalIntBinaryOp<"remui"> {
     Unsigned integer division remainder. Treats the leading bit as the most
     significant, i.e. for `i16`, `6 % -2 = 6 % (2^16 - 2) = 6`.
 
-    Note: the semantics of division by zero is TBD; do NOT assume any specific
-    behavior.
+    Division by zero is undefined behaviour.
 
     Example:
 
@@ -567,8 +575,7 @@ def Arith_RemSIOp : Arith_TotalIntBinaryOp<"remsi"> {
     Signed integer division remainder. Treats the leading bit as sign, i.e. `6 %
     -2 = 0`.
 
-    Note: the semantics of division by zero is TBD; do NOT assume any specific
-    behavior.
+    Division by zero is undefined behaviour.
 
     Example:
 
@@ -680,8 +687,11 @@ def Arith_XOrIOp : Arith_TotalIntBinaryOp<"xori", [Commutative]> {
 def Arith_ShLIOp : Arith_TotalIntBinaryOp<"shli"> {
   let summary = "integer left-shift";
   let description = [{
-    The `shli` operation shifts an integer value to the left by a variable
-    amount. The low order bits are filled with zeros.
+    The `shli` operation shifts the integer value of the first operand to the left 
+    by the integer value of the second operand. The second operand is interpreted as 
+    unsigned. The low order bits are filled with zeros. If the value of the second 
+    operand is greater than the number of bits in the first operand, then the 
+    operation returns a poison.
 
     Example:
 
@@ -701,9 +711,11 @@ def Arith_ShLIOp : Arith_TotalIntBinaryOp<"shli"> {
 def Arith_ShRUIOp : Arith_TotalIntBinaryOp<"shrui"> {
   let summary = "unsigned integer right-shift";
   let description = [{
-    The `shrui` operation shifts an integer value to the right by a variable
-    amount. The integer is interpreted as unsigned. The high order bits are
-    always filled with zeros.
+    The `shrui` operation shifts an integer value of the first operand to the right 
+    by the value of the second operand. The first operand is interpreted as unsigned,
+    and the second operand is interpreted as unsigned. The high order bits are always 
+    filled with zeros. If the value of the second operand is greater than the number 
+    of bits in the first operand, then the operation returns poison.
 
     Example:
 
@@ -723,10 +735,13 @@ def Arith_ShRUIOp : Arith_TotalIntBinaryOp<"shrui"> {
 def Arith_ShRSIOp : Arith_TotalIntBinaryOp<"shrsi"> {
   let summary = "signed integer right-shift";
   let description = [{
-    The `shrsi` operation shifts an integer value to the right by a variable
-    amount. The integer is interpreted as signed. The high order bits in the
-    output are filled with copies of the most-significant bit of the shifted
-    value (which means that the sign of the value is preserved).
+    The `shrsi` operation shifts an integer value of the first operand to the right 
+    by the value of the second operand. The first operand is interpreted as signed, 
+    and the second operand is interpreter as unsigned. The high order bits in the 
+    output are filled with copies of the most-significant bit of the shifted value 
+    (which means that the sign of the value is preserved). If the value of the second 
+    operand is greater than the number of bits in the first operand, then the 
+    operation returns poison.
 
     Example:
 
@@ -1422,9 +1437,15 @@ def SelectOp : Arith_Op<"select", [Pure,
   let summary = "select operation";
   let description = [{
     The `arith.select` operation chooses one value based on a binary condition
-    supplied as its first operand. If the value of the first operand is `1`,
-    the second operand is chosen, otherwise the third operand is chosen.
-    The second and the third operand must have the same type.
+    supplied as its first operand. 
+    
+    If the value of the first operand is `1`, then the second operand is returned, 
+    and the third operand is ignored, even if it were poison. 
+    
+    If the value of the first operand is `0`, then the third operand is returned, 
+    and the second operand is ignored, even if it were poison. 
+    
+    If the value of the first operand is poison, then the operation returns poison. 
 
     The operation applies to vectors and tensors elementwise given the _shape_
     of all operands is identical. The choice is made for each element

>From a4f22f77a8759f01a5602da7be3cf953147bb930 Mon Sep 17 00:00:00 2001
From: Jacob Yu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 11:27:50 +0000
Subject: [PATCH 02/15] Update mlir/include/mlir/Dialect/Arith/IR/ArithBase.td

Co-authored-by: Jakub Kuderski <kubakuderski at gmail.com>
---
 mlir/include/mlir/Dialect/Arith/IR/ArithBase.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
index 240e49cfb13d73b..72609112d80472f 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
@@ -22,8 +22,8 @@ def Arith_Dialect : Dialect {
     dialect also accept vectors and tensors of integers or floats. The dialect
     assumes unsigned integers are represented by bitvectors, and signed integers 
     are represented by bitvectors with a two's complement representation. Unless 
-    otherwise stated, the operations within this dialect will propagate poison 
-    values (if any of its inputs are poison, then the output is poison). 
+    otherwise stated, the operations within this dialect propagate poison 
+    values, i.e., if any of its inputs are poison, then the output is poison).
   }];
 
   let hasConstantMaterializer = 1;

>From e3efd631598cd5c45e3d9156382433584b006824 Mon Sep 17 00:00:00 2001
From: Jacob Yu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 11:28:21 +0000
Subject: [PATCH 03/15] Update mlir/include/mlir/Dialect/Arith/IR/ArithOps.td

Co-authored-by: Jakub Kuderski <kubakuderski at gmail.com>
---
 mlir/include/mlir/Dialect/Arith/IR/ArithOps.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index 836606d62554d89..dede4ef14e86152 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -276,7 +276,7 @@ def Arith_AddUIExtendedOp : Arith_Op<"addui_extended", [Pure, Commutative,
 
 def Arith_SubIOp : Arith_TotalIntBinaryOp<"subi"> {
   let summary = [{
-    integer subtraction operation. If an overflow occurs, the result is the 
+    Integer subtraction operation. If an overflow occurs, the result is the 
     mathematical value of the addition modulo 2^n, where `n` is the width of
     the integer type. 
   }];

>From db0f817cb9aff04d3f805f69d77dd561a2b5231e Mon Sep 17 00:00:00 2001
From: Jacob Yu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 11:29:15 +0000
Subject: [PATCH 04/15] Update mlir/include/mlir/Dialect/Arith/IR/ArithOps.td

Co-authored-by: Jakub Kuderski <kubakuderski at gmail.com>
---
 mlir/include/mlir/Dialect/Arith/IR/ArithOps.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index dede4ef14e86152..879097ce25f5a28 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -290,7 +290,7 @@ def Arith_SubIOp : Arith_TotalIntBinaryOp<"subi"> {
 
 def Arith_MulIOp : Arith_TotalIntBinaryOp<"muli", [Commutative]> {
   let summary = [{
-    integer multiplication operation. If an overflow occurs, the result is the 
+    Integer multiplication operation. If an overflow occurs, the result is the 
     mathematical value of the addition modulo 2^n, where `n` is the width of
     the integer type. 
   }];

>From e07c27481c00f9606e4efcddf04c5824be4e607d Mon Sep 17 00:00:00 2001
From: Jacob Yu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 11:29:29 +0000
Subject: [PATCH 05/15] Update mlir/include/mlir/Dialect/Arith/IR/ArithOps.td

Co-authored-by: Jakub Kuderski <kubakuderski at gmail.com>
---
 mlir/include/mlir/Dialect/Arith/IR/ArithOps.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index 879097ce25f5a28..0a0bbc0654df912 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -1439,7 +1439,7 @@ def SelectOp : Arith_Op<"select", [Pure,
     The `arith.select` operation chooses one value based on a binary condition
     supplied as its first operand. 
     
-    If the value of the first operand is `1`, then the second operand is returned, 
+    If the value of the first operand (the condition) is `1`, then the second operand is returned, 
     and the third operand is ignored, even if it were poison. 
     
     If the value of the first operand is `0`, then the third operand is returned, 

>From f3477943c247a4e86dfe75ac61f31998890cfea4 Mon Sep 17 00:00:00 2001
From: Jacob Yu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 11:30:40 +0000
Subject: [PATCH 06/15] Update mlir/include/mlir/Dialect/Arith/IR/ArithOps.td

Co-authored-by: Jakub Kuderski <kubakuderski at gmail.com>
---
 mlir/include/mlir/Dialect/Arith/IR/ArithOps.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index 0a0bbc0654df912..5e431f129ca5d19 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -690,7 +690,7 @@ def Arith_ShLIOp : Arith_TotalIntBinaryOp<"shli"> {
     The `shli` operation shifts the integer value of the first operand to the left 
     by the integer value of the second operand. The second operand is interpreted as 
     unsigned. The low order bits are filled with zeros. If the value of the second 
-    operand is greater than the number of bits in the first operand, then the 
+    operand is greater than the bitwidth of the first operand, then the 
     operation returns a poison.
 
     Example:

>From 92c889db869fda8713031fad118afc4b5c3b9d0d Mon Sep 17 00:00:00 2001
From: Jacob Yu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 12:01:08 +0000
Subject: [PATCH 07/15] Update mlir/include/mlir/Dialect/Arith/IR/ArithOps.td

Co-authored-by: Jakub Kuderski <kubakuderski at gmail.com>
---
 mlir/include/mlir/Dialect/Arith/IR/ArithOps.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index 5e431f129ca5d19..d9210d9e996602a 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -1440,7 +1440,7 @@ def SelectOp : Arith_Op<"select", [Pure,
     supplied as its first operand. 
     
     If the value of the first operand (the condition) is `1`, then the second operand is returned, 
-    and the third operand is ignored, even if it were poison. 
+    and the third operand is ignored, even if it was poison. 
     
     If the value of the first operand is `0`, then the third operand is returned, 
     and the second operand is ignored, even if it were poison. 

>From 6d9d316e858cfc50642fe1ed9ffa4d2ee60993de Mon Sep 17 00:00:00 2001
From: Jacob Yu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 12:01:17 +0000
Subject: [PATCH 08/15] Update mlir/include/mlir/Dialect/Arith/IR/ArithOps.td

Co-authored-by: Jakub Kuderski <kubakuderski at gmail.com>
---
 mlir/include/mlir/Dialect/Arith/IR/ArithOps.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index d9210d9e996602a..e30befb0abfb470 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -1442,7 +1442,7 @@ def SelectOp : Arith_Op<"select", [Pure,
     If the value of the first operand (the condition) is `1`, then the second operand is returned, 
     and the third operand is ignored, even if it was poison. 
     
-    If the value of the first operand is `0`, then the third operand is returned, 
+    If the value of the first operand (the condition) is `0`, then the third operand is returned, 
     and the second operand is ignored, even if it were poison. 
     
     If the value of the first operand is poison, then the operation returns poison. 

>From 2520e1c7094d4304368a2dc7dbeeb447fd7530b0 Mon Sep 17 00:00:00 2001
From: Jacob Yu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 12:01:24 +0000
Subject: [PATCH 09/15] Update mlir/include/mlir/Dialect/Arith/IR/ArithOps.td

Co-authored-by: Jakub Kuderski <kubakuderski at gmail.com>
---
 mlir/include/mlir/Dialect/Arith/IR/ArithOps.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index e30befb0abfb470..1b335186b193b76 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -1443,7 +1443,7 @@ def SelectOp : Arith_Op<"select", [Pure,
     and the third operand is ignored, even if it was poison. 
     
     If the value of the first operand (the condition) is `0`, then the third operand is returned, 
-    and the second operand is ignored, even if it were poison. 
+    and the second operand is ignored, even if it was poison. 
     
     If the value of the first operand is poison, then the operation returns poison. 
 

>From a66ee6b628be82ad1fd238215f842eece59885dd Mon Sep 17 00:00:00 2001
From: Jacob Yu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 12:01:31 +0000
Subject: [PATCH 10/15] Update mlir/include/mlir/Dialect/Arith/IR/ArithOps.td

Co-authored-by: Jakub Kuderski <kubakuderski at gmail.com>
---
 mlir/include/mlir/Dialect/Arith/IR/ArithOps.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index 1b335186b193b76..e86a2c9d09c7216 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -1445,7 +1445,7 @@ def SelectOp : Arith_Op<"select", [Pure,
     If the value of the first operand (the condition) is `0`, then the third operand is returned, 
     and the second operand is ignored, even if it was poison. 
     
-    If the value of the first operand is poison, then the operation returns poison. 
+    If the value of the first operand (the condition) is poison, then the operation returns poison. 
 
     The operation applies to vectors and tensors elementwise given the _shape_
     of all operands is identical. The choice is made for each element

>From 38fe3b7ec1195a5ba1585e6a971712352fc8ad39 Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 14:55:26 +0000
Subject: [PATCH 11/15] [mlir][arith] pr suggestions adopted for overflows,
 descriptions, vectors

---
 .../mlir/Dialect/Arith/IR/ArithBase.td        |  9 ++-
 .../include/mlir/Dialect/Arith/IR/ArithOps.td | 77 +++++++++++--------
 2 files changed, 52 insertions(+), 34 deletions(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
index 72609112d80472f..d84c25cfd13ba89 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
@@ -20,10 +20,11 @@ def Arith_Dialect : Dialect {
     mathematical operations. This includes unary, binary, and ternary arithmetic
     ops, bitwise and shift ops, cast ops, and compare ops. Operations in this
     dialect also accept vectors and tensors of integers or floats. The dialect
-    assumes unsigned integers are represented by bitvectors, and signed integers 
-    are represented by bitvectors with a two's complement representation. Unless 
-    otherwise stated, the operations within this dialect propagate poison 
-    values, i.e., if any of its inputs are poison, then the output is poison).
+    assumes integers are represented by bitvectors with a two's complement 
+    representation. Unless otherwise stated, the operations within this dialect 
+    propagate poison values, i.e., if any of its inputs are poison, then the 
+    output is poison. Unless otherwise stated, operatiosn applied to `vector` 
+    and tensor` values propagates poison elementwise.
   }];
 
   let hasConstantMaterializer = 1;
diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index e86a2c9d09c7216..b905f48e3957af4 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -196,11 +196,10 @@ def Arith_AddIOp : Arith_TotalIntBinaryOp<"addi", [Commutative]> {
   let summary = "integer addition operation";
   let description = [{
     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. If an overflow occurs, the result is the 
-    mathematical value of the addition modulo 2^n, where `n` is the width of
-    the integer type. 
+    these is required to be the same type. The result is the mathematical value 
+    of the addition modulo 2^n, where `n` is the bitwidth. 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. If an overflow occurs, 
 
     Example:
 
@@ -276,9 +275,11 @@ def Arith_AddUIExtendedOp : Arith_Op<"addui_extended", [Pure, Commutative,
 
 def Arith_SubIOp : Arith_TotalIntBinaryOp<"subi"> {
   let summary = [{
-    Integer subtraction operation. If an overflow occurs, the result is the 
-    mathematical value of the addition modulo 2^n, where `n` is the width of
-    the integer type. 
+    Integer subtraction operation.
+  }];
+  let description = [{
+    The result is the mathematical value of the subtraction modulo 2^n, where 
+    `n` is the bitwidth.
   }];
   let hasFolder = 1;
   let hasCanonicalizer = 1;
@@ -290,10 +291,12 @@ def Arith_SubIOp : Arith_TotalIntBinaryOp<"subi"> {
 
 def Arith_MulIOp : Arith_TotalIntBinaryOp<"muli", [Commutative]> {
   let summary = [{
-    Integer multiplication operation. If an overflow occurs, the result is the 
-    mathematical value of the addition modulo 2^n, where `n` is the width of
-    the integer type. 
+    Integer multiplication operation.
   }];
+  let description = [{
+    The result is the mathematical value of the multiplication modulo 2^n, 
+    where `n` is the bitwidth.
+  }]
   let hasFolder = 1;
   let hasCanonicalizer = 1;
 }
@@ -395,8 +398,9 @@ def Arith_DivUIOp : Arith_IntBinaryOp<"divui", [ConditionallySpeculatable]> {
     the most significant, i.e. for `i16` given two's complement representation,
     `6 / -2 = 6 / (2^16 - 2) = 0`.
 
-    Note: the semantics of division by zero is TBD; do NOT assume any specific
-    behavior.
+    Division by zero is undefined behaviour. When applied to `vector` and 
+    `tensor` values, the result is undefined if _any_ elements are divided by 
+    zero.
 
     Example:
 
@@ -431,7 +435,9 @@ def Arith_DivSIOp : Arith_IntBinaryOp<"divsi", [ConditionallySpeculatable]> {
     sign, i.e. `6 / -2 = -3`.
 
     Divison by zero, or signed division overflow (minimum value divided by -1) 
-    is undefined behaviour.
+    is undefined behaviour. When applied to `vector` and `tensor` values, the 
+    result is undefined if _any_ of its elements are divided by zero or has a 
+    signed division overflow.
 
     Example:
 
@@ -465,9 +471,11 @@ def Arith_CeilDivUIOp : Arith_IntBinaryOp<"ceildivui",
   let description = [{
     Unsigned integer division. Rounds towards positive infinity. Treats the
     leading bit as the most significant, i.e. for `i16` given two's complement
-    representation, `6 / -2 = 6 / (2^16 - 2) = 1`.
+    representation, `6 / -2 = 6 / (2^16 - 2) = 1`. 
 
-    Division by zero is undefined behaviour.
+    Division by zero is undefined behaviour. When applied to `vector` and 
+    `tensor` values, the result is undefined if _any_ elements are divided by 
+    zero.
 
     Example:
 
@@ -496,7 +504,9 @@ def Arith_CeilDivSIOp : Arith_IntBinaryOp<"ceildivsi",
     Signed integer division. Rounds towards positive infinity, i.e. `7 / -2 = -3`.
 
     Divison by zero, or signed division overflow (minimum value divided by -1) 
-    is undefined behaviour.
+    is undefined behaviour. When applied to `vector` and `tensor` values, the 
+    result is undefined if _any_ of its elements are divided by zero or has a 
+    signed division overflow.
 
     Example:
 
@@ -524,7 +534,9 @@ def Arith_FloorDivSIOp : Arith_TotalIntBinaryOp<"floordivsi"> {
     Signed integer division. Rounds towards negative infinity, i.e. `5 / -2 = -3`.
 
     Divison by zero, or signed division overflow (minimum value divided by -1) 
-    is undefined behaviour.
+    is undefined behaviour. When applied to `vector` and `tensor` values, the 
+    result is undefined if _any_ of its elements are divided by zero or has a 
+    signed division overflow.
 
     Example:
 
@@ -547,7 +559,9 @@ def Arith_RemUIOp : Arith_TotalIntBinaryOp<"remui"> {
     Unsigned integer division remainder. Treats the leading bit as the most
     significant, i.e. for `i16`, `6 % -2 = 6 % (2^16 - 2) = 6`.
 
-    Division by zero is undefined behaviour.
+    Division by zero is undefined behaviour. When applied to `vector` and 
+    `tensor` values, the result is undefined if _any_ elements are divided by 
+    zero.
 
     Example:
 
@@ -575,7 +589,9 @@ def Arith_RemSIOp : Arith_TotalIntBinaryOp<"remsi"> {
     Signed integer division remainder. Treats the leading bit as sign, i.e. `6 %
     -2 = 0`.
 
-    Division by zero is undefined behaviour.
+    Division by zero is undefined behaviour. When applied to `vector` and 
+    `tensor` values, the result is undefined if _any_ elements are divided by 
+    zero.
 
     Example:
 
@@ -691,7 +707,7 @@ def Arith_ShLIOp : Arith_TotalIntBinaryOp<"shli"> {
     by the integer value of the second operand. The second operand is interpreted as 
     unsigned. The low order bits are filled with zeros. If the value of the second 
     operand is greater than the bitwidth of the first operand, then the 
-    operation returns a poison.
+    operation returns poison.
 
     Example:
 
@@ -714,8 +730,8 @@ def Arith_ShRUIOp : Arith_TotalIntBinaryOp<"shrui"> {
     The `shrui` operation shifts an integer value of the first operand to the right 
     by the value of the second operand. The first operand is interpreted as unsigned,
     and the second operand is interpreted as unsigned. The high order bits are always 
-    filled with zeros. If the value of the second operand is greater than the number 
-    of bits in the first operand, then the operation returns poison.
+    filled with zeros. If the value of the second operand is greater than the bitwidth
+    of the first operand, then the operation returns poison.
 
     Example:
 
@@ -740,8 +756,8 @@ def Arith_ShRSIOp : Arith_TotalIntBinaryOp<"shrsi"> {
     and the second operand is interpreter as unsigned. The high order bits in the 
     output are filled with copies of the most-significant bit of the shifted value 
     (which means that the sign of the value is preserved). If the value of the second 
-    operand is greater than the number of bits in the first operand, then the 
-    operation returns poison.
+    operand is greater than bitwidth of the first operand, then the operation returns 
+    poison.
 
     Example:
 
@@ -1439,13 +1455,14 @@ def SelectOp : Arith_Op<"select", [Pure,
     The `arith.select` operation chooses one value based on a binary condition
     supplied as its first operand. 
     
-    If the value of the first operand (the condition) is `1`, then the second operand is returned, 
-    and the third operand is ignored, even if it was poison. 
+    If the value of the first operand (the condition) is `1`, then the second 
+    operand is returned, and the third operand is ignored, even if it was poison. 
     
-    If the value of the first operand (the condition) is `0`, then the third operand is returned, 
-    and the second operand is ignored, even if it was poison. 
+    If the value of the first operand (the condition) is `0`, then the third 
+    operand is returned, and the second operand is ignored, even if it was poison. 
     
-    If the value of the first operand (the condition) is poison, then the operation returns poison. 
+    If the value of the first operand (the condition) is poison, then the 
+    operation returns poison. 
 
     The operation applies to vectors and tensors elementwise given the _shape_
     of all operands is identical. The choice is made for each element

>From b3297aab6ad89a201c9da1514396fa9c8559e3ef Mon Sep 17 00:00:00 2001
From: Jacob Yu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 14:59:20 +0000
Subject: [PATCH 12/15] Update mlir/include/mlir/Dialect/Arith/IR/ArithBase.td

Co-authored-by: Fehr Mathieu <mathieu.fehr at gmail.com>
---
 mlir/include/mlir/Dialect/Arith/IR/ArithBase.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
index d84c25cfd13ba89..71bffa1591310a6 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
@@ -23,7 +23,7 @@ def Arith_Dialect : Dialect {
     assumes integers are represented by bitvectors with a two's complement 
     representation. Unless otherwise stated, the operations within this dialect 
     propagate poison values, i.e., if any of its inputs are poison, then the 
-    output is poison. Unless otherwise stated, operatiosn applied to `vector` 
+    output is poison. Unless otherwise stated, operations applied to `vector` 
     and tensor` values propagates poison elementwise.
   }];
 

>From 74715070381988b139155a438e8f52811b9a2703 Mon Sep 17 00:00:00 2001
From: Jacob Yu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 14:59:30 +0000
Subject: [PATCH 13/15] Update mlir/include/mlir/Dialect/Arith/IR/ArithBase.td

Co-authored-by: Fehr Mathieu <mathieu.fehr at gmail.com>
---
 mlir/include/mlir/Dialect/Arith/IR/ArithBase.td | 2 +-
 mlir/include/mlir/Dialect/Arith/IR/ArithOps.td  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
index 71bffa1591310a6..1e4061392b22d48 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
@@ -24,7 +24,7 @@ def Arith_Dialect : Dialect {
     representation. Unless otherwise stated, the operations within this dialect 
     propagate poison values, i.e., if any of its inputs are poison, then the 
     output is poison. Unless otherwise stated, operations applied to `vector` 
-    and tensor` values propagates poison elementwise.
+    and `tensor` values propagates poison elementwise.
   }];
 
   let hasConstantMaterializer = 1;
diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index b905f48e3957af4..d47ebc6598bdd42 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -199,7 +199,7 @@ def Arith_AddIOp : Arith_TotalIntBinaryOp<"addi", [Commutative]> {
     these is required to be the same type. The result is the mathematical value 
     of the addition modulo 2^n, where `n` is the bitwidth. 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. If an overflow occurs, 
+    integers. It has no standard attributes.
 
     Example:
 

>From 5d7182919a4e07cb706ab75facf54029da69147a Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 15:07:20 +0000
Subject: [PATCH 14/15] [mlir][arith] grepped behaviour -> behavior

---
 mlir/include/mlir/Dialect/Arith/IR/ArithOps.td | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index d47ebc6598bdd42..10d9d65c4346114 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -398,7 +398,7 @@ def Arith_DivUIOp : Arith_IntBinaryOp<"divui", [ConditionallySpeculatable]> {
     the most significant, i.e. for `i16` given two's complement representation,
     `6 / -2 = 6 / (2^16 - 2) = 0`.
 
-    Division by zero is undefined behaviour. When applied to `vector` and 
+    Division by zero is undefined behavior. When applied to `vector` and 
     `tensor` values, the result is undefined if _any_ elements are divided by 
     zero.
 
@@ -435,7 +435,7 @@ def Arith_DivSIOp : Arith_IntBinaryOp<"divsi", [ConditionallySpeculatable]> {
     sign, i.e. `6 / -2 = -3`.
 
     Divison by zero, or signed division overflow (minimum value divided by -1) 
-    is undefined behaviour. When applied to `vector` and `tensor` values, the 
+    is undefined behavior. When applied to `vector` and `tensor` values, the 
     result is undefined if _any_ of its elements are divided by zero or has a 
     signed division overflow.
 
@@ -473,7 +473,7 @@ def Arith_CeilDivUIOp : Arith_IntBinaryOp<"ceildivui",
     leading bit as the most significant, i.e. for `i16` given two's complement
     representation, `6 / -2 = 6 / (2^16 - 2) = 1`. 
 
-    Division by zero is undefined behaviour. When applied to `vector` and 
+    Division by zero is undefined behavior. When applied to `vector` and 
     `tensor` values, the result is undefined if _any_ elements are divided by 
     zero.
 
@@ -504,7 +504,7 @@ def Arith_CeilDivSIOp : Arith_IntBinaryOp<"ceildivsi",
     Signed integer division. Rounds towards positive infinity, i.e. `7 / -2 = -3`.
 
     Divison by zero, or signed division overflow (minimum value divided by -1) 
-    is undefined behaviour. When applied to `vector` and `tensor` values, the 
+    is undefined behavior. When applied to `vector` and `tensor` values, the 
     result is undefined if _any_ of its elements are divided by zero or has a 
     signed division overflow.
 
@@ -534,7 +534,7 @@ def Arith_FloorDivSIOp : Arith_TotalIntBinaryOp<"floordivsi"> {
     Signed integer division. Rounds towards negative infinity, i.e. `5 / -2 = -3`.
 
     Divison by zero, or signed division overflow (minimum value divided by -1) 
-    is undefined behaviour. When applied to `vector` and `tensor` values, the 
+    is undefined behavior. When applied to `vector` and `tensor` values, the 
     result is undefined if _any_ of its elements are divided by zero or has a 
     signed division overflow.
 
@@ -559,7 +559,7 @@ def Arith_RemUIOp : Arith_TotalIntBinaryOp<"remui"> {
     Unsigned integer division remainder. Treats the leading bit as the most
     significant, i.e. for `i16`, `6 % -2 = 6 % (2^16 - 2) = 6`.
 
-    Division by zero is undefined behaviour. When applied to `vector` and 
+    Division by zero is undefined behavior. When applied to `vector` and 
     `tensor` values, the result is undefined if _any_ elements are divided by 
     zero.
 
@@ -589,7 +589,7 @@ def Arith_RemSIOp : Arith_TotalIntBinaryOp<"remsi"> {
     Signed integer division remainder. Treats the leading bit as sign, i.e. `6 %
     -2 = 0`.
 
-    Division by zero is undefined behaviour. When applied to `vector` and 
+    Division by zero is undefined behavior. When applied to `vector` and 
     `tensor` values, the result is undefined if _any_ elements are divided by 
     zero.
 

>From b4c70bfb35258754de629044391bc6c08f672c2b Mon Sep 17 00:00:00 2001
From: pingshiyu <pingshiyu at gmail.com>
Date: Tue, 21 Nov 2023 15:17:48 +0000
Subject: [PATCH 15/15] [mlir][arith] result -> behavior

---
 mlir/include/mlir/Dialect/Arith/IR/ArithOps.td | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index 10d9d65c4346114..fe8a74f7e15b73e 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -399,7 +399,7 @@ def Arith_DivUIOp : Arith_IntBinaryOp<"divui", [ConditionallySpeculatable]> {
     `6 / -2 = 6 / (2^16 - 2) = 0`.
 
     Division by zero is undefined behavior. When applied to `vector` and 
-    `tensor` values, the result is undefined if _any_ elements are divided by 
+    `tensor` values, the behavior is undefined if _any_ elements are divided by 
     zero.
 
     Example:
@@ -436,7 +436,7 @@ def Arith_DivSIOp : Arith_IntBinaryOp<"divsi", [ConditionallySpeculatable]> {
 
     Divison by zero, or signed division overflow (minimum value divided by -1) 
     is undefined behavior. When applied to `vector` and `tensor` values, the 
-    result is undefined if _any_ of its elements are divided by zero or has a 
+    behavior is undefined if _any_ of its elements are divided by zero or has a 
     signed division overflow.
 
     Example:
@@ -474,7 +474,7 @@ def Arith_CeilDivUIOp : Arith_IntBinaryOp<"ceildivui",
     representation, `6 / -2 = 6 / (2^16 - 2) = 1`. 
 
     Division by zero is undefined behavior. When applied to `vector` and 
-    `tensor` values, the result is undefined if _any_ elements are divided by 
+    `tensor` values, the behavior is undefined if _any_ elements are divided by 
     zero.
 
     Example:
@@ -505,7 +505,7 @@ def Arith_CeilDivSIOp : Arith_IntBinaryOp<"ceildivsi",
 
     Divison by zero, or signed division overflow (minimum value divided by -1) 
     is undefined behavior. When applied to `vector` and `tensor` values, the 
-    result is undefined if _any_ of its elements are divided by zero or has a 
+    behavior is undefined if _any_ of its elements are divided by zero or has a 
     signed division overflow.
 
     Example:
@@ -535,7 +535,7 @@ def Arith_FloorDivSIOp : Arith_TotalIntBinaryOp<"floordivsi"> {
 
     Divison by zero, or signed division overflow (minimum value divided by -1) 
     is undefined behavior. When applied to `vector` and `tensor` values, the 
-    result is undefined if _any_ of its elements are divided by zero or has a 
+    behavior is undefined if _any_ of its elements are divided by zero or has a 
     signed division overflow.
 
     Example:
@@ -560,7 +560,7 @@ def Arith_RemUIOp : Arith_TotalIntBinaryOp<"remui"> {
     significant, i.e. for `i16`, `6 % -2 = 6 % (2^16 - 2) = 6`.
 
     Division by zero is undefined behavior. When applied to `vector` and 
-    `tensor` values, the result is undefined if _any_ elements are divided by 
+    `tensor` values, the behavior is undefined if _any_ elements are divided by 
     zero.
 
     Example:
@@ -590,7 +590,7 @@ def Arith_RemSIOp : Arith_TotalIntBinaryOp<"remsi"> {
     -2 = 0`.
 
     Division by zero is undefined behavior. When applied to `vector` and 
-    `tensor` values, the result is undefined if _any_ elements are divided by 
+    `tensor` values, the behavior is undefined if _any_ elements are divided by 
     zero.
 
     Example:



More information about the Mlir-commits mailing list