From: Kaveh R. Ghazi Date: Sun, 12 Nov 2006 23:51:36 +0000 (+0000) Subject: builtins.c (fold_builtin_cosh): New. X-Git-Tag: releases/gcc-4.3.0~8508 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c5b21550c5b1b9631b0d14569cc47f6d16dfc7b;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 22b956f1ff5f..0eacd1e7b8bc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2006-11-12 Kaveh R. Ghazi + + * 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 * tree-flow.h (name_mappings_registered_p): Declare. diff --git a/gcc/builtins.c b/gcc/builtins.c index 3d82b6b2eb8f..b9005b48799c 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 cf1df69c4683..eeec0c175bd4 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 71597e25d1c4..7237d4f2b7d5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2006-11-12 Kaveh R. Ghazi + + * gcc.dg/torture/builtin-symmetric-1.c: Add more cases. + 2006-11-12 Zdenek Dvorak * 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 49be06f8f846..b8ea99d84cf7 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; }