aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2015-10-07 08:09:45 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2015-10-07 08:09:45 +0000
commitd01db77a06a80459acf79e963c55e3b94106eeb3 (patch)
tree26df13af657839b7995fa4de21f93310ada1c766 /gcc/builtins.c
parent5b5dce39b8c076c185ce1fa19d4800d6129f3f53 (diff)
downloadgcc-d01db77a06a80459acf79e963c55e3b94106eeb3.zip
gcc-d01db77a06a80459acf79e963c55e3b94106eeb3.tar.gz
gcc-d01db77a06a80459acf79e963c55e3b94106eeb3.tar.bz2
Cache reals for 1/4, 1/6 and 1/9
We have a global 1/2 and a cached 1/3, but recalculate 1/4, 1/6 and 1/9 each time we need them. That seems a bit arbitrary and makes the folding code more noisy (especially once it's moved to match.pd). This patch caches the other three constants too. Bootstrapped & regression-tested on x86_64-linux-gnu. gcc/ * real.h (dconst_quarter, dconst_sixth, dconst_ninth): New macros. (dconst_quarter_ptr, dconst_sixth_ptr, dconst_ninth_ptr): Declare. * real.c (CACHED_FRACTION): New helper macro. (dconst_third_ptr): Use it. (dconst_quarter_ptr, dconst_sixth_ptr, dconst_ninth_ptr): New. * builtins.c (fold_builtin_sqrt): Use dconst_quarter and dconst_sixth. (fold_builtin_cbrt): Use dconst_sixth and dconst_ninth. From-SVN: r228561
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c31
1 files changed, 6 insertions, 25 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 89bea60..8fa3927 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7742,20 +7742,10 @@ fold_builtin_sqrt (location_t loc, tree arg, tree type)
if (powfn)
{
tree arg0 = CALL_EXPR_ARG (arg, 0);
- tree tree_root;
- /* The inner root was either sqrt or cbrt. */
- /* This was a conditional expression but it triggered a bug
- in Sun C 5.5. */
- REAL_VALUE_TYPE dconstroot;
- if (BUILTIN_SQRT_P (fcode))
- dconstroot = dconsthalf;
- else
- dconstroot = dconst_third ();
-
- /* Adjust for the outer root. */
- SET_REAL_EXP (&dconstroot, REAL_EXP (&dconstroot) - 1);
- tree_root = build_real_truncate (type, dconstroot);
- return build_call_expr_loc (loc, powfn, 2, arg0, tree_root);
+ tree arg1 = (BUILTIN_SQRT_P (fcode)
+ ? build_real (type, dconst_quarter ())
+ : build_real_truncate (type, dconst_sixth ()));
+ return build_call_expr_loc (loc, powfn, 2, arg0, arg1);
}
}
@@ -7815,11 +7805,7 @@ fold_builtin_cbrt (location_t loc, tree arg, tree type)
if (powfn)
{
tree arg0 = CALL_EXPR_ARG (arg, 0);
- tree tree_root;
- REAL_VALUE_TYPE dconstroot = dconst_third ();
-
- SET_REAL_EXP (&dconstroot, REAL_EXP (&dconstroot) - 1);
- tree_root = build_real_truncate (type, dconstroot);
+ tree tree_root = build_real_truncate (type, dconst_sixth ());
return build_call_expr_loc (loc, powfn, 2, arg0, tree_root);
}
}
@@ -7834,12 +7820,7 @@ fold_builtin_cbrt (location_t loc, tree arg, tree type)
if (powfn)
{
- tree tree_root;
- REAL_VALUE_TYPE dconstroot;
-
- real_arithmetic (&dconstroot, MULT_EXPR,
- dconst_third_ptr (), dconst_third_ptr ());
- tree_root = build_real_truncate (type, dconstroot);
+ tree tree_root = build_real_truncate (type, dconst_ninth ());
return build_call_expr_loc (loc, powfn, 2, arg0, tree_root);
}
}