https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879
Bug ID: 107879 Summary: [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: slyfox at gcc dot gnu.org Target Milestone: --- Test failure is initially observed on ffmpeg-4.4.2 test suite where a bunch of tests started failing comparison against golden values. Extracted minimized example: // $ cat a.c /* Extracted from ffmpeg-4 test failure initially. How to reproduce: $ gcc-13/bin/gcc -O0 -lm a.c -o a -mfpmath=sse -fexcess-precision=standard -Wall -Wextra && ./a ... OK $ gcc-13/bin/gcc -O1 -lm a.c -o a -mfpmath=sse -fexcess-precision=standard -Wall -Wextra && ./a ... BUG */ #include <stdio.h> __attribute__((noinline, noipa)) static double build_filter(double * y) { volatile int ph = 0; volatile double vf = 1.0; double factor = vf; double x = - (double)ph * factor; /* should be -0.0 */ fprintf(stderr, "z = %f\n", x); /* prints -0.0, ok */ /* This 'if / else' code should not affect calculation of 'ffm', but removing it does change things. */ if (x == 0) *y = 1.0; /* should be 1.0 or .. */ else *y = 1.0 / x; /* -inf? */ fprintf(stderr, "*y = %f\n", *y); /* printf 1.0, ok */ double w = 2.0 * x / factor; /* should be -0.0 */ fprintf(stderr, "w = %f\n", w); /* prints -0.0, ok */ double omww = 1 - w; /* should be 1.0 */ fprintf(stderr, "omww = %f\n", omww); /* printf 1.0, ok */ double ffm = (omww > 0.0) ? omww : 0.0; /* should be 1.0 */ fprintf(stderr, "ffm = %f\n", ffm); /* printf 0.0 or 1.0, BUG */ return ffm; } int main() { double y = 42.0; double filter = build_filter(&y); fprintf(stderr, "f = %.20f; y = %.20f\n", filter, y); /* Should be 1.0, sometimes returns 0.0. */ fprintf(stderr, "%s\n", (filter > 0.5) ? "OK" : "BUG"); } How to reproduce: # -O0, good: $ gcc-HEAD/bin/gcc -O0 -lm a.c -o a -mfpmath=sse -fexcess-precision=standard -Wall -Wextra && ./a z = -0.000000 *y = 1.000000 w = -0.000000 omww = 1.000000 ffm = 1.000000 f = 1.00000000000000000000; y = 1.00000000000000000000 OK # -O1, bad: $ gcc-HEAD/bin/gcc -O1 -lm a.c -o a -mfpmath=sse -fexcess-precision=standard -Wall -Wextra && ./a z = -0.000000 *y = 1.000000 w = -0.000000 omww = 1.000000 ffm = 0.000000 f = 0.00000000000000000000; y = 1.00000000000000000000 BUG I think the code does not have anything controversial. Probably a code generation bug? $ LANG=C gcc-HEAD/bin/gcc -v Using built-in specs. COLLECT_GCC=/<<NIX>>/gcc-13.0.0/bin/gcc COLLECT_LTO_WRAPPER=/<<NIX>>/gcc-13.0.0/libexec/gcc/x86_64-unknown-linux-gnu/13.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: Thread model: posix Supported LTO compression algorithms: zlib gcc version 13.0.0 20221126 (experimental) (GCC)