I don’t know how many people use the -ffp-model=fast
command line option, as opposed to -ffast-math
, but I’d like to propose a change in the behavior of this option. Specifically, I’d like to make it a little more user friendly.
Currently, the -ffp-model=fast
option is follows the behavior of -ffast-math
, including the fact that the option implies -ffinite-math-only
. There are people who have been very vocal about the fact that -ffast-math
is too dangerous to ever use, and I think the -ffinite-math-only
option is a big part of this.
I think most users would be better served using -funsafe-math-optimizations
, but the name is a bit off-putting. Do you want options that are “fast” or options that are “unsafe”? Without any more information, you’d probably prefer “fast”, right? But the fact is that -ffast-math
is much more unsafe than -funsafe-math-optimizations
.
I’d like to propose that we make -ffp-model=fast
a bit more user friendly, and maybe add something new (-ffp-model=aggressive
) for people who want to keep the current behavior.
To provide a bit of backstory to this, my experience with this is through working with customers of Intel’s C and C++ compilers, both the one we are now calling the “Classic Compiler” (icc) and the new “oneAPI Compiler” (icx). These compilers have long supported the -fp-model
option but have a distinction between -fp-model fast=1
and -fp-model fast=2
which more or less follows the proposal I’m making here. The oneAPI compiler initially followed the current clang implementation of -ffp-model=fast
but we got a lot of feedback from our customers that the NaN handling was just too aggressive.
Initially, I’d like to make the following changes:
fast | aggressive | |
---|---|---|
Honor NaNs | Yes | No |
Honor infinities | Yes | No |
Complex Arithmetic | promoted | basic |
contract | fast-honor-pragmas | fast-honor-pragmas |
With the exception of the contract behavior, the “aggressive” column matches what we do today with -ffp-model=fast
. I’m proposing changing the contract behavior to honor pragmas in both cases because I don’t understand why anyone wants to ignore pragmas.
One other change I’d like to include in the less aggressive version of this is not canonicalizing based on fast-math flags, but that would require changes to the optimizer. Right now the optimizer does things like (X / Y) * Z ==> (X * Z) / Y
when fast-math is enabled, just because it might enable other optimizations later. This seems too aggressive to me, but there’s nothing we can do about it at the moment. I just wanted to note it here as another thing I’d like to change with the -ffp-model=fast
option when I can.
My question here is, is anyone using the -ffp-model
option who would object to the changes I’m proposing above?