https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102219
Bug ID: 102219 Summary: fast-math inhibits fp contraction for a + b * a Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: mkretz at gcc dot gnu.org Target Milestone: --- Test case (compiled with -O2 -mfma): [[gnu::optimize("fast-math")]] float f(float a, float b) { return a + b * a; } float g(float a, float b) { return a + b * a; } f is not contracted to an fma, while g is. Wild guess: GCC considers a transformation to (1 + b) * a and determines too late that (1 + b) * a is better transformed to a + b * a (note that `return (1 + b) * a` also emits vmulss, vaddss like f above and also doesn't contract to an FMA even though it could/should). Maybe (1 + b) * a should be contracted to fma(a, b, a) with fast-math, in general?