[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:14:22 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:

The lowering strategy to LLVM is as follows:
* `arith.addf` -> `fadd`
* `arith.addf rounding_mode<...>` -> `llvm.experimental.constrained.fadd`

`fadd` has no rounding mode. I think that means LLVM does not guarantee any rounding mode. This is consistent with the rounding mode attribute: it's an OptionalAttr, not a DefaultValuedAttr.

How about rephrasing like this:
```
If the value cannot be exactly represented, it is rounded using the provided
rounding mode. If no rounding mode is specified, the compiler is free to choose
any rounding mode.
```


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


More information about the Mlir-commits mailing list