https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128006

            Bug ID: 128006
           Summary: wrong code at -O1 and above with -ffast-math for (x *
                    y) * pow (x, 2.5) + z * x
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyuwoncho18 at gmail dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

#include <math.h>
__attribute__((noipa)) double f(double x, double y, double z) {
  return (x * y) * pow(x, 2.5) + z * x;
}
int main(void) {
  if (f(4.0, 1.0, 0.0) != 128.0)
    __builtin_abort();
}

godbolt: https://godbolt.org/z/9xo7sxheh

With -O0 -ffast-math, or -O2 without -ffast-math, f(4, 1, 0) returns 128 (4 *
4^2.5) and the program exits normally, but with -O1, -O2 or -O3 -ffast-math it
returns 64, as if the exponent were 2, and the program aborts.
-fno-tree-reassoc avoids it.

Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.

Reply via email to