aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>2006-11-12 23:51:36 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2006-11-12 23:51:36 +0000
commit5c5b21550c5b1b9631b0d14569cc47f6d16dfc7b (patch)
tree9a539cef8be2437dc8b524015aa3a340c925fa7d /gcc
parent8f8bb1d2008496ba3856bc12f8b2cae12195c235 (diff)
downloadgcc-5c5b21550c5b1b9631b0d14569cc47f6d16dfc7b.zip
gcc-5c5b21550c5b1b9631b0d14569cc47f6d16dfc7b.tar.gz
gcc-5c5b21550c5b1b9631b0d14569cc47f6d16dfc7b.tar.bz2
builtins.c (fold_builtin_cosh): New.
* builtins.c (fold_builtin_cosh): New. (fold_builtin_1): Use it. * fold-const.c (negate_mathfn_p): Add llround, lround, round, trunc to the list of "odd" functions. Also add llrint, lrint, rint and nearbyint when flag_rounding_math is false. testsuite: * gcc.dg/torture/builtin-symmetric-1.c: Add more cases. From-SVN: r118733
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/builtins.c29
-rw-r--r--gcc/fold-const.c12
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/torture/builtin-symmetric-1.c28
5 files changed, 73 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 22b956f..0eacd1e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2006-11-12 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * builtins.c (fold_builtin_cosh): New.
+ (fold_builtin_1): Use it.
+ * fold-const.c (negate_mathfn_p): Add llround, lround, round,
+ trunc to the list of "odd" functions. Also add llrint, lrint,
+ rint and nearbyint when flag_rounding_math is false.
+
2006-11-12 Zdenek Dvorak <dvorakz@suse.cz>
* tree-flow.h (name_mappings_registered_p): Declare.
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 3d82b6b..b9005b4 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -151,6 +151,7 @@ static tree fold_builtin_cbrt (tree, tree);
static tree fold_builtin_pow (tree, tree, tree);
static tree fold_builtin_powi (tree, tree, tree);
static tree fold_builtin_cos (tree, tree, tree);
+static tree fold_builtin_cosh (tree, tree, tree);
static tree fold_builtin_tan (tree, tree);
static tree fold_builtin_trunc (tree, tree);
static tree fold_builtin_floor (tree, tree);
@@ -7121,6 +7122,29 @@ fold_builtin_cos (tree arglist, tree type, tree fndecl)
return NULL_TREE;
}
+/* Fold function call to builtin cosh, coshf, or coshl. Return
+ NULL_TREE if no simplification can be made. */
+static tree
+fold_builtin_cosh (tree arglist, tree type, tree fndecl)
+{
+ if (validate_arglist (arglist, REAL_TYPE, VOID_TYPE))
+ {
+ tree arg = TREE_VALUE (arglist);
+ tree res, narg;
+
+ /* Calculate the result when the argument is a constant. */
+ if ((res = do_mpfr_arg1 (arg, type, mpfr_cosh, NULL, NULL, 0)))
+ return res;
+
+ /* Optimize cosh(-x) into cosh (x). */
+ if ((narg = fold_strip_sign_ops (arg)))
+ return build_function_call_expr (fndecl,
+ build_tree_list (NULL_TREE, narg));
+ }
+
+ return NULL_TREE;
+}
+
/* Fold function call to builtin tan, tanf, or tanl. Return
NULL_TREE if no simplification can be made. */
static tree
@@ -9046,10 +9070,7 @@ fold_builtin_1 (tree fndecl, tree arglist, bool ignore)
break;
CASE_FLT_FN (BUILT_IN_COSH):
- if (validate_arglist (arglist, REAL_TYPE, VOID_TYPE))
- return do_mpfr_arg1 (TREE_VALUE (arglist), type, mpfr_cosh,
- NULL, NULL, 0);
- break;
+ return fold_builtin_cosh (arglist, type, fndecl);
CASE_FLT_FN (BUILT_IN_TANH):
if (validate_arglist (arglist, REAL_TYPE, VOID_TYPE))
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index cf1df69..eeec0c1 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -890,13 +890,23 @@ negate_mathfn_p (enum built_in_function code)
CASE_FLT_FN (BUILT_IN_ATAN):
CASE_FLT_FN (BUILT_IN_ATANH):
CASE_FLT_FN (BUILT_IN_CBRT):
+ CASE_FLT_FN (BUILT_IN_ERF):
+ CASE_FLT_FN (BUILT_IN_LLROUND):
+ CASE_FLT_FN (BUILT_IN_LROUND):
+ CASE_FLT_FN (BUILT_IN_ROUND):
CASE_FLT_FN (BUILT_IN_SIN):
CASE_FLT_FN (BUILT_IN_SINH):
CASE_FLT_FN (BUILT_IN_TAN):
CASE_FLT_FN (BUILT_IN_TANH):
- CASE_FLT_FN (BUILT_IN_ERF):
+ CASE_FLT_FN (BUILT_IN_TRUNC):
return true;
+ CASE_FLT_FN (BUILT_IN_LLRINT):
+ CASE_FLT_FN (BUILT_IN_LRINT):
+ CASE_FLT_FN (BUILT_IN_NEARBYINT):
+ CASE_FLT_FN (BUILT_IN_RINT):
+ return !flag_rounding_math;
+
default:
break;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 71597e2..7237d4f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2006-11-12 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * gcc.dg/torture/builtin-symmetric-1.c: Add more cases.
+
2006-11-12 Zdenek Dvorak <dvorakz@suse.cz>
* gcc.dg/tree-ssa/prefetch-3.c: New test.
diff --git a/gcc/testsuite/gcc.dg/torture/builtin-symmetric-1.c b/gcc/testsuite/gcc.dg/torture/builtin-symmetric-1.c
index 49be06f..b8ea99d 100644
--- a/gcc/testsuite/gcc.dg/torture/builtin-symmetric-1.c
+++ b/gcc/testsuite/gcc.dg/torture/builtin-symmetric-1.c
@@ -21,6 +21,12 @@ extern void link_error(int);
link_error(__LINE__); \
} while (0)
+/* Test that FUNC(-VAR) == FUNC(VAR), where VAR has an int type. */
+#define TESTIT_EVEN_I(FUNC,VAR) do { \
+ if (__builtin_##FUNC(-VAR) != __builtin_##FUNC(VAR)) \
+ link_error(__LINE__); \
+ } while (0)
+
/* Test that -FUNC(ARG) == FUNC(-ARG). */
#define TESTIT_ODD(FUNC) do { \
if (-__builtin_##FUNC##f(-xf) != __builtin_##FUNC##f(xf)) \
@@ -31,24 +37,40 @@ extern void link_error(int);
link_error(__LINE__); \
} while (0)
-void foo (float xf, double x, long double xl)
+void foo (float xf, double x, long double xl,
+ int i, long l, long long ll, __INTMAX_TYPE__ im)
{
TESTIT_EVEN(cos);
+ TESTIT_EVEN(cosh);
+ TESTIT_EVEN(fabs);
+
+ TESTIT_EVEN_I(abs, i);
+ TESTIT_EVEN_I(imaxabs, im);
+ TESTIT_EVEN_I(labs, l);
+ TESTIT_EVEN_I(llabs, ll);
TESTIT_ODD(asin);
TESTIT_ODD(asinh);
TESTIT_ODD(atan);
TESTIT_ODD(atanh);
TESTIT_ODD(cbrt);
+ TESTIT_ODD(erf);
+ TESTIT_ODD(llrint);
+ TESTIT_ODD(llround);
+ TESTIT_ODD(lrint);
+ TESTIT_ODD(lround);
+ TESTIT_ODD(nearbyint);
+ TESTIT_ODD(rint);
+ TESTIT_ODD(round);
TESTIT_ODD(sin);
TESTIT_ODD(sinh);
TESTIT_ODD(tan);
TESTIT_ODD(tanh);
- TESTIT_ODD(erf);
+ TESTIT_ODD(trunc);
}
int main()
{
- foo (1,1,1);
+ foo (1,1,1,1,1,1,1);
return 0;
}