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

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