[flang-commits] [flang] [mlir] [RFC][mlir] Conditional support for fast-math attributes. (PR #125620)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Tue Feb 4 12:26:47 PST 2025
================
@@ -225,6 +225,17 @@ def LLVM_FCmpOp : LLVM_ArithmeticCmpOp<"fcmp", [
// Set the $predicate index to -1 to indicate there is no matching operand
// and decrement the following indices.
list<int> llvmArgIndices = [-1, 0, 1, 2];
+
+ let extraClassDeclaration = [{
+ /// Always allow FastmathFlags on llvm.fcmp.
+ /// It does not produce a floating point result, but
+ /// LLVM is currently relying on fast-math flags attached
----------------
vzakhari wrote:
LLVM can look at both compare and select, depending on what it needs to do.
What I mean here is: LLVM's `fcmp` instruction supports fast-math flags, and `llvm.fcmp` operation should also support them; the general rule for instructions/operations to support fast-math is that they produce a floating point result; neither `fcmp` nor `llvm.fcmp` produce floating point result, so they are exceptions from the general rule, so `isFastmathApplicable` should be overridden here.
There is not need to override `isFastmathApplicable` for `llvm.select`, because it is covered by the general rule.
Note that the comment is explicitly saying that this is a temporary solution while LLVM expects it.
LLVM code has the following TODO about `fcmp`:
```
// FIXME: To clean up and correct the semantics of fast-math-flags, FCmp
// should not be treated as a math op, but the other opcodes should.
// This would make things consistent with Select/PHI (FP value type
// determines whether they are math ops and, therefore, capable of
// having fast-math-flags).
```
https://github.com/llvm/llvm-project/pull/125620
More information about the flang-commits
mailing list