re PR fortran/17030 (gfortran does not optimize ABS of complex that well)
authorAndrew Pinski <apinski@apple.com>
Sun, 15 Aug 2004 19:26:32 +0000 (19:26 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Sun, 15 Aug 2004 19:26:32 +0000 (12:26 -0700)
2004-08-15  Andrew Pinski  <apinski@apple.com>

        PR fortran/17030
        * f95-lang.c (gfc_init_builtin_functions): Initialize the builtins
        for cabs{,f} and copysign{,f}.
        * trans-decl.c (gfor_fndecl_math_cabsf): Delete.
        (gfor_fndecl_math_cabs): Delete.
        (gfor_fndecl_math_sign4): Delete.
        (gfor_fndecl_math_sign8): Delete.
        (gfc_build_intrinsic_function_decls): Remove the
        initializing of cabs{,f} and copysign{,f} functions.
        * trans-intrinsic.c (gfc_conv_intrinsic_abs): Use the builtins
        instead of the functions definitions.
        (gfc_conv_intrinsic_sign): Likewise.
        * trans.h (gfor_fndecl_math_cabsf): Delete.
        (gfor_fndecl_math_cabs): Delete.
        (gfor_fndecl_math_sign4): Delete.
        (gfor_fndecl_math_sign8): Delete.

From-SVN: r86027

gcc/fortran/ChangeLog
gcc/fortran/f95-lang.c
gcc/fortran/trans-decl.c
gcc/fortran/trans-intrinsic.c
gcc/fortran/trans.h

index 460263611f3ce0c81d66c99d1931c41b5c58edff..e0d97f2648c1926dde96ebe7114591514563d8b5 100644 (file)
@@ -1,3 +1,22 @@
+2004-08-15  Andrew Pinski  <apinski@apple.com>
+
+       PR fortran/17030
+       * f95-lang.c (gfc_init_builtin_functions): Initialize the builtins
+       for cabs{,f} and copysign{,f}.
+       * trans-decl.c (gfor_fndecl_math_cabsf): Delete. 
+       (gfor_fndecl_math_cabs): Delete. 
+       (gfor_fndecl_math_sign4): Delete. 
+       (gfor_fndecl_math_sign8): Delete. 
+       (gfc_build_intrinsic_function_decls): Remove the
+       initializing of cabs{,f} and copysign{,f} functions.
+       * trans-intrinsic.c (gfc_conv_intrinsic_abs): Use the builtins
+       instead of the functions definitions.
+       (gfc_conv_intrinsic_sign): Likewise.
+       * trans.h (gfor_fndecl_math_cabsf): Delete. 
+       (gfor_fndecl_math_cabs): Delete. 
+       (gfor_fndecl_math_sign4): Delete. 
+       (gfor_fndecl_math_sign8): Delete. 
+
 2004-08-15  Nathan Sidwell  <nathan@codesourcery.com>
 
        * trans-array.c (gfc_trans_array_constructor_value): Use
index 3e8320c3f44de2847b5d61f71a8e51ab6dbb3ba7..aee5c9594a48a947c63111e6dd532d043707ffde 100644 (file)
@@ -723,6 +723,8 @@ gfc_init_builtin_functions (void)
 {
   tree mfunc_float[2];
   tree mfunc_double[2];
+  tree func_cfloat_float;
+  tree func_cdouble_double;
   tree ftype;
   tree tmp;
 
@@ -730,11 +732,19 @@ gfc_init_builtin_functions (void)
   mfunc_float[0] = build_function_type (float_type_node, tmp);
   tmp = tree_cons (NULL_TREE, float_type_node, tmp);
   mfunc_float[1] = build_function_type (float_type_node, tmp);
+  
+  tmp = tree_cons (NULL_TREE, complex_float_type_node, void_list_node);
+  func_cfloat_float = build_function_type (float_type_node, tmp);
+  
 
   tmp = tree_cons (NULL_TREE, double_type_node, void_list_node);
   mfunc_double[0] = build_function_type (double_type_node, tmp);
   tmp = tree_cons (NULL_TREE, double_type_node, tmp);
   mfunc_double[1] = build_function_type (double_type_node, tmp);
+  
+  
+  tmp = tree_cons (NULL_TREE, complex_double_type_node, void_list_node);
+  func_cdouble_double = build_function_type (double_type_node, tmp);
 
 #include "mathbuiltins.def"
 
@@ -748,6 +758,17 @@ gfc_init_builtin_functions (void)
                      BUILT_IN_ROUND, "round", true);
   gfc_define_builtin ("__builtin_roundf", mfunc_float[0], 
                      BUILT_IN_ROUNDF, "roundf", true);
+  
+  gfc_define_builtin ("__builtin_cabs", func_cdouble_double, 
+                     BUILT_IN_CABS, "cabs", true);
+  gfc_define_builtin ("__builtin_cabsf", func_cfloat_float, 
+                     BUILT_IN_CABSF, "cabsf", true);
+                     
+  
+  gfc_define_builtin ("__builtin_copysign", mfunc_double[1], 
+                     BUILT_IN_COPYSIGN, "copysign", true);
+  gfc_define_builtin ("__builtin_copysignf", mfunc_float[1], 
+                     BUILT_IN_COPYSIGNF, "copysignf", true);
 
   /* These are used to implement the ** operator.  */
   gfc_define_builtin ("__builtin_pow", mfunc_double[1], 
index ef802ecee7fc28d441820105fed86eb12967ee22..d9476b8220135cf51e5182ef8b301592f58d80c3 100644 (file)
@@ -96,10 +96,6 @@ tree gfor_fndecl_associated;
 gfc_powdecl_list gfor_fndecl_math_powi[3][2];
 tree gfor_fndecl_math_cpowf;
 tree gfor_fndecl_math_cpow;
-tree gfor_fndecl_math_cabsf;
-tree gfor_fndecl_math_cabs;
-tree gfor_fndecl_math_sign4;
-tree gfor_fndecl_math_sign8;
 tree gfor_fndecl_math_ishftc4;
 tree gfor_fndecl_math_ishftc8;
 tree gfor_fndecl_math_exponent4;
@@ -1460,22 +1456,6 @@ gfc_build_intrinsic_function_decls (void)
     gfc_build_library_function_decl (get_identifier ("cpow"),
                                     gfc_complex8_type_node,
                                     1, gfc_complex8_type_node);
-  gfor_fndecl_math_cabsf =
-    gfc_build_library_function_decl (get_identifier ("cabsf"),
-                                    gfc_real4_type_node,
-                                    1, gfc_complex4_type_node);
-  gfor_fndecl_math_cabs =
-    gfc_build_library_function_decl (get_identifier ("cabs"),
-                                    gfc_real8_type_node,
-                                    1, gfc_complex8_type_node);
-  gfor_fndecl_math_sign4 =
-    gfc_build_library_function_decl (get_identifier ("copysignf"),
-                                    gfc_real4_type_node,
-                                    1, gfc_real4_type_node);
-  gfor_fndecl_math_sign8 =
-    gfc_build_library_function_decl (get_identifier ("copysign"),
-                                    gfc_real8_type_node,
-                                    1, gfc_real8_type_node);
   gfor_fndecl_math_ishftc4 =
     gfc_build_library_function_decl (get_identifier (PREFIX("ishftc4")),
                                     gfc_int4_type_node,
index c580cd4a42b7af380eba2d68f1ce3d892c58be5c..1a8a8b6f70b1e566d5d554c871f57df9a1aadd88 100644 (file)
@@ -703,7 +703,7 @@ gfc_conv_intrinsic_abs (gfc_se * se, gfc_expr * expr)
 {
   tree args;
   tree val;
-  tree fndecl;
+  int n;
 
   args = gfc_conv_intrinsic_function_args (se, expr);
   assert (args && TREE_CHAIN (args) == NULL_TREE);
@@ -720,15 +720,15 @@ gfc_conv_intrinsic_abs (gfc_se * se, gfc_expr * expr)
       switch (expr->ts.kind)
        {
        case 4:
-         fndecl = gfor_fndecl_math_cabsf;
+         n = BUILT_IN_CABSF;
          break;
        case 8:
-         fndecl = gfor_fndecl_math_cabs;
+         n = BUILT_IN_CABS;
          break;
        default:
          abort ();
        }
-      se->expr = gfc_build_function_call (fndecl, args);
+      se->expr = fold (gfc_build_function_call (built_in_decls[n], args));
       break;
 
     default:
@@ -893,15 +893,15 @@ gfc_conv_intrinsic_sign (gfc_se * se, gfc_expr * expr)
       switch (expr->ts.kind)
        {
        case 4:
-         tmp = gfor_fndecl_math_sign4;
+         tmp = built_in_decls[BUILT_IN_COPYSIGNF];
          break;
        case 8:
-         tmp = gfor_fndecl_math_sign8;
+         tmp = built_in_decls[BUILT_IN_COPYSIGN];
          break;
        default:
          abort ();
        }
-      se->expr = gfc_build_function_call (tmp, arg);
+      se->expr = fold (gfc_build_function_call (tmp, arg));
       return;
     }
 
index 51c63ce56864088221a7959bf4dd0858d5b998b2..7f9e997f83b493824afa9e547ab0bbe2b65f7ea5 100644 (file)
@@ -465,10 +465,6 @@ gfc_powdecl_list;
 extern GTY(()) gfc_powdecl_list gfor_fndecl_math_powi[3][2];
 extern GTY(()) tree gfor_fndecl_math_cpowf;
 extern GTY(()) tree gfor_fndecl_math_cpow;
-extern GTY(()) tree gfor_fndecl_math_cabsf;
-extern GTY(()) tree gfor_fndecl_math_cabs;
-extern GTY(()) tree gfor_fndecl_math_sign4;
-extern GTY(()) tree gfor_fndecl_math_sign8;
 extern GTY(()) tree gfor_fndecl_math_ishftc4;
 extern GTY(()) tree gfor_fndecl_math_ishftc8;
 extern GTY(()) tree gfor_fndecl_math_exponent4;