From patchwork Tue Jul 13 20:28:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Mark several libgfortran helpers as DECL_PURE_P or TREE_READONLY in the FE From: Jakub Jelinek X-Patchwork-Id: 58816 Message-Id: <20100713202829.GE20208@tyan-ft48-01.lab.bos.redhat.com> To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Date: Tue, 13 Jul 2010 22:28:32 +0200 Hi! I was quite surprised that in subroutine foo (c) character :: c if (c .eq. 'a') call abort if (c .eq. 'ab') call abort if (c .eq. 'a') call abort end subroutine the third test hasn't been optimized away. The problem is just that apparently many of the decls in fortran FE aren't marked DECL_PURE_P when they really are pure. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux. Ok for trunk? 2010-07-13 Jakub Jelinek * trans-decl.c (gfc_build_intrinsic_function_decls, gfc_build_builtin_function_decls): Mark functions as DECL_PURE_P or TREE_READONLY. Jakub --- gcc/fortran/trans-decl.c.jj 2010-07-13 15:56:30.000000000 +0200 +++ gcc/fortran/trans-decl.c 2010-07-13 17:45:07.000000000 +0200 @@ -2415,6 +2415,7 @@ gfc_build_intrinsic_function_decls (void get_identifier (PREFIX("compare_string")), "..R.R", integer_type_node, 4, gfc_charlen_type_node, pchar1_type_node, gfc_charlen_type_node, pchar1_type_node); + DECL_PURE_P (gfor_fndecl_compare_string) = 1; gfor_fndecl_concat_string = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("concat_string")), "..W.R.R", @@ -2425,21 +2426,25 @@ gfc_build_intrinsic_function_decls (void gfor_fndecl_string_len_trim = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("string_len_trim")), "..R", gfc_charlen_type_node, 2, gfc_charlen_type_node, pchar1_type_node); + DECL_PURE_P (gfor_fndecl_string_len_trim) = 1; gfor_fndecl_string_index = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("string_index")), "..R.R.", gfc_charlen_type_node, 5, gfc_charlen_type_node, pchar1_type_node, gfc_charlen_type_node, pchar1_type_node, gfc_logical4_type_node); + DECL_PURE_P (gfor_fndecl_string_index) = 1; gfor_fndecl_string_scan = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("string_scan")), "..R.R.", gfc_charlen_type_node, 5, gfc_charlen_type_node, pchar1_type_node, gfc_charlen_type_node, pchar1_type_node, gfc_logical4_type_node); + DECL_PURE_P (gfor_fndecl_string_scan) = 1; gfor_fndecl_string_verify = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("string_verify")), "..R.R.", gfc_charlen_type_node, 5, gfc_charlen_type_node, pchar1_type_node, gfc_charlen_type_node, pchar1_type_node, gfc_logical4_type_node); + DECL_PURE_P (gfor_fndecl_string_verify) = 1; gfor_fndecl_string_trim = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("string_trim")), ".Ww.R", @@ -2467,11 +2472,13 @@ gfc_build_intrinsic_function_decls (void get_identifier (PREFIX("select_string")), ".R.R.", integer_type_node, 4, pvoid_type_node, integer_type_node, pchar1_type_node, gfc_charlen_type_node); + DECL_PURE_P (gfor_fndecl_select_string) = 1; gfor_fndecl_compare_string_char4 = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("compare_string_char4")), "..R.R", integer_type_node, 4, gfc_charlen_type_node, pchar4_type_node, gfc_charlen_type_node, pchar4_type_node); + DECL_PURE_P (gfor_fndecl_compare_string_char4) = 1; gfor_fndecl_concat_string_char4 = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("concat_string_char4")), "..W.R.R", @@ -2482,21 +2489,25 @@ gfc_build_intrinsic_function_decls (void gfor_fndecl_string_len_trim_char4 = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("string_len_trim_char4")), "..R", gfc_charlen_type_node, 2, gfc_charlen_type_node, pchar4_type_node); + DECL_PURE_P (gfor_fndecl_string_len_trim_char4) = 1; gfor_fndecl_string_index_char4 = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("string_index_char4")), "..R.R.", gfc_charlen_type_node, 5, gfc_charlen_type_node, pchar4_type_node, gfc_charlen_type_node, pchar4_type_node, gfc_logical4_type_node); + DECL_PURE_P (gfor_fndecl_string_index_char4) = 1; gfor_fndecl_string_scan_char4 = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("string_scan_char4")), "..R.R.", gfc_charlen_type_node, 5, gfc_charlen_type_node, pchar4_type_node, gfc_charlen_type_node, pchar4_type_node, gfc_logical4_type_node); + DECL_PURE_P (gfor_fndecl_string_scan_char4) = 1; gfor_fndecl_string_verify_char4 = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("string_verify_char4")), "..R.R.", gfc_charlen_type_node, 5, gfc_charlen_type_node, pchar4_type_node, gfc_charlen_type_node, pchar4_type_node, gfc_logical4_type_node); + DECL_PURE_P (gfor_fndecl_string_verify_char4) = 1; gfor_fndecl_string_trim_char4 = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("string_trim_char4")), ".Ww.R", @@ -2524,6 +2535,7 @@ gfc_build_intrinsic_function_decls (void get_identifier (PREFIX("select_string_char4")), ".R.R.", integer_type_node, 4, pvoid_type_node, integer_type_node, pvoid_type_node, gfc_charlen_type_node); + DECL_PURE_P (gfor_fndecl_select_string_char4) = 1; /* Conversion between character kinds. */ @@ -2557,15 +2569,18 @@ gfc_build_intrinsic_function_decls (void gfor_fndecl_sc_kind = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("selected_char_kind")), "..R", gfc_int4_type_node, 2, gfc_charlen_type_node, pchar_type_node); + DECL_PURE_P (gfor_fndecl_sc_kind) = 1; gfor_fndecl_si_kind = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("selected_int_kind")), ".R", gfc_int4_type_node, 1, pvoid_type_node); + DECL_PURE_P (gfor_fndecl_si_kind) = 1; gfor_fndecl_sr_kind = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("selected_real_kind2008")), ".RR", gfc_int4_type_node, 3, pvoid_type_node, pvoid_type_node, pvoid_type_node); + DECL_PURE_P (gfor_fndecl_sr_kind) = 1; /* Power functions. */ { @@ -2687,10 +2702,12 @@ gfc_build_intrinsic_function_decls (void gfor_fndecl_size0 = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("size0")), ".R", gfc_array_index_type, 1, pvoid_type_node); + DECL_PURE_P (gfor_fndecl_size0) = 1; gfor_fndecl_size1 = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("size1")), ".R", gfc_array_index_type, 2, pvoid_type_node, gfc_array_index_type); + DECL_PURE_P (gfor_fndecl_size1) = 1; gfor_fndecl_iargc = gfc_build_library_function_decl ( get_identifier (PREFIX ("iargc")), gfc_int4_type_node, 0); @@ -2701,9 +2718,11 @@ gfc_build_intrinsic_function_decls (void gfor_fndecl_clz128 = gfc_build_library_function_decl ( get_identifier (PREFIX ("clz128")), integer_type_node, 1, uint128); + TREE_READONLY (gfor_fndecl_clz128) = 1; gfor_fndecl_ctz128 = gfc_build_library_function_decl ( get_identifier (PREFIX ("ctz128")), integer_type_node, 1, uint128); + TREE_READONLY (gfor_fndecl_ctz128) = 1; } } @@ -2725,8 +2744,8 @@ gfc_build_builtin_function_decls (void) get_identifier (PREFIX("stop_string")), ".R.", void_type_node, 2, pchar_type_node, gfc_int4_type_node); /* STOP doesn't return. */ - TREE_THIS_VOLATILE (gfor_fndecl_stop_string) = 1; + gfor_fndecl_error_stop_numeric = gfc_build_library_function_decl ( get_identifier (PREFIX("error_stop_numeric")), void_type_node, 1, gfc_int4_type_node); @@ -2812,6 +2831,7 @@ gfc_build_builtin_function_decls (void) gfor_fndecl_associated = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("associated")), ".RR", integer_type_node, 2, ppvoid_type_node, ppvoid_type_node); + DECL_PURE_P (gfor_fndecl_associated) = 1; gfc_build_intrinsic_function_decls (); gfc_build_intrinsic_lib_fndecls ();