[Mlir-commits] [mlir] [mlir][arith] Add overflow flags support to arith ops (PR #77211)
Jakub Kuderski
llvmlistbot at llvm.org
Sun Jan 7 15:01:16 PST 2024
================
@@ -278,21 +301,41 @@ def Arith_AddUIExtendedOp : Arith_Op<"addui_extended", [Pure, Commutative,
// SubIOp
//===----------------------------------------------------------------------===//
-def Arith_SubIOp : Arith_TotalIntBinaryOp<"subi"> {
+def Arith_SubIOp : Arith_IntArithmeticOpWithOverflowFlag<"subi"> {
let summary = [{
Integer subtraction operation.
}];
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
+ 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.
+ 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.
+
+ This op supports nuw/nsw flags which stands stand for "No Unsigned Wrap" and
+ "No Signed Wrap", respectively. If the nuw and/or nsw flags are present, the
+ result value is undefined if unsigned and/or signed overflow, respectively,
+ occurs.
+
+ Example:
+
+ ```mlir
+ // Scalar subtraction.
+ %a = arith.subi %b, %c : i64
+
+ // Scalar subtraction with overflow flags.
+ %a = arith.subi %b, %c overflow<nsw, nuw> : i64
+
+ // SIMD vector element-wise subtraction, e.g. for Intel SSE.
----------------
kuhar wrote:
Given how far away the arith dialect is from hardware intrinsics, I don't think mentioning a single instruction set (that may not even support that vector type) adds clarity.
```suggestion
// SIMD vector element-wise subtraction.
```
https://github.com/llvm/llvm-project/pull/77211
More information about the Mlir-commits
mailing list