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


Re:

> The following patch implements the following optimizations:
> 
> 	sqrt(0.0) = 0.0
> 	sqrt(1.0) = 1.0
> 	log(1.0) = 0.0
> 	exp(0.0) = 1.0
> 
> 	fabs(sqrt(x)) = sqrt(x)
> 	fabs(exp(x)) = exp(x)
> 
> 	x/exp(y) = x*exp(-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.

> 	log(exp(x)) = x
> 
> 	sqrt(x)*sqrt(y) = sqrt(x*y)

Ditto.

> 	exp(x)*exp(y) = exp(x+y)
> 
> 	sqrt(exp(x)) = exp(x/2.0)
> 	log(sqrt(x)) = log(x)/2.0


BTW, I like your concrete approach to adding optimizations to gcc.

Brad


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