[Bug middle-end/98420] New: Invalid simplification of x - x with -frounding-math
ubizjak at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Dec 22 14:56:35 GMT 2020
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.
More information about the Gcc-bugs
mailing list