aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>2004-05-01 01:51:33 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2004-05-01 01:51:33 +0000
commit3bf05748728b93e0241a62bb0926ec12a58f01f6 (patch)
treec6cc39f425e081d97178cd6f716c458a546f39c4 /gcc/builtins.c
parentc08732313cfc81fadfe6487a722f16931f9dae6a (diff)
downloadgcc-3bf05748728b93e0241a62bb0926ec12a58f01f6.zip
gcc-3bf05748728b93e0241a62bb0926ec12a58f01f6.tar.gz
gcc-3bf05748728b93e0241a62bb0926ec12a58f01f6.tar.bz2
builtins.c (fold_builtin_round): Fix comment typo.
* builtins.c (fold_builtin_round): Fix comment typo. (fold_builtin_lround): New function. (fold_builtin): Use it. testsuite: * gcc.dg/torture/builtin-rounding-1.c: New test. * gcc.dg/builtins-25.c: Delete. * gcc.dg/builtins-29.c: Delete. From-SVN: r81380
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 3130f3b..0d04f03 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -6254,7 +6254,7 @@ fold_builtin_round (tree exp)
if (! validate_arglist (arglist, REAL_TYPE, VOID_TYPE))
return 0;
- /* Optimize ceil of constant value. */
+ /* Optimize round of constant value. */
arg = TREE_VALUE (arglist);
if (TREE_CODE (arg) == REAL_CST && ! TREE_CONSTANT_OVERFLOW (arg))
{
@@ -6274,6 +6274,42 @@ fold_builtin_round (tree exp)
return fold_trunc_transparent_mathfn (exp);
}
+/* Fold function call to builtin lround, lroundf or lroundl (or the
+ corresponding long long versions). Return NULL_TREE if no
+ simplification can be made. */
+
+static tree
+fold_builtin_lround (tree exp)
+{
+ tree arglist = TREE_OPERAND (exp, 1);
+ tree arg;
+
+ if (! validate_arglist (arglist, REAL_TYPE, VOID_TYPE))
+ return 0;
+
+ /* Optimize lround of constant value. */
+ arg = TREE_VALUE (arglist);
+ if (TREE_CODE (arg) == REAL_CST && ! TREE_CONSTANT_OVERFLOW (arg))
+ {
+ const REAL_VALUE_TYPE x = TREE_REAL_CST (arg);
+
+ if (! REAL_VALUE_ISNAN (x) && ! REAL_VALUE_ISINF (x))
+ {
+ tree itype = TREE_TYPE (exp), ftype = TREE_TYPE (arg), result;
+ HOST_WIDE_INT hi, lo;
+ REAL_VALUE_TYPE r;
+
+ real_round (&r, TYPE_MODE (ftype), &x);
+ REAL_VALUE_TO_INT (&lo, &hi, r);
+ result = build_int_2 (lo, hi);
+ if (int_fits_type_p (result, itype))
+ return fold_convert (itype, result);
+ }
+ }
+
+ return 0;
+}
+
/* Fold function call to builtin ffs, clz, ctz, popcount and parity
and their long and long long variants (i.e. ffsl and ffsll).
Return NULL_TREE if no simplification can be made. */
@@ -7376,6 +7412,14 @@ fold_builtin (tree exp)
case BUILT_IN_RINTL:
return fold_trunc_transparent_mathfn (exp);
+ case BUILT_IN_LROUND:
+ case BUILT_IN_LROUNDF:
+ case BUILT_IN_LROUNDL:
+ case BUILT_IN_LLROUND:
+ case BUILT_IN_LLROUNDF:
+ case BUILT_IN_LLROUNDL:
+ return fold_builtin_lround (exp);
+
case BUILT_IN_FFS:
case BUILT_IN_FFSL:
case BUILT_IN_FFSLL: