* builtins.c (fold_builtin_cosh): New.
authorghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 12 Nov 2006 23:51:36 +0000 (23:51 +0000)
committerghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 12 Nov 2006 23:51:36 +0000 (23:51 +0000)
(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

gcc/ChangeLog
gcc/builtins.c
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/builtin-symmetric-1.c

index 22b956f..0eacd1e 100644 (file)
@@ -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.
index 3d82b6b..b9005b4 100644 (file)
@@ -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))
index cf1df69..eeec0c1 100644 (file)
@@ -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;
     }
index 71597e2..7237d4f 100644 (file)
@@ -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.
index 49be06f..b8ea99d 100644 (file)
@@ -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;
 }