This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Yet more constant folding of pow.
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: roger at www dot eyesopen dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 5 Apr 2003 17:42:39 -0500 (EST)
- Subject: Re: [PATCH] Yet more constant folding of pow.
- References: <Pine.LNX.4.44.0304051324290.13787-100000@www.eyesopen.com>
> This patch implements the following optimizations:
>
> sqrt(x)*sqrt(x) = x
> pow(x,y)*pow(z,y) = pow(x*z,y)
> pow(x,y)*pow(x,z) = pow(x,y+z)
> x/pow(y,z) = x*pow(y,-z)
Excellent, thanks Roger. However I was wondering something. Correct
me if I'm wrong, but it seems that when we combine multiple folds
using your patch(es) we would get these extra transformations for
free:
pow(x, 0.5) * sqrt(y) -> sqrt(x*y)
sqrt(x) * pow(y, 0.5) -> sqrt(x*y)
sqrt(x) / pow(y, -0.5) -> sqrt(x*y)
I noticed that by combining opts #4 and #3 above you'd get this for
free too:
pow(x,y) / pow(x,z) -> pow(x, y-z)
And with #4 and #2 you get:
pow(x,y) / pow(z,-y) -> pow(x*z, y)
Perhaps you could add all the above to the testcase?
But I don't see that you could necessarily get this one:
pow(x,z) / pow(y,z) -> pow(x/y, z)
Do your transformations figure this last one out?
(Sorry to be such a pain, I can't resist this topic.)
--Kaveh
--
Kaveh R. Ghazi ghazi at caip dot rutgers dot edu