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
- Cc: lucier at math dot purdue dot edu (Brad Lucier), gcc-patches at gcc dot gnu dot org
- Date: Sun, 25 Aug 2002 22:08:17 -0500 (EST)
- Subject: 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