public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/107879] New: [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics
@ 2022-11-26 15:46 slyfox at gcc dot gnu.org
  2022-11-26 16:23 ` [Bug middle-end/107879] " amonakov at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: slyfox at gcc dot gnu.org @ 2022-11-26 15:46 UTC (permalink / raw)
  To: gcc-bugs

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)

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-12-08 22:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-26 15:46 [Bug middle-end/107879] New: [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics slyfox at gcc dot gnu.org
2022-11-26 16:23 ` [Bug middle-end/107879] " amonakov at gcc dot gnu.org
2022-11-26 16:40 ` [Bug tree-optimization/107879] " pinskia at gcc dot gnu.org
2022-11-26 17:20 ` slyfox at gcc dot gnu.org
2022-11-28  7:37 ` rguenth at gcc dot gnu.org
2022-11-28 10:55 ` jakub at gcc dot gnu.org
2022-11-28 13:57 ` jakub at gcc dot gnu.org
2022-11-28 19:09 ` jakub at gcc dot gnu.org
2022-11-28 22:44 ` slyfox at gcc dot gnu.org
2022-12-05 10:19 ` cvs-commit at gcc dot gnu.org
2022-12-05 10:36 ` jakub at gcc dot gnu.org
2022-12-05 11:31 ` amonakov at gcc dot gnu.org
2022-12-05 11:33 ` marxin at gcc dot gnu.org
2022-12-08 22:44 ` slyfox at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).