No fastmath attribute on `arith::CmpFOp`

Is there a reason why arith::CmpFOp does not have a fastmath attribute? The corresponding operation in the LLVM dialect (LLVM::FCmpOp) has this flag and thus I assumed that cmpf should have it as well.

I checked the revisions that introduced these flags to the Arith dialect (⚙ D126305 [mlir][arith] Initial support for fastmath flag attributes in the Arithmetic dialect (v2)) and the topic here on discourse ([RFC] FastMath flags support in MLIR (arith dialect)) but there was no mentioning of cmpf anywhere.

It was probably a mistake to add fast math flags to fcmp; it might make sense to not propagate that mistake up through mlir

Could you clarify why this was a mistake?

See __builtin_isnan/__builtin_isfinite should not produce poison with -ffinite-math-only · Issue #45422 · llvm/llvm-project · GitHub and similar issues. The short version is fcmp can be used for guarding code that would trigger edge case behavior and it’s more helpful to consider the inputs on their own

1 Like

This feature has been requested in flang: [Flang] TSVC s314: `fcmp` doesn't have fast-math flags · Issue #74263 · llvm/llvm-project · GitHub

So I have a PR open to add this to arith::CmpFOp: [mlir][flang] add fast math attribute to fcmp by tblah · Pull Request #74315 · llvm/llvm-project · GitHub

I’m happy to take a different approach if you know a different way to solve the flang issue