(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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@118733
138bc75d-0d04-0410-961f-
82ee72b054a4
+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.
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);
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
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))
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;
}
+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.
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)) \
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;
}