public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/98420] New: Invalid simplification of x - x with -frounding-math
@ 2020-12-22 14:56 ubizjak at gmail dot com
  2021-01-05  9:39 ` [Bug middle-end/98420] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ubizjak at gmail dot com @ 2020-12-22 14:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98420
           Summary: Invalid simplification of x - x with -frounding-math
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ubizjak at gmail dot com
  Target Milestone: ---

Split out from PR96793, where Marc says in c13:

-q-
x-x does depend on the rounding mode (the transformation in match.pd gets it
wrong, by the way).
-/q-

The testcase:

--cut here--
#include <fenv.h>

double
__attribute__((noinline))
foo (double a)
{
  return a - a;
}

int
main ()
{
  double res;

  fesetround (FE_DOWNWARD);

  res = foo (1.11);

  if (__builtin_signbit (res) == 0)
    __builtin_abort ();

  return 0;
}
--cut here--

aborts with -O2 -ffinite-math-only -frounding-math

Please note that x - x with FE_DOWNWARD should result in -0.0.

The problem is in match.pd, where:

(simplify
 (minus @0 @0)
 (if (!FLOAT_TYPE_P (type) || !HONOR_NANS (type))
  { build_zero_cst (type); }))

should involve flag_rounding_math in some way.

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

* [Bug middle-end/98420] Invalid simplification of x - x with -frounding-math
  2020-12-22 14:56 [Bug middle-end/98420] New: Invalid simplification of x - x with -frounding-math ubizjak at gmail dot com
@ 2021-01-05  9:39 ` rguenth at gcc dot gnu.org
  2021-12-13  5:42 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-01-05  9:39 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
     Ever confirmed|0                           |1
          Component|tree-optimization           |middle-end
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-01-05

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
probably conditional on HONOR_SIGNED_ZEROS.

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

* [Bug middle-end/98420] Invalid simplification of x - x with -frounding-math
  2020-12-22 14:56 [Bug middle-end/98420] New: Invalid simplification of x - x with -frounding-math ubizjak at gmail dot com
  2021-01-05  9:39 ` [Bug middle-end/98420] " rguenth at gcc dot gnu.org
@ 2021-12-13  5:42 ` pinskia at gcc dot gnu.org
  2022-03-10 23:56 ` roger at nextmovesoftware dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-13  5:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> probably conditional on HONOR_SIGNED_ZEROS.

That is checked now:

+      || (!tree_expr_maybe_nan_p (@0)
+         && !tree_expr_maybe_infinite_p (@0)))

The part that is missed is the flag_rounding_math .

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

* [Bug middle-end/98420] Invalid simplification of x - x with -frounding-math
  2020-12-22 14:56 [Bug middle-end/98420] New: Invalid simplification of x - x with -frounding-math ubizjak at gmail dot com
  2021-01-05  9:39 ` [Bug middle-end/98420] " rguenth at gcc dot gnu.org
  2021-12-13  5:42 ` pinskia at gcc dot gnu.org
@ 2022-03-10 23:56 ` roger at nextmovesoftware dot com
  2022-03-12  9:23 ` cvs-commit at gcc dot gnu.org
  2022-03-14 18:39 ` roger at nextmovesoftware dot com
  4 siblings, 0 replies; 6+ messages in thread
From: roger at nextmovesoftware dot com @ 2022-03-10 23:56 UTC (permalink / raw)
  To: gcc-bugs

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

Roger Sayle <roger at nextmovesoftware dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |roger at nextmovesoftware dot com
                 CC|                            |roger at nextmovesoftware dot com
             Status|NEW                         |ASSIGNED

--- Comment #3 from Roger Sayle <roger at nextmovesoftware dot com> ---
Patch proposed.
https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591583.html

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

* [Bug middle-end/98420] Invalid simplification of x - x with -frounding-math
  2020-12-22 14:56 [Bug middle-end/98420] New: Invalid simplification of x - x with -frounding-math ubizjak at gmail dot com
                   ` (2 preceding siblings ...)
  2022-03-10 23:56 ` roger at nextmovesoftware dot com
@ 2022-03-12  9:23 ` cvs-commit at gcc dot gnu.org
  2022-03-14 18:39 ` roger at nextmovesoftware dot com
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-12  9:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Roger Sayle <sayle@gcc.gnu.org>:

https://gcc.gnu.org/g:72c243017dee611bf3c32ea7bfad6ac538021aaf

commit r12-7621-g72c243017dee611bf3c32ea7bfad6ac538021aaf
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Sat Mar 12 09:20:52 2022 +0000

    PR middle-end/98420: Don't fold x - x to 0.0 with -frounding-math

    This patch addresses PR middle-end/98420, which is inappropriate constant
    folding of x - x to 0.0 (in match.pd) when -frounding-math is specified.
    Specifically, x - x may be -0.0 with FE_DOWNWARD as the rounding mode.

    To summarize, the desired IEEE behaviour, x - x for floating point x,
    (1) can't be folded to 0.0 by default, due to the possibility of NaN or Inf
    (2) can be folded to 0.0 with -ffinite-math-only
    (3) can't be folded to 0.0 with -ffinite-math-only -frounding-math
    (4) can be folded with -ffinite-math-only -frounding-math -fno-signed-zeros

    2022-03-12  Roger Sayle  <roger@nextmovesoftware.com>

    gcc/ChangeLog
            PR middle-end/98420
            * match.pd (minus @0 @0): Additional checks for -fno-rounding-math
            (the defaut) or -fno-signed-zeros.

    gcc/testsuite/ChangeLog
            PR middle-end/98420
            * gcc.dg/pr98420.c: New test case.

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

* [Bug middle-end/98420] Invalid simplification of x - x with -frounding-math
  2020-12-22 14:56 [Bug middle-end/98420] New: Invalid simplification of x - x with -frounding-math ubizjak at gmail dot com
                   ` (3 preceding siblings ...)
  2022-03-12  9:23 ` cvs-commit at gcc dot gnu.org
@ 2022-03-14 18:39 ` roger at nextmovesoftware dot com
  4 siblings, 0 replies; 6+ messages in thread
From: roger at nextmovesoftware dot com @ 2022-03-14 18:39 UTC (permalink / raw)
  To: gcc-bugs

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

Roger Sayle <roger at nextmovesoftware dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |12.0

--- Comment #5 from Roger Sayle <roger at nextmovesoftware dot com> ---
This should now be fixed on mainline.

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

end of thread, other threads:[~2022-03-14 18:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-22 14:56 [Bug middle-end/98420] New: Invalid simplification of x - x with -frounding-math ubizjak at gmail dot com
2021-01-05  9:39 ` [Bug middle-end/98420] " rguenth at gcc dot gnu.org
2021-12-13  5:42 ` pinskia at gcc dot gnu.org
2022-03-10 23:56 ` roger at nextmovesoftware dot com
2022-03-12  9:23 ` cvs-commit at gcc dot gnu.org
2022-03-14 18:39 ` roger at nextmovesoftware dot com

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).