tree-optimization/115701 - factor out maybe_duplicate_ssa_info_at_copy

The following factors out the code that preserves SSA info of the LHS
of a SSA copy LHS = RHS when LHS is about to be eliminated to RHS.

	PR tree-optimization/115701
	* tree-ssanames.h (maybe_duplicate_ssa_info_at_copy): Declare.
	* tree-ssanames.cc (maybe_duplicate_ssa_info_at_copy): New
	function, split out from ...
	* tree-ssa-copy.cc (fini_copy_prop): ... here.
	* tree-ssa-sccvn.cc (eliminate_dom_walker::eliminate_stmt): ...
	and here.

(cherry picked from commit b5c64b413fd5bc03a1a8ef86d005892071e42cbe)
This commit is contained in:
Richard Biener 2024-06-30 11:28:11 +02:00 committed by Richard Biener
parent ca275b68ef
commit 6f74a5f5dc
4 changed files with 34 additions and 50 deletions

View file

@ -527,38 +527,10 @@ fini_copy_prop (void)
|| copy_of[i].value == var)
continue;
/* In theory the points-to solution of all members of the
copy chain is their intersection. For now we do not bother
to compute this but only make sure we do not lose points-to
information completely by setting the points-to solution
of the representative to the first solution we find if
it doesn't have one already. */
/* Duplicate points-to and range info appropriately. */
if (copy_of[i].value != var
&& TREE_CODE (copy_of[i].value) == SSA_NAME)
{
basic_block copy_of_bb
= gimple_bb (SSA_NAME_DEF_STMT (copy_of[i].value));
basic_block var_bb = gimple_bb (SSA_NAME_DEF_STMT (var));
if (POINTER_TYPE_P (TREE_TYPE (var))
&& SSA_NAME_PTR_INFO (var)
&& !SSA_NAME_PTR_INFO (copy_of[i].value))
{
duplicate_ssa_name_ptr_info (copy_of[i].value,
SSA_NAME_PTR_INFO (var));
/* Points-to information is cfg insensitive,
but [E]VRP might record context sensitive alignment
info, non-nullness, etc. So reset context sensitive
info if the two SSA_NAMEs aren't defined in the same
basic block. */
if (var_bb != copy_of_bb)
reset_flow_sensitive_info (copy_of[i].value);
}
else if (!POINTER_TYPE_P (TREE_TYPE (var))
&& SSA_NAME_RANGE_INFO (var)
&& !SSA_NAME_RANGE_INFO (copy_of[i].value)
&& var_bb == copy_of_bb)
duplicate_ssa_name_range_info (copy_of[i].value, var);
}
maybe_duplicate_ssa_info_at_copy (var, copy_of[i].value);
}
class copy_folder copy_folder;

View file

@ -6871,27 +6871,10 @@ eliminate_dom_walker::eliminate_stmt (basic_block b, gimple_stmt_iterator *gsi)
/* If this now constitutes a copy duplicate points-to
and range info appropriately. This is especially
important for inserted code. See tree-ssa-copy.cc
for similar code. */
important for inserted code. */
if (sprime
&& TREE_CODE (sprime) == SSA_NAME)
{
basic_block sprime_b = gimple_bb (SSA_NAME_DEF_STMT (sprime));
if (POINTER_TYPE_P (TREE_TYPE (lhs))
&& SSA_NAME_PTR_INFO (lhs)
&& ! SSA_NAME_PTR_INFO (sprime))
{
duplicate_ssa_name_ptr_info (sprime,
SSA_NAME_PTR_INFO (lhs));
if (b != sprime_b)
reset_flow_sensitive_info (sprime);
}
else if (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
&& SSA_NAME_RANGE_INFO (lhs)
&& ! SSA_NAME_RANGE_INFO (sprime)
&& b == sprime_b)
duplicate_ssa_name_range_info (sprime, lhs);
}
maybe_duplicate_ssa_info_at_copy (lhs, sprime);
/* Inhibit the use of an inserted PHI on a loop header when
the address of the memory reference is a simple induction

View file

@ -757,6 +757,34 @@ duplicate_ssa_name_range_info (tree name, tree src)
}
}
/* For a SSA copy DEST = SRC duplicate SSA info present on DEST to SRC
to preserve it in case DEST is eliminated to SRC. */
void
maybe_duplicate_ssa_info_at_copy (tree dest, tree src)
{
if (POINTER_TYPE_P (TREE_TYPE (dest))
&& SSA_NAME_PTR_INFO (dest)
&& ! SSA_NAME_PTR_INFO (src))
{
duplicate_ssa_name_ptr_info (src, SSA_NAME_PTR_INFO (dest));
/* Points-to information is cfg insensitive,
but VRP might record context sensitive alignment
info, non-nullness, etc. So reset context sensitive
info if the two SSA_NAMEs aren't defined in the same
basic block. */
if (gimple_bb (SSA_NAME_DEF_STMT (src))
!= gimple_bb (SSA_NAME_DEF_STMT (dest)))
reset_flow_sensitive_info (src);
}
else if (INTEGRAL_TYPE_P (TREE_TYPE (dest))
&& SSA_NAME_RANGE_INFO (dest)
&& ! SSA_NAME_RANGE_INFO (src)
&& (gimple_bb (SSA_NAME_DEF_STMT (src))
== gimple_bb (SSA_NAME_DEF_STMT (dest))))
duplicate_ssa_name_range_info (src, dest);
}
/* Creates a duplicate of a ssa name NAME tobe defined by statement STMT
in function FN. */

View file

@ -79,9 +79,10 @@ extern struct ptr_info_def *get_ptr_info (tree);
extern void set_ptr_nonnull (tree);
extern tree copy_ssa_name_fn (struct function *, tree, gimple *);
extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *);
extern tree duplicate_ssa_name_fn (struct function *, tree, gimple *);
extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *);
extern void duplicate_ssa_name_range_info (tree dest, tree src);
extern void maybe_duplicate_ssa_info_at_copy (tree dest, tree src);
extern void reset_flow_sensitive_info (tree);
extern void reset_flow_sensitive_info_in_bb (basic_block);
extern void release_defs (gimple *);