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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]