On Tue, 15 Oct 2024, Jakub Jelinek wrote: > On Mon, Oct 14, 2024 at 08:53:29AM +0200, Jakub Jelinek wrote: > > > PR middle-end/116891 > > > * match.pd ((negate (IFN_FNMS@3 @0 @1 @2)) -> (IFN_FMA @0 @1 @2)): > > > Only enable for !HONOR_SIGN_DEPENDENT_ROUNDING. > > > > Guess it would be nice to have a testcase which FAILs without the patch and > > PASSes with it, but it can be added later. > > I've added such a testcase now, and additionally found the fix only fixed > one of the 4 problematic similar cases. > > Here is a patch which fixes the others too and adds the testcases. > fma-pr116891.c FAILed without your patch, FAILs with your patch too (but > only due to the bar/baz/qux checks) and PASSes with the patch.
Whoops - I did search but for some reasons I was blind ... > Ok for trunk if it passes full bootstrap/regtest? OK. Thanks a lot, Richard. > 2024-10-15 Jakub Jelinek <ja...@redhat.com> > > PR middle-end/116891 > * match.pd ((negate (fmas@3 @0 @1 @2)) -> (IFN_FNMS @0 @1 @2)): > Only enable for !HONOR_SIGN_DEPENDENT_ROUNDING. > ((negate (IFN_FMS@3 @0 @1 @2)) -> (IFN_FNMA @0 @1 @2)): Likewise. > ((negate (IFN_FNMA@3 @0 @1 @2)) -> (IFN_FMS @0 @1 @2)): Likewise. > > * gcc.dg/pr116891.c: New test. > * gcc.target/i386/fma-pr116891.c: New test. > > --- gcc/match.pd.jj 2024-10-15 12:50:47.699905473 +0200 > +++ gcc/match.pd 2024-10-15 12:57:19.547400416 +0200 > @@ -9452,7 +9452,7 @@ (define_operator_list SYNC_FETCH_AND_AND > (IFN_FNMS @0 @1 @2)) > (simplify > (negate (fmas@3 @0 @1 @2)) > - (if (single_use (@3)) > + (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3)) > (IFN_FNMS @0 @1 @2)))) > > (simplify > @@ -9466,7 +9466,7 @@ (define_operator_list SYNC_FETCH_AND_AND > (IFN_FNMA @0 @1 @2)) > (simplify > (negate (IFN_FMS@3 @0 @1 @2)) > - (if (single_use (@3)) > + (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3)) > (IFN_FNMA @0 @1 @2))) > > (simplify > @@ -9480,7 +9480,7 @@ (define_operator_list SYNC_FETCH_AND_AND > (IFN_FMS @0 @1 @2)) > (simplify > (negate (IFN_FNMA@3 @0 @1 @2)) > - (if (single_use (@3)) > + (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3)) > (IFN_FMS @0 @1 @2))) > > (simplify > --- gcc/testsuite/gcc.dg/pr116891.c.jj 2024-10-15 12:31:57.619723244 > +0200 > +++ gcc/testsuite/gcc.dg/pr116891.c 2024-10-15 12:56:37.809987933 +0200 > @@ -0,0 +1,47 @@ > +/* PR middle-end/116891 */ > +/* { dg-do run } */ > +/* { dg-require-effective-target fenv } */ > +/* { dg-require-effective-target hard_float } */ > +/* { dg-require-effective-target c99_runtime } */ > +/* { dg-options "-O2 -frounding-math" } */ > + > +#include <fenv.h> > + > +__attribute__((noipa)) double > +foo (double x, double y, double z) > +{ > + return -__builtin_fma (-x, y, -z); > +} > + > +__attribute__((noipa)) double > +bar (double x, double y, double z) > +{ > + return -__builtin_fma (-x, y, z); > +} > + > +__attribute__((noipa)) double > +baz (double x, double y, double z) > +{ > + return -__builtin_fma (x, y, -z); > +} > + > +__attribute__((noipa)) double > +qux (double x, double y, double z) > +{ > + return -__builtin_fma (x, y, z); > +} > + > +int > +main () > +{ > +#if defined (FE_DOWNWARD) && __DBL_MANT_DIG__ == 53 && __DBL_MAX_EXP__ == > 1024 > + fesetround (FE_DOWNWARD); > + double a = foo (-0x1.p256, 0x1.p256, 0x1.p-256); > + if (a != -__builtin_nextafter (0x1p256 * 0x1p256, 0.)) > + __builtin_abort (); > + if (a != bar (-0x1.p256, 0x1.p256, -0x1.p-256) > + || a != baz (0x1.p256, 0x1.p256, 0x1.p-256) > + || a != qux (0x1.p256, 0x1.p256, -0x1.p-256)) > + __builtin_abort (); > +#endif > +} > --- gcc/testsuite/gcc.target/i386/fma-pr116891.c.jj 2024-10-15 > 12:42:39.711719596 +0200 > +++ gcc/testsuite/gcc.target/i386/fma-pr116891.c 2024-10-15 > 12:44:56.692806834 +0200 > @@ -0,0 +1,19 @@ > +/* PR middle-end/116891 */ > +/* { dg-do run } */ > +/* { dg-require-effective-target fenv } */ > +/* { dg-require-effective-target hard_float } */ > +/* { dg-require-effective-target c99_runtime } */ > +/* { dg-require-effective-target fma } */ > +/* { dg-options "-O2 -mfma -frounding-math" } */ > + > +#include <fenv.h> > +#include "fma-check.h" > + > +#define main() do_main () > +#include "../../gcc.dg/pr116891.c" > + > +static void > +fma_test (void) > +{ > + do_main (); > +} > > > Jakub > > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)