]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
builtins.c (fold_builtin_carg): New.
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>
Thu, 25 Jan 2007 03:57:30 +0000 (03:57 +0000)
committerKaveh Ghazi <ghazi@gcc.gnu.org>
Thu, 25 Jan 2007 03:57:30 +0000 (03:57 +0000)
* builtins.c (fold_builtin_carg): New.
(fold_builtin_1): Use it.

testsuite:
* gcc.dg/builtins-20.c: Test builtin carg.

From-SVN: r121159

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/builtins-20.c

index c750497c2528219672323f2b5eb7255ed794e889..f0167fa7df61ce05bbfbd8b8a3c4d0919b21dfa6 100644 (file)
@@ -1,3 +1,8 @@
+2007-01-24  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * builtins.c (fold_builtin_carg): New.
+       (fold_builtin_1): Use it.
+
 2007-01-24  Jan Hubicka  <jh@suse.cz>
 
        * ipa-inline.c (cgraph_decide_inlining): Initialize initial_insns.
index 240231e538b39dd6a8f34d97679447bb4e7d6c82..19e7d345e53df3a310ed8bcf404c8128f4671689 100644 (file)
@@ -9058,6 +9058,29 @@ fold_builtin_fmin_fmax (tree arglist, tree type, bool max)
   return NULL_TREE;
 }
 
+/* Fold a call to builtin carg(a+bi) -> atan2(b,a).  */
+
+static tree
+fold_builtin_carg(tree arglist, tree type)
+{
+  if (validate_arglist (arglist, COMPLEX_TYPE, VOID_TYPE))
+    {
+      tree atan2_fn = mathfn_built_in (type, BUILT_IN_ATAN2);
+      
+      if (atan2_fn)
+        {
+         tree arg = builtin_save_expr (TREE_VALUE (arglist));
+         tree r_arg = fold_build1 (REALPART_EXPR, type, arg);
+         tree i_arg = fold_build1 (IMAGPART_EXPR, type, arg);
+         tree newarglist = tree_cons (NULL_TREE, i_arg,
+                                      build_tree_list (NULL_TREE, r_arg));
+         return build_function_call_expr (atan2_fn, newarglist);
+       }
+    }
+  
+  return NULL_TREE;
+}
+
 /* Fold a call to __builtin_isnan(), __builtin_isinf, __builtin_finite.
    EXP is the CALL_EXPR for the call.  */
 
@@ -9339,6 +9362,9 @@ fold_builtin_1 (tree fndecl, tree arglist, bool ignore)
     CASE_FLT_FN (BUILT_IN_CABS):
       return fold_builtin_cabs (arglist, type, fndecl);
 
+    CASE_FLT_FN (BUILT_IN_CARG):
+      return fold_builtin_carg (arglist, type);
+
     CASE_FLT_FN (BUILT_IN_SQRT):
       return fold_builtin_sqrt (arglist, type);
 
index 3f42ce95963ea2c46f9982a082301a9f36256f6f..a2e86f4ba579719cc99b765b091493b6802807df 100644 (file)
@@ -1,3 +1,7 @@
+2007-01-24  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * gcc.dg/builtins-20.c: Test builtin carg.
+
 2007-01-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/27416
index 1211cf0b6cd42289722b04ebd394fb0bfa1a7a99..be3c81daea31fe3e733dc5c353699635b9ae21e9 100644 (file)
@@ -16,29 +16,35 @@ extern double cos (double);
 extern double sin (double);
 extern double tan (double);
 extern double fabs (double);
+extern double atan2 (double, double);
 extern double copysign (double, double);
 extern double fmin (double, double);
 extern double fmax (double, double);
 extern double hypot (double, double);
 extern double pure (double) __attribute__ ((__pure__));
+extern double carg (__complex__ double);
 extern float cosf (float);
 extern float sinf (float);
 extern float tanf (float);
 extern float fabsf (float);
+extern float atan2f (float, float);
 extern float copysignf (float, float);
 extern float fminf (float, float);
 extern float fmaxf (float, float);
 extern float hypotf (float, float);
 extern float puref (float) __attribute__ ((__pure__));
+extern float cargf (__complex__ float);
 extern long double cosl (long double);
 extern long double sinl (long double);
 extern long double tanl (long double);
 extern long double fabsl (long double);
+extern long double atan2l (long double, long double);
 extern long double copysignl (long double, long double);
 extern long double fminl (long double, long double);
 extern long double fmaxl (long double, long double);
 extern long double hypotl (long double, long double);
 extern long double purel (long double) __attribute__ ((__pure__));
+extern long double cargl (__complex__ long double);
 
 extern void link_error(void);
 
@@ -187,6 +193,12 @@ void test2(double x, double y)
     link_error ();
 }
 
+void test3(__complex__ double z)
+{
+  if (carg(z) != atan2(__imag__ z, __real__ z))
+    link_error ();
+}
+
 void test1f(float x)
 {
   if (cosf(x) != cosf(-x))
@@ -334,6 +346,11 @@ void test2f(float x, float y)
     link_error ();
 }
 
+void test3f(__complex__ float z)
+{
+  if (cargf(z) != atan2f(__imag__ z, __real__ z))
+    link_error ();
+}
 
 void test1l(long double x)
 {
@@ -482,6 +499,12 @@ void test2l(long double x, long double y)
     link_error ();
 }
 
+void test3l(__complex__ long double z)
+{
+  if (cargl(z) != atan2l(__imag__ z, __real__ z))
+    link_error ();
+}
+
 int main()
 {
   test1 (1.0);