https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116891
Bug ID: 116891 Summary: invalid optimization of -fma(-x,y,-z) when -03 and -frounding-math are used Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: walter.mascarenhas at gmail dot com Target Milestone: --- GCC generates invalid code for this statement x = - fma( -y, z, -w ) with -frounding-math. It "optimizes" it to x = fma( y, z, w ) but this is incorrect when the rounding mode is downwards or upwards. In more detail, for the function double bad_fma( double y, double z, double w) { return std::fma( -y, z, -w ); } with flags -O3 -mfma -frounding-math I get this in godbolt, with gcc 14.2: bad_fma: vfmadd132sd xmm0, xmm2, xmm1 ret That is, gcc incorrectly "optimizes" the code.