[Mlir-commits] [mlir] [mlir][arith] Define the fastmath flags (PR #230085)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Oct 8 05:13:58 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-arith

Author: Hung-Kuan Tseng (Tim096)

<details>
<summary>Changes</summary>

The `FastMathFlags` enum had no description. Define each flag in arith's
own terms, as #<!-- -->217087 started and as requested in its review. The
definitions follow the LLVM IR fast-math flags, which
`convert-arith-to-llvm` maps them to one-to-one.

Supersedes #<!-- -->217087.

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


1 Files Affected:

- (modified) mlir/include/mlir/Dialect/Arith/IR/ArithBase.td (+32) 


``````````diff
diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
index 0c05c4db79bed..13a1622728ff4 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithBase.td
@@ -139,6 +139,38 @@ def FastMathFlags : I32BitEnumAttr<
   let cppNamespace = "::mlir::arith";
   let genSpecializedAttr = 0;
   let printBitEnumPrimaryGroups = 1;
+  let description = [{
+    Floating-point fast math flags. Each flag lets transformations assume
+    something about the operation, or rewrite it into a different sequence of
+    operations.
+
+    * `nnan`: the operands and the result are assumed not to be NaN. If an
+      operand is NaN, or the result would be NaN, the result is poison.
+    * `ninf`: the operands and the result are assumed not to be +/-Inf. If an
+      operand is +/-Inf, or the result would be +/-Inf, the result is poison.
+    * `nsz`: the sign of a zero operand may be flipped non-deterministically.
+      This does not make `-0.0` poison.
+    * `arcp`: a division may be treated as a multiplication by the reciprocal,
+      e.g. `a / b` as `a * (1.0 / b)`.
+    * `contract`: the operation may be fused with a neighbouring operation into
+      one operation with a single rounding, e.g. a `mulf` feeding an `addf`
+      into an `fma`. This does not allow reassociation to form a fusion.
+    * `afn`: the operation may be replaced by an approximation. This applies to
+      the `math` operations that carry this attribute.
+    * `reassoc`: the operation may be replaced by an algebraically equivalent
+      expression, e.g. reassociated with neighbouring operations, even though
+      floating-point arithmetic is not associative.
+    * `fast`: all of the above.
+
+    `arcp`, `contract`, `afn` and `reassoc` are rewrite-based: a rewrite that
+    involves several operations needs the flag on all of them, and the
+    operations it creates generally carry the intersection of the flags of the
+    operations they replace. The other flags apply to each operation on its
+    own.
+
+    These are the LLVM IR fast-math flags of the same name, which is what
+    `convert-arith-to-llvm` lowers them to.
+  }];
 }
 
 def Arith_FastMathAttr :

``````````

</details>


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


More information about the Mlir-commits mailing list