This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, middle-end]: Committed: Also optimize a/cbrt(b/c) into a*cbrt(c/b).
- From: "Uros Bizjak" <ubizjak at gmail dot com>
- To: "Kaveh R. GHAZI" <ghazi at caip dot rutgers dot edu>
- Cc: "GCC Patches" <gcc-patches at gcc dot gnu dot org>, "Richard Guenther" <richard dot guenther at gmail dot com>
- Date: Tue, 12 Jun 2007 09:24:20 +0200
- Subject: [PATCH, middle-end]: Committed: Also optimize a/cbrt(b/c) into a*cbrt(c/b).
On 6/11/07, Uros Bizjak <ubizjak@gmail.com> wrote:
Kaveh R. GHAZI wrote:
> Is it possible to do the same with cbrt, pow (possibly others?) along the
> lines of negate_exp/negate_expr_p/negate_mathfn_p?
>
At least for cbrt, it is possible to simply change BUILTIN_SQRT_P into
BUILTIN_ROOT_P, and the same code will handle cbrt.
Attached patch transforms a*cbrt(b/c) in the same way as sqrt. Patch
was committed as obvious after bootstrapping and regtesting on
x86_64-pc-linux-gnu for all default languages.
2007-06-12 Uros Bizjak <ubizjak@gmail.com>
* fold-const (fold_binary) [RDIV_EXPR]: Also optimize a/cbrt(b/c)
into a*cbrt(c/b) if flag_unsafe_math_optimizations is set.
testuite/ChangeLog:
2007-06-12 Uros Bizjak <ubizjak@gmail.com>
* gcc.dg/builtins-11.c: Also check folding of a/cbrt(b/c).
Uros.
Index: fold-const.c
===================================================================
--- fold-const.c (revision 125636)
+++ fold-const.c (working copy)
@@ -10555,8 +10555,8 @@
}
}
- /* Optimize a/sqrt(b/c) into a*sqrt(c/b). */
- if (BUILTIN_SQRT_P (fcode1))
+ /* Optimize a/root(b/c) into a*root(c/b). */
+ if (BUILTIN_ROOT_P (fcode1))
{
tree rootarg = CALL_EXPR_ARG (arg1, 0);
Index: testsuite/gcc.dg/builtins-11.c
===================================================================
--- testsuite/gcc.dg/builtins-11.c (revision 125636)
+++ testsuite/gcc.dg/builtins-11.c (working copy)
@@ -12,6 +12,7 @@
extern double exp(double);
extern double sqrt(double);
+extern double cbrt(double);
extern double pow(double,double);
void test(double x, double y, double z)
@@ -39,6 +40,9 @@
if (x/sqrt(y/z) != x*sqrt(z/y))
link_error ();
+
+ if (x/cbrt(y/z) != x*cbrt(z/y))
+ link_error ();
}
int main()