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: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: roger at eyesopen dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 26 Aug 2002 15:45:41 -0400 (EDT)
- Subject: Re: [PATCH] Perform constant folding of math builtins
> From: Roger Sayle <roger at eyesopen dot com>
>
> The following patch implements the following optimizations:
>
How about some with pow?
Simplifications of pow with constants:
pow (1.0, x) = 1.0
pow (x, 0.0) = 1.0
pow (x, 1.0) = x
pow (x, 2.0) = x * x
pow (x, -1.0) = 1 / x
pow (x, -2.0) = 1 / (x * x)
pow (x, 0.5) = sqrt (x)
Simplifications of pow mixed with log/exp/sqrt:
log (pow (x, p)) = p * log (x)
pow (exp (x), p) = exp (x * p)
sqrt (pow (x, y)) = pow (x, y / 2)
pow (x, sqrt (y)) = pow (x, y / 2)
Simplifications of multiple pow calls:
pow (x, p) * pow (x, q) = pow (x, p + q)
pow (x, p) / pow (x, q) = pow (x, p - q)
pow (pow (x, p), q) = pow (x, p * q)
pow (x, p) * pow (y, p) = pow (x * y, p)
Assuming I remembered everything correctly, these are mathematical
identities. But I'm not sure which if any are valid/invalid in the
presence of NaNs, etc.
--Kaveh
--
Kaveh R. Ghazi Director of Systems Architecture
ghazi@caip.rutgers.edu Qwest Solutions