From feb5b3eb277f1baf83ad1cd1362849d24e357cf0 Mon Sep 17 00:00:00 2001 From: uros Date: Sat, 21 Oct 2006 20:05:35 +0000 Subject: [PATCH] 2006-10-21 Uros Bizjak PR middle-end/28252 * builtins.c (fold_builtin): Fold pow(x,1.0/3.0) as cbrt(x) if flag_unsafe_math_optimizations is set. testsuite/ChangeLog: PR middle-end/28252 * gcc.dg/builtins-8.c: Also check pow(x,1.0/3.0) to cbrt(x) transformation. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117937 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/builtins.c | 17 +++++++++++++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/builtins-8.c | 6 +++++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 42b4dedc4f4..21550b3626f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -6,6 +6,12 @@ 2006-10-21 Uros Bizjak + PR middle-end/28252 + * builtins.c (fold_builtin): Fold pow(x,1.0/3.0) as cbrt(x) if + flag_unsafe_math_optimizations is set. + +2006-10-21 Uros Bizjak + PR target/19398 * config/i386/i386.md (fix_trunc?f?i_sse): Add peephole2 patterns to use memory input operand in x87->mem->XMM diff --git a/gcc/builtins.c b/gcc/builtins.c index c1996dc44b1..ecee42b69be 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -7775,6 +7775,23 @@ fold_builtin_pow (tree fndecl, tree arglist, tree type) } } + /* Optimize pow(x,1.0/3.0) = cbrt(x). */ + if (flag_unsafe_math_optimizations) + { + const REAL_VALUE_TYPE dconstroot + = real_value_truncate (TYPE_MODE (type), dconstthird); + + if (REAL_VALUES_EQUAL (c, dconstroot)) + { + tree cbrtfn = mathfn_built_in (type, BUILT_IN_CBRT); + if (cbrtfn != NULL_TREE) + { + tree arglist = build_tree_list (NULL_TREE, arg0); + return build_function_call_expr (cbrtfn, arglist); + } + } + } + /* Check for an integer exponent. */ n = real_to_integer (&c); real_from_integer (&cint, VOIDmode, n, n < 0 ? -1 : 0, 0); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c30830dff1b..b55cd7c8f8b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2006-10-21 Uros Bizjak + + PR middle-end/28252 + * gcc.dg/builtins-8.c: Also check pow(x,1.0/3.0) to cbrt(x) + transformation. + 2006-10-21 Richard Guenther PR tree-optimization/3511 diff --git a/gcc/testsuite/gcc.dg/builtins-8.c b/gcc/testsuite/gcc.dg/builtins-8.c index c3066b41cab..be17774d526 100644 --- a/gcc/testsuite/gcc.dg/builtins-8.c +++ b/gcc/testsuite/gcc.dg/builtins-8.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 Free Software Foundation. +/* Copyright (C) 2003, 2006 Free Software Foundation. Verify that built-in math function constant folding of functions with one constant argument is correctly performed by the compiler. @@ -11,6 +11,7 @@ extern void abort(void); extern double pow(double, double); extern double sqrt(double); +extern double cbrt(double); void test(double x) { @@ -25,6 +26,9 @@ void test(double x) if (pow(x,0.5) != sqrt(x)) abort (); + + if (pow(x,1.0/3.0) != cbrt(x)) + abort (); } int main() -- 2.11.4.GIT