[Mlir-commits] [mlir] [mlir][arith] Add rounding mode flags to binary arithmetic operations (PR #188458)

Matthias Springer llvmlistbot at llvm.org
Wed Mar 25 06:48:51 PDT 2026


================
@@ -988,14 +1022,17 @@ def Arith_AddFOp : Arith_FloatBinaryOp<"addf", [Commutative]> {
 // SubFOp
 //===----------------------------------------------------------------------===//
 
-def Arith_SubFOp : Arith_FloatBinaryOp<"subf"> {
+def Arith_SubFOp : Arith_FloatBinaryOpWithRoundingMode<"subf"> {
   let summary = "floating point subtraction operation";
   let description = [{
     The `subf` operation takes two operands and returns one result, each of
     these is required to be the same type. This type may be a floating point
     scalar type, a vector whose element type is a floating point type, or a
     floating point tensor.
 
+    If the value cannot be exactly represented, it is rounded using the
+    provided rounding mode or the default one if no rounding mode is provided.
----------------
matthias-springer wrote:

We could rephrase to:
```
If the value cannot be exactly represented, it is rounded using the provided
rounding mode. If no rounding mode is specified, the rounding mode selection
is done by the target backend.
```

In particular, this means:
* Rewriting an `arith.addf` (without specified rounding mode) to `arith.addf rounding<some_specific_rounding_mode>` would **not** be a semantics-preserving transformation. (And should not be blindly performed on the MLIR level.)


https://github.com/llvm/llvm-project/pull/188458


More information about the Mlir-commits mailing list