https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116979
--- Comment #30 from Alexander Monakov <amonakov at gcc dot gnu.org> --- (In reply to Paul Caprioli from comment #27) > The motivation for this bug report was accuracy (one might even say > correctness), not so much performance. Using FMA in a complex product gives > lower maximum relative normwise error. An explanation is given in section > 1.1 of https://inria.hal.science/hal-04714173 (and references are given to > papers proving the theory). The claim in the paper is that "maximum relative normwise error of this algorithm is 2u". However, errors in the individual real/imaginary components may be arbitrarily large. Take the case of multiplying two conjugate complex numbers, (x+yi)*(x-yi). With FMA, GCC computes the imaginary part of the result as fma(x, -y, x*y) or fma(x, y, -x*y), which gives the (negated) round-off tail of x*y and infinite relative error, while the plain fma-less computation gives the accurate zero result. (I think with one extra fma it should be possible to compute sum of two products required here accurately, a*b+c*d -> fma(a, b, c*d)+fma(c, d, -c*d)) > The experimental results in that paper in sections 3 and 4 show that GCC is > more accurate than clang for complex multiplication for the code that was > tested. GCC (unlike clang) is using FMA for that code, which is great. > > The "always" in the title of this bug expresses the desire to have FMA used > regardless of whether a function is inlined, whether constant propagation > allows compile-time computation of the product, whether the code is > vectorized, and regardless of cost model or other optimization decisions. > For scientific work, it's nice to have this robustness. Despite the issue described above? And note that since use of FMA is asymmetric, complex multiplication becomes non-commutative (imag(c0*c1) != imag(c1*c0) if you expand both sides with the same use of FMA), which can make the result unpredictable as long as GCC doesn't promise to always keep operands of complex multiplication in the source order.
