Skip to content

[mlir][arith] Overflow semantics in documentation for muli, subi, and addi #74346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 7, 2023

Conversation

pingshiyu
Copy link
Contributor

Following discussions from this RFC: https://discourse.llvm.org/t/rfc-integer-overflow-semantics

Adding the overflow semantics into the muli, subi and addi arith operations.

@llvmbot
Copy link
Member

llvmbot commented Dec 4, 2023

@llvm/pr-subscribers-mlir

Author: Jacob Yu (pingshiyu)

Changes

Following discussions from this RFC: https://discourse.llvm.org/t/rfc-integer-overflow-semantics

Adding the overflow semantics into the muli, subi and addi arith operations.


Full diff: https://github.com/llvm/llvm-project/pull/74346.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/Arith/IR/ArithOps.td (+28)
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;
 }

@llvmbot
Copy link
Member

llvmbot commented Dec 4, 2023

@llvm/pr-subscribers-mlir-arith

Author: Jacob Yu (pingshiyu)

Changes

Following discussions from this RFC: https://discourse.llvm.org/t/rfc-integer-overflow-semantics

Adding the overflow semantics into the muli, subi and addi arith operations.


Full diff: https://github.com/llvm/llvm-project/pull/74346.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/Arith/IR/ArithOps.td (+28)
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;
 }

@pingshiyu
Copy link
Contributor Author

@pingshiyu pingshiyu requested a review from kuhar December 5, 2023 18:52
Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@math-fehr math-fehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kuhar
Copy link
Member

kuhar commented Dec 6, 2023

@joker-eph do you have any comments?

@joker-eph
Copy link
Collaborator

No comments, thanks for checking!

@kuhar kuhar merged commit 0c17f43 into llvm:main Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants