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]

[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()


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