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] Yet more constant folding of pow.


 > 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


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