This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: FP negation optimization
- From: Roger Sayle <roger at eyesopen dot com>
- To: Gabriel Paubert <paubert at iram dot es>
- Cc: Chris Lattner <sabre at nondot dot org>, <gcc at gcc dot gnu dot org>
- Date: Mon, 2 Feb 2004 06:11:03 -0700 (MST)
- Subject: Re: FP negation optimization
On Mon, 2 Feb 2004, Gabriel Paubert wrote:
> Indeed, but doesn't constant folding assume that the rounding mode
> is round to nearest (at least for C, I believe that Ada has different
> rules) ?
The GCC middle-end has the internal flag flag_rounding_math that is
used to determine whether it should enable/disable optimizations that
may be affected by non-standard and sign dependent rounding modes.
The biggest use of this flag is the macro HONOR_SIGN_DEPENDENT_ROUNDING.
Anyone writing a C/C++ program that sets the rounding mode to anything
other than the default should use "-frounding-math" to ensure that they
get consistent results.
> At least a quick look at fold-const.c, real.c, real.h shows that
> while do_add and friends return a boolean telling whether the result
> is inexact or not, the returned value is ignored.
Indeed this is potentially a bug. real_arithmetic could be tweaked
to return a bool indicating whether the operation involved any rounding,
and this result could then be checked in fold-const.c's const_binop when
flag_rounding_math is set, such that we only perform constant folding at
compile-time of floating point expressions that don't overflow. i.e. if
the user sets -frounding-math, then "x = 1.0/3.0;" should be evaluated
at run-time.
Roger
--