[PATCH] Yet more constant folding of pow.

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Sat Apr 5 22:42:00 GMT 2003


 > 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@caip.rutgers.edu



More information about the Gcc-patches mailing list