This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Optimize -1.0*x into -x
- From: Richard Henderson <rth at redhat dot com>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 31 May 2002 15:16:01 -0700
- Subject: Re: [PATCH] Optimize -1.0*x into -x
- References: <Pine.LNX.4.33.0205231821560.22069-100000@www.eyesopen.com>
On Thu, May 23, 2002 at 06:31:53PM -0600, Roger Sayle wrote:
> The following patch transforms the floating point multiplication
> -1.0 * x into the equivalent -x. This allows use of the faster
> floating point negation instructions, e.g. fchs on x86. I believe
> that this transformation is always valid for IEEE math, including
> NaNs, infinities and signed zeros, but I thought I'd get a second
> opinion from the reviewer/FP lawyers.
It is safe unless we're looking for acrued exception bits. Which gcc
isn't terribly consistent at doing. Technically this is only important
for C99 #pragma STDC FENV_ACCESS on, which we don't support yet. But
I think leaving it -ffast-math is a good idea for now.
> * tree.c (real_minus_onep): New function to test for -1.0.
> * fold-const.c (fold) [MULT_EXPR]: Optimize -1.0*x into -x.
> * gcc.dg/fnegate-1.c: New test case.
Ok.
r~