[PATCH] D72675: [Clang][Driver] Fix -ffast-math/-ffp-contract interaction

Ulrich Weigand via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 20 09:49:12 PST 2020


uweigand added a comment.

I've had a quick look at GCC, and it seems there's a couple of different issues.

First of all, `-ffast-math` is a "collective" flag that has no separate meaning except setting a bunch of other flags.  Currently, these flags are:  `-fno-math-errno`, ` -funsafe-math-optimizations` (which is itself a collective flag enabling `-fno-signed-zeros`, `-fno-trapping-math`, `-fassociative-math`, and `-freciprocal-math`),  `-ffinite-math-only`, `-fno-rounding-math`, `-fno-signaling-nans`, `-fcx-limited-range`, and  `-fexcess-precision=fast`.

When deciding whether to define `__FAST_MATH__`, GCC will not specifically look at whether or not the -ffast-math option itself was given, but whether the status of those other flags matches what would have been set by -ffast-math.  However, it does not include all of the flags; currently only `-fmath-errno`, `-funsafe-math-optimizations`, `-fsigned-zeros`, `-ftrapping-math`, `-ffinite-math-only`,  and `-fexcess-precision` are checked, while `-fassociative-math`, `-freciprocal-math`, `-frounding-math`, `-fsignaling-nans`, and `-fcx-limited-range` are ignored.

I'm not sure whether this is deliberate (but it seems weird) or just a bug.  I can ask the GCC developers ...

A separate question is the interaction of `-ffast-math` with `-ffp-contract=`.  Currently, there is no such interaction whatsoever in GCC: `-ffast-math` does not imply any particular `-ffp-contract=` setting, and vice versa the `-ffp-contract=` setting is not considered at all when defining `__FAST_MATH__`.  This seems at least internally consistent.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72675/new/

https://reviews.llvm.org/D72675





More information about the llvm-commits mailing list