This is the mail archive of the
`gcc-patches@gcc.gnu.org`
mailing list for the GCC project.

# Re: [PATCH] Perform constant folding of math builtins

*From*: Brad Lucier <lucier at math dot purdue dot edu>
*To*: roger at eyesopen dot com (Roger Sayle)
*Cc*: lucier at math dot purdue dot edu (Brad Lucier), gcc-patches at gcc dot gnu dot org
*Date*: Wed, 28 Aug 2002 11:38:19 -0500 (EST)
*Subject*: Re: [PATCH] Perform constant folding of math builtins

>
>
> Hi Brad,
> > > sqrt(x)*sqrt(y) = sqrt(x*y)
> > > exp(log(x)) = x
> >
> > This is false for negative x, for obvious reasons. This could mask
> > a real error; I don't think it should be used.
>
> I was relying on the semantics of "-funsafe-math-optimizations", that
> to quote the documentation, "allows optimizations for floating-point
> arithmetic that assume the arguments and results are valid".
>
> I don't suppose I could convince you this is a reasonable transformation
> at GCC's most aggressive level of numerical optimization, namely
> "-funsafe-math-optimizations"? I've had the misfortune to recently
> come across sqrt(x)*sqrt(y) in a "real world" example:
>
> > #define len(v) sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2])
> >
> > double dotprod(double *a, double *b)
> > {
> > return (a[0]*b[0] + a[1]*b[1] + a[2]*b[2])/(len(a)*len(b));
> > }
After reading Geoff Keating's post giving, for example,
a/b/c -> a/(b*c)
as a valid transformation for -funsafe-math-optimizations, I realize it's OK
to accept sqrt(x)*sqrt(y)->sqrt(x*y) as OK under -funsafe-math-optimizations.
I guess I'm just someone for whom this option does not hold a whole
lot of promise.
Brad