From ead6d15f70bfdd702d3a7a4fbf3eaab14afcba82 Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Sun, 15 Aug 2004 19:26:32 +0000 Subject: [PATCH] re PR fortran/17030 (gfortran does not optimize ABS of complex that well) 2004-08-15 Andrew Pinski 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 | 19 +++++++++++++++++++ gcc/fortran/f95-lang.c | 21 +++++++++++++++++++++ gcc/fortran/trans-decl.c | 20 -------------------- gcc/fortran/trans-intrinsic.c | 14 +++++++------- gcc/fortran/trans.h | 4 ---- 5 files changed, 47 insertions(+), 31 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 460263611f3..e0d97f2648c 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,22 @@ +2004-08-15 Andrew Pinski + + 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 * trans-array.c (gfc_trans_array_constructor_value): Use diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c index 3e8320c3f44..aee5c9594a4 100644 --- a/gcc/fortran/f95-lang.c +++ b/gcc/fortran/f95-lang.c @@ -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], diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index ef802ecee7f..d9476b82201 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -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, diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index c580cd4a42b..1a8a8b6f70b 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -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; } diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h index 51c63ce5686..7f9e997f83b 100644 --- a/gcc/fortran/trans.h +++ b/gcc/fortran/trans.h @@ -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; -- 2.30.2