From beccc91a67898bd69b8bbf22c2837227991f593c Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 29 Aug 2018 14:12:25 +0000 Subject: 2018-08-29 Richard Biener * tree-core.h: Document use of deprecated_flag in SSA_NAME. * tree.h (SSA_NAME_POINTS_TO_READONLY_MEMORY): Define. * tree-into-ssa.c (pass_build_ssa::execute): Initialize function parameters SSA_NAME_POINTS_TO_READONLY_MEMORY from fnspec. * tree-ssa-sccvn.c (const_parms, init_const_parms): Remove. (vn_reference_lookup_3): Remove use of const_parms. (free_rpo_vn): Do not free const_parms. (do_rpo_vn): Do not call init_const_parms. * tree-ssa-alias.c (refs_may_alias_p_1): Honor SSA_NAME_POINTS_TO_READONLY_MEMORY. (call_may_clobber_ref_p_1): Likewise. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@263958 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 14 ++++++++++++++ gcc/tree-core.h | 3 +++ gcc/tree-into-ssa.c | 22 ++++++++++++++++++++++ gcc/tree-ssa-alias.c | 18 ++++++++++++++++++ gcc/tree-ssa-sccvn.c | 47 ----------------------------------------------- gcc/tree.h | 7 +++++++ 6 files changed, 64 insertions(+), 47 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a8a9b2df206..02a7b94d1f2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2018-08-29 Richard Biener + + * tree-core.h: Document use of deprecated_flag in SSA_NAME. + * tree.h (SSA_NAME_POINTS_TO_READONLY_MEMORY): Define. + * tree-into-ssa.c (pass_build_ssa::execute): Initialize + function parameters SSA_NAME_POINTS_TO_READONLY_MEMORY from fnspec. + * tree-ssa-sccvn.c (const_parms, init_const_parms): Remove. + (vn_reference_lookup_3): Remove use of const_parms. + (free_rpo_vn): Do not free const_parms. + (do_rpo_vn): Do not call init_const_parms. + * tree-ssa-alias.c (refs_may_alias_p_1): Honor + SSA_NAME_POINTS_TO_READONLY_MEMORY. + (call_may_clobber_ref_p_1): Likewise. + 2018-08-29 Alexander Monakov PR other/86726 diff --git a/gcc/tree-core.h b/gcc/tree-core.h index f98cfefef94..dee27f89dec 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -1238,6 +1238,9 @@ struct GTY(()) tree_base { IDENTIFIER_TRANSPARENT_ALIAS in IDENTIFIER_NODE + SSA_NAME_POINTS_TO_READONLY_MEMORY in + SSA_NAME + visited: TREE_VISITED in diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c index f4af33c1303..cdae75d1aae 100644 --- a/gcc/tree-into-ssa.c +++ b/gcc/tree-into-ssa.c @@ -2490,6 +2490,28 @@ pass_build_ssa::execute (function *fun) SET_SSA_NAME_VAR_OR_IDENTIFIER (name, DECL_NAME (decl)); } + /* Initialize SSA_NAME_POINTS_TO_READONLY_MEMORY. */ + tree fnspec = lookup_attribute ("fn spec", + TYPE_ATTRIBUTES (TREE_TYPE (fun->decl))); + if (fnspec) + { + fnspec = TREE_VALUE (TREE_VALUE (fnspec)); + unsigned i = 1; + for (tree arg = DECL_ARGUMENTS (cfun->decl); + arg; arg = DECL_CHAIN (arg), ++i) + { + if (i >= (unsigned) TREE_STRING_LENGTH (fnspec)) + break; + if (TREE_STRING_POINTER (fnspec)[i] == 'R' + || TREE_STRING_POINTER (fnspec)[i] == 'r') + { + tree name = ssa_default_def (fun, arg); + if (name) + SSA_NAME_POINTS_TO_READONLY_MEMORY (name) = 1; + } + } + } + return 0; } diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index e6e21e8773c..6efe4c3a4a7 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -1483,6 +1483,16 @@ refs_may_alias_p_1 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p) ao_ref_alias_set (ref2))) return false; + /* If the reference is based on a pointer that points to memory + that may not be written to then the other reference cannot possibly + clobber it. */ + if ((TREE_CODE (TREE_OPERAND (base2, 0)) == SSA_NAME + && SSA_NAME_POINTS_TO_READONLY_MEMORY (TREE_OPERAND (base2, 0))) + || (ind1_p + && TREE_CODE (TREE_OPERAND (base1, 0)) == SSA_NAME + && SSA_NAME_POINTS_TO_READONLY_MEMORY (TREE_OPERAND (base1, 0)))) + return false; + /* Dispatch to the pointer-vs-decl or pointer-vs-pointer disambiguators. */ if (var1_p && ind2_p) return indirect_ref_may_alias_decl_p (ref2->ref, base2, @@ -1991,6 +2001,14 @@ call_may_clobber_ref_p_1 (gcall *call, ao_ref *ref) || !is_global_var (base))) return false; + /* If the reference is based on a pointer that points to memory + that may not be written to then the call cannot possibly clobber it. */ + if ((TREE_CODE (base) == MEM_REF + || TREE_CODE (base) == TARGET_MEM_REF) + && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME + && SSA_NAME_POINTS_TO_READONLY_MEMORY (TREE_OPERAND (base, 0))) + return false; + callee = gimple_call_fndecl (call); /* Handle those builtin functions explicitly that do not act as diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 04b3808feff..e3b9f1c7dbc 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -133,7 +133,6 @@ along with GCC; see the file COPYING3. If not see static tree *last_vuse_ptr; static vn_lookup_kind vn_walk_kind; static vn_lookup_kind default_vn_walk_kind; -bitmap const_parms; /* vn_nary_op hashtable helpers. */ @@ -1863,18 +1862,6 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_, bool lhs_ref_ok = false; poly_int64 copy_size; - /* If the reference is based on a parameter that was determined as - pointing to readonly memory it doesn't change. */ - if (TREE_CODE (base) == MEM_REF - && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME - && SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (base, 0)) - && bitmap_bit_p (const_parms, - SSA_NAME_VERSION (TREE_OPERAND (base, 0)))) - { - *disambiguate_only = true; - return NULL; - } - /* First try to disambiguate after value-replacing in the definitions LHS. */ if (is_gimple_assign (def_stmt)) { @@ -4514,37 +4501,6 @@ set_hashtable_value_ids (void) set_value_id_for_result (vr->result, &vr->value_id); } - -/* Allocate and initialize CONST_PARAMS, a bitmap of parameter default defs - we know point to readonly memory. */ - -static void -init_const_parms () -{ - /* Collect pointers we know point to readonly memory. */ - const_parms = BITMAP_ALLOC (NULL); - tree fnspec = lookup_attribute ("fn spec", - TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl))); - if (fnspec) - { - fnspec = TREE_VALUE (TREE_VALUE (fnspec)); - unsigned i = 1; - for (tree arg = DECL_ARGUMENTS (cfun->decl); - arg; arg = DECL_CHAIN (arg), ++i) - { - if (i >= (unsigned) TREE_STRING_LENGTH (fnspec)) - break; - if (TREE_STRING_POINTER (fnspec)[i] == 'R' - || TREE_STRING_POINTER (fnspec)[i] == 'r') - { - tree name = ssa_default_def (cfun, arg); - if (name) - bitmap_set_bit (const_parms, SSA_NAME_VERSION (name)); - } - } - } -} - /* Return the maximum value id we have ever seen. */ unsigned int @@ -5606,8 +5562,6 @@ free_rpo_vn (void) obstack_free (&vn_tables_obstack, NULL); obstack_free (&vn_tables_insert_obstack, NULL); - BITMAP_FREE (const_parms); - vn_ssa_aux_iterator_type it; vn_ssa_aux_t info; FOR_EACH_HASH_TABLE_ELEMENT (*vn_ssa_aux_hash, info, vn_ssa_aux_t, it) @@ -6326,7 +6280,6 @@ do_rpo_vn (function *fn, edge entry, bitmap exit_bbs, unsigned region_size = (((unsigned HOST_WIDE_INT)n * num_ssa_names) / (n_basic_blocks_for_fn (fn) - NUM_FIXED_BLOCKS)); VN_TOP = create_tmp_var_raw (void_type_node, "vn_top"); - init_const_parms (); vn_ssa_aux_hash = new hash_table (region_size * 2); gcc_obstack_init (&vn_ssa_aux_obstack); diff --git a/gcc/tree.h b/gcc/tree.h index 562a88b8aff..4f415b7a220 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -1743,6 +1743,13 @@ extern tree maybe_wrap_with_location (tree, location_t); #define SSA_NAME_IS_DEFAULT_DEF(NODE) \ SSA_NAME_CHECK (NODE)->base.default_def_flag +/* Nonzero if this SSA_NAME is known to point to memory that may not + be written to. This is set for default defs of function parameters + that have a corresponding r or R specification in the functions + fn spec attribute. This is used by alias analysis. */ +#define SSA_NAME_POINTS_TO_READONLY_MEMORY(NODE) \ + SSA_NAME_CHECK (NODE)->base.deprecated_flag + /* Attributes for SSA_NAMEs for pointer-type variables. */ #define SSA_NAME_PTR_INFO(N) \ SSA_NAME_CHECK (N)->ssa_name.info.ptr_info -- cgit v1.2.3