aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>2004-03-25 17:51:17 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2004-03-25 17:51:17 +0000
commite19f6bded7ebdab435f14256f33376d36ee94b1c (patch)
tree666a4a6d283551504a605f8b912b83befd89d93b /gcc/fold-const.c
parentec507f2d8b6a00a9139d53964d2e7df902336814 (diff)
downloadgcc-e19f6bded7ebdab435f14256f33376d36ee94b1c.zip
gcc-e19f6bded7ebdab435f14256f33376d36ee94b1c.tar.gz
gcc-e19f6bded7ebdab435f14256f33376d36ee94b1c.tar.bz2
builtins.c (fold_builtin): Add new builtin optimizations for sqrt and/or cbrt.
* builtins.c (fold_builtin): Add new builtin optimizations for sqrt and/or cbrt. * fold-const.c (fold): Likewise. testsuite: * gcc.dg/torture/builtin-explog-1.c: Add new cases. * gcc.dg/torture/builtin-math-1.c: Likewise. * builtin-power-1.c: New test. From-SVN: r79959
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 417d1a4..e8c36f0 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -6389,23 +6389,24 @@ fold (tree expr)
enum built_in_function fcode0 = builtin_mathfn_code (arg0);
enum built_in_function fcode1 = builtin_mathfn_code (arg1);
- /* Optimizations of sqrt(...)*sqrt(...). */
- if (fcode0 == fcode1 && BUILTIN_SQRT_P (fcode0))
+ /* Optimizations of root(...)*root(...). */
+ if (fcode0 == fcode1 && BUILTIN_ROOT_P (fcode0))
{
- tree sqrtfn, arg, arglist;
+ tree rootfn, arg, arglist;
tree arg00 = TREE_VALUE (TREE_OPERAND (arg0, 1));
tree arg10 = TREE_VALUE (TREE_OPERAND (arg1, 1));
/* Optimize sqrt(x)*sqrt(x) as x. */
- if (operand_equal_p (arg00, arg10, 0)
+ if (BUILTIN_SQRT_P (fcode0)
+ && operand_equal_p (arg00, arg10, 0)
&& ! HONOR_SNANS (TYPE_MODE (type)))
return arg00;
- /* Optimize sqrt(x)*sqrt(y) as sqrt(x*y). */
- sqrtfn = TREE_OPERAND (TREE_OPERAND (arg0, 0), 0);
+ /* Optimize root(x)*root(y) as root(x*y). */
+ rootfn = TREE_OPERAND (TREE_OPERAND (arg0, 0), 0);
arg = fold (build (MULT_EXPR, type, arg00, arg10));
arglist = build_tree_list (NULL_TREE, arg);
- return build_function_call_expr (sqrtfn, arglist);
+ return build_function_call_expr (rootfn, arglist);
}
/* Optimize expN(x)*expN(y) as expN(x+y). */