Skip to content

Commit 0c17f43

Browse files
authored
[mlir][arith] Overflow semantics in documentation for muli, subi, and addi (#74346)
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.
1 parent 6c39ab9 commit 0c17f43

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

mlir/include/mlir/Dialect/Arith/IR/ArithOps.td

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ def Arith_ConstantOp : Op<Arith_Dialect, "constant",
195195
def Arith_AddIOp : Arith_TotalIntBinaryOp<"addi", [Commutative]> {
196196
let summary = "integer addition operation";
197197
let description = [{
198+
Performs N-bit addition on the operands. The operands are interpreted as
199+
unsigned bitvectors. The result is represented by a bitvector containing the
200+
mathematical value of the addition modulo 2^n, where `n` is the bitwidth.
201+
Because `arith` integers use a two's complement representation, this operation
202+
is applicable on both signed and unsigned integer operands.
203+
198204
The `addi` operation takes two operands and returns one result, each of
199205
these is required to be the same type. This type may be an integer scalar type,
200206
a vector whose element type is integer, or a tensor of integers. It has no
@@ -230,7 +236,7 @@ def Arith_AddUIExtendedOp : Arith_Op<"addui_extended", [Pure, Commutative,
230236
let description = [{
231237
Performs (N+1)-bit addition on zero-extended operands. Returns two results:
232238
the N-bit sum (same type as both operands), and the overflow bit
233-
(boolean-like), where`1` indicates unsigned addition overflow, while `0`
239+
(boolean-like), where `1` indicates unsigned addition overflow, while `0`
234240
indicates no overflow.
235241

236242
Example:
@@ -276,6 +282,18 @@ def Arith_SubIOp : Arith_TotalIntBinaryOp<"subi"> {
276282
let summary = [{
277283
Integer subtraction operation.
278284
}];
285+
let description = [{
286+
Performs N-bit subtraction on the operands. The operands are interpreted as unsigned
287+
bitvectors. The result is represented by a bitvector containing the mathematical
288+
value of the subtraction modulo 2^n, where `n` is the bitwidth. Because `arith`
289+
integers use a two's complement representation, this operation is applicable on
290+
both signed and unsigned integer operands.
291+
292+
The `subi` operation takes two operands and returns one result, each of
293+
these is required to be the same type. This type may be an integer scalar type,
294+
a vector whose element type is integer, or a tensor of integers. It has no
295+
standard attributes.
296+
}];
279297
let hasFolder = 1;
280298
let hasCanonicalizer = 1;
281299
}
@@ -288,6 +306,18 @@ def Arith_MulIOp : Arith_TotalIntBinaryOp<"muli", [Commutative]> {
288306
let summary = [{
289307
Integer multiplication operation.
290308
}];
309+
let description = [{
310+
Performs N-bit multiplication on the operands. The operands are interpreted as
311+
unsigned bitvectors. The result is represented by a bitvector containing the
312+
mathematical value of the multiplication modulo 2^n, where `n` is the bitwidth.
313+
Because `arith` integers use a two's complement representation, this operation is
314+
applicable on both signed and unsigned integer operands.
315+
316+
The `muli` operation takes two operands and returns one result, each of
317+
these is required to be the same type. This type may be an integer scalar type,
318+
a vector whose element type is integer, or a tensor of integers. It has no
319+
standard attributes.
320+
}];
291321
let hasFolder = 1;
292322
let hasCanonicalizer = 1;
293323
}

0 commit comments

Comments
 (0)