[cfe-dev] fp-contract at -O0

David Greene via cfe-dev cfe-dev at lists.llvm.org
Tue Feb 18 10:59:07 PST 2020


"Kaylor, Andrew via cfe-dev" <cfe-dev at lists.llvm.org> writes:

> --------
> test.c
> --------
> double f(double a, double b, double c) {
>   return a * b + c;
> }
> --------
> clang -c -O0 -ffp-contract=on test.c
> --------
>
> Since clang 5.0 this has produced a call to llvm.fmuladd, which for
> targets that support FMA will generally result in an FMA
> instruction. Arguably this is what the user asked for, since they
> explicitly enabled fp-contract. On the other hand, it is also an
> optimization, which they said they did not want. As a point of
> comparison, specifying -ffast-math will cause the front end to attach
> the "fast" flag to math operations (which also allows contraction),
> but will not lead to FMA formation.
>
> What should we do with this? I see two possible solutions:
>
> 1. The driver should not pass the -ffp-contract=on flag by default at
> -O0 (still allows fmuladd formation if the user specifies
> -ffp-contract=on)
>
> 2. The front end should not form the llvm.fmuladd intrinsic at -O0

I prefer option #1.  If the user explicitly adds -ffp-contract=on then
we should absolutely generate FMAs even at -O0.  To me this is the
principle of least surprise.  A "more specific" option
(-ffp-contract=on) overrides a "more general" option (-O0).

                       -David


More information about the cfe-dev mailing list