There are currently two options that are used to tell the compiler to perform unsafe floating-point optimizations: '-ffast-math' and '-funsafe-math-optimizations'.
'ffast-math' is enabled by default. It automatically enables the driver option '-menable-unsafe-fp-math'.
Below is a table illustrating the special operations enabled automatically by '-ffast-math', '-funsafe-math-optimizations' and '-menable-unsafe-fp-math' respectively.
Special Operations | -ffast-math | -funsafe-math-optimizations | -menable-unsafe-fp-math |
MathErrno | 0 | 1 | 1 |
FiniteMathOnly | 1 | 0 | 0 |
AllowFPReassoc | 1 | 1 | 1 |
NoSignedZero | 1 | 1 | 1 |
AllowRecip | 1 | 1 | 1 |
ApproxFunc | 1 | 1 | 1 |
RoundingMath | 0 | 0 | 0 |
UnsafeFPMath | 1 | 0 | 1 |
FPContract | fast | on | on |
'-ffast-math' enables '-fno-math-errno', '-ffinite-math-only', '-funsafe-math-optimzations' and sets 'FpContract' to 'fast'. The driver option
'-menable-unsafe-fp-math' enables the same special options than '-funsafe-math-optimizations'. This is redundant. We propose to remove the driver
option '-menable-unsafe-fp-math' and use instead, the setting of the special operations to set the function attribute 'unsafe-fp-math'. This attribute will
be enabled only if those special operations are enabled and if 'FPContract' is either 'fast' or set to the default value.
Because we diagnose unknown driver flags as an error (https://godbolt.org/z/4xjzKh4Ej) and there's no deprecation period, I think we should put this under the potentially breaking changes section. In this case, I'm specifically worried about proprietary projects using the flag for optimization purposes (a lot of numerical analysis code is behind closed doors).
CC @MaskRay just to make sure there's agreement (we're still trying to figure out what constitutes a breaking change we want to be loud about in terms of driver flags).
Assuming Fangrui doesn't disagree, once this lands, please post an announcement about it into https://discourse.llvm.org/c/announce/46 with the clang and potentially-breaking tags (an example of such a post is: https://discourse.llvm.org/t/clang-16-notice-of-potentially-breaking-changes/65562/ though you wouldn't need all that lead-in text).