Commit 6a8b77b2 by Richard Biener Committed by Richard Biener

tree-ssa-sccvn.c (has_VN_INFO): New function.

2015-10-02  Richard Biener  <rguenther@suse.de>

	* tree-ssa-sccvn.c (has_VN_INFO): New function.
	(free_scc_vn): Use it.
	(visit_use): Remove dead code and refactor to use gassign
	and use less indentation.

From-SVN: r228369
parent d751beac
2015-10-02 Richard Biener <rguenther@suse.de>
* tree-ssa-sccvn.c (has_VN_INFO): New function.
(free_scc_vn): Use it.
(visit_use): Remove dead code and refactor to use gassign
and use less indentation.
2015-10-01 Segher Boessenkool <segher@kernel.crashing.org> 2015-10-01 Segher Boessenkool <segher@kernel.crashing.org>
PR target/67788 PR target/67788
...@@ -365,6 +365,16 @@ static vec<tree> sccstack; ...@@ -365,6 +365,16 @@ static vec<tree> sccstack;
static vec<vn_ssa_aux_t> vn_ssa_aux_table; static vec<vn_ssa_aux_t> vn_ssa_aux_table;
static struct obstack vn_ssa_aux_obstack; static struct obstack vn_ssa_aux_obstack;
/* Return whether there is value numbering information for a given SSA name. */
bool
has_VN_INFO (tree name)
{
if (SSA_NAME_VERSION (name) < vn_ssa_aux_table.length ())
return vn_ssa_aux_table[SSA_NAME_VERSION (name)] != NULL;
return false;
}
/* Return the value numbering information for a given SSA name. */ /* Return the value numbering information for a given SSA name. */
vn_ssa_aux_t vn_ssa_aux_t
...@@ -3316,17 +3326,15 @@ visit_use (tree use) ...@@ -3316,17 +3326,15 @@ visit_use (tree use)
/* Handle uninitialized uses. */ /* Handle uninitialized uses. */
if (SSA_NAME_IS_DEFAULT_DEF (use)) if (SSA_NAME_IS_DEFAULT_DEF (use))
changed = set_ssa_val_to (use, use); changed = set_ssa_val_to (use, use);
else else if (gimple_code (stmt) == GIMPLE_PHI)
{
if (gimple_code (stmt) == GIMPLE_PHI)
changed = visit_phi (stmt); changed = visit_phi (stmt);
else if (gimple_has_volatile_ops (stmt)) else if (gimple_has_volatile_ops (stmt))
changed = defs_to_varying (stmt); changed = defs_to_varying (stmt);
else if (is_gimple_assign (stmt)) else if (gassign *ass = dyn_cast <gassign *> (stmt))
{ {
enum tree_code code = gimple_assign_rhs_code (stmt); enum tree_code code = gimple_assign_rhs_code (ass);
tree lhs = gimple_assign_lhs (stmt); tree lhs = gimple_assign_lhs (ass);
tree rhs1 = gimple_assign_rhs1 (stmt); tree rhs1 = gimple_assign_rhs1 (ass);
tree simplified; tree simplified;
/* Shortcut for copies. Simplifying copies is pointless, /* Shortcut for copies. Simplifying copies is pointless,
...@@ -3337,13 +3345,13 @@ visit_use (tree use) ...@@ -3337,13 +3345,13 @@ visit_use (tree use)
changed = visit_copy (lhs, rhs1); changed = visit_copy (lhs, rhs1);
goto done; goto done;
} }
simplified = try_to_simplify (as_a <gassign *> (stmt)); simplified = try_to_simplify (ass);
if (simplified) if (simplified)
{ {
if (dump_file && (dump_flags & TDF_DETAILS)) if (dump_file && (dump_flags & TDF_DETAILS))
{ {
fprintf (dump_file, "RHS "); fprintf (dump_file, "RHS ");
print_gimple_expr (dump_file, stmt, 0, 0); print_gimple_expr (dump_file, ass, 0, 0);
fprintf (dump_file, " simplified to "); fprintf (dump_file, " simplified to ");
print_generic_expr (dump_file, simplified, 0); print_generic_expr (dump_file, simplified, 0);
fprintf (dump_file, "\n"); fprintf (dump_file, "\n");
...@@ -3371,7 +3379,7 @@ visit_use (tree use) ...@@ -3371,7 +3379,7 @@ visit_use (tree use)
if ((TREE_CODE (lhs) == SSA_NAME if ((TREE_CODE (lhs) == SSA_NAME
/* We can substitute SSA_NAMEs that are live over /* We can substitute SSA_NAMEs that are live over
abnormal edges with their constant value. */ abnormal edges with their constant value. */
&& !(gimple_assign_copy_p (stmt) && !(gimple_assign_copy_p (ass)
&& is_gimple_min_invariant (rhs1)) && is_gimple_min_invariant (rhs1))
&& !(simplified && !(simplified
&& is_gimple_min_invariant (simplified)) && is_gimple_min_invariant (simplified))
...@@ -3380,13 +3388,13 @@ visit_use (tree use) ...@@ -3380,13 +3388,13 @@ visit_use (tree use)
abnormal edges are a problem. */ abnormal edges are a problem. */
|| (code == SSA_NAME || (code == SSA_NAME
&& SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1))) && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1)))
changed = defs_to_varying (stmt); changed = defs_to_varying (ass);
else if (REFERENCE_CLASS_P (lhs) else if (REFERENCE_CLASS_P (lhs)
|| DECL_P (lhs)) || DECL_P (lhs))
changed = visit_reference_op_store (lhs, rhs1, stmt); changed = visit_reference_op_store (lhs, rhs1, ass);
else if (TREE_CODE (lhs) == SSA_NAME) else if (TREE_CODE (lhs) == SSA_NAME)
{ {
if ((gimple_assign_copy_p (stmt) if ((gimple_assign_copy_p (ass)
&& is_gimple_min_invariant (rhs1)) && is_gimple_min_invariant (rhs1))
|| (simplified || (simplified
&& is_gimple_min_invariant (simplified))) && is_gimple_min_invariant (simplified)))
...@@ -3398,59 +3406,38 @@ visit_use (tree use) ...@@ -3398,59 +3406,38 @@ visit_use (tree use)
} }
else else
{ {
/* First try to lookup the simplified expression. */ /* Visit the original statement. */
if (simplified) switch (vn_get_stmt_kind (ass))
{
enum gimple_rhs_class rhs_class;
rhs_class = get_gimple_rhs_class (TREE_CODE (simplified));
if ((rhs_class == GIMPLE_UNARY_RHS
|| rhs_class == GIMPLE_BINARY_RHS
|| rhs_class == GIMPLE_TERNARY_RHS)
&& valid_gimple_rhs_p (simplified))
{
tree result = vn_nary_op_lookup (simplified, NULL);
if (result)
{
changed = set_ssa_val_to (lhs, result);
goto done;
}
}
}
/* Otherwise visit the original statement. */
switch (vn_get_stmt_kind (stmt))
{ {
case VN_NARY: case VN_NARY:
changed = visit_nary_op (lhs, stmt); changed = visit_nary_op (lhs, ass);
break; break;
case VN_REFERENCE: case VN_REFERENCE:
changed = visit_reference_op_load (lhs, rhs1, stmt); changed = visit_reference_op_load (lhs, rhs1, ass);
break; break;
default: default:
changed = defs_to_varying (stmt); changed = defs_to_varying (ass);
break; break;
} }
} }
} }
else else
changed = defs_to_varying (stmt); changed = defs_to_varying (ass);
} }
else if (gcall *call_stmt = dyn_cast <gcall *> (stmt)) else if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
{ {
tree lhs = gimple_call_lhs (stmt); tree lhs = gimple_call_lhs (call_stmt);
if (lhs && TREE_CODE (lhs) == SSA_NAME) if (lhs && TREE_CODE (lhs) == SSA_NAME)
{ {
/* Try constant folding based on our current lattice. */ /* Try constant folding based on our current lattice. */
tree simplified = gimple_fold_stmt_to_constant_1 (stmt, tree simplified = gimple_fold_stmt_to_constant_1 (call_stmt,
vn_valueize); vn_valueize);
if (simplified) if (simplified)
{ {
if (dump_file && (dump_flags & TDF_DETAILS)) if (dump_file && (dump_flags & TDF_DETAILS))
{ {
fprintf (dump_file, "call "); fprintf (dump_file, "call ");
print_gimple_expr (dump_file, stmt, 0, 0); print_gimple_expr (dump_file, call_stmt, 0, 0);
fprintf (dump_file, " simplified to "); fprintf (dump_file, " simplified to ");
print_generic_expr (dump_file, simplified, 0); print_generic_expr (dump_file, simplified, 0);
fprintf (dump_file, "\n"); fprintf (dump_file, "\n");
...@@ -3464,35 +3451,32 @@ visit_use (tree use) ...@@ -3464,35 +3451,32 @@ visit_use (tree use)
&& is_gimple_min_invariant (simplified)) && is_gimple_min_invariant (simplified))
{ {
changed = set_ssa_val_to (lhs, simplified); changed = set_ssa_val_to (lhs, simplified);
if (gimple_vdef (stmt)) if (gimple_vdef (call_stmt))
changed |= set_ssa_val_to (gimple_vdef (stmt), changed |= set_ssa_val_to (gimple_vdef (call_stmt),
SSA_VAL (gimple_vuse (stmt))); SSA_VAL (gimple_vuse (call_stmt)));
goto done; goto done;
} }
else if (simplified else if (simplified
&& TREE_CODE (simplified) == SSA_NAME) && TREE_CODE (simplified) == SSA_NAME)
{ {
changed = visit_copy (lhs, simplified); changed = visit_copy (lhs, simplified);
if (gimple_vdef (stmt)) if (gimple_vdef (call_stmt))
changed |= set_ssa_val_to (gimple_vdef (stmt), changed |= set_ssa_val_to (gimple_vdef (call_stmt),
SSA_VAL (gimple_vuse (stmt))); SSA_VAL (gimple_vuse (call_stmt)));
goto done; goto done;
} }
else else if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
{
if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
{ {
changed = defs_to_varying (stmt); changed = defs_to_varying (call_stmt);
goto done; goto done;
} }
} }
}
if (!gimple_call_internal_p (stmt) if (!gimple_call_internal_p (call_stmt)
&& (/* Calls to the same function with the same vuse && (/* Calls to the same function with the same vuse
and the same operands do not necessarily return the same and the same operands do not necessarily return the same
value, unless they're pure or const. */ value, unless they're pure or const. */
gimple_call_flags (stmt) & (ECF_PURE | ECF_CONST) gimple_call_flags (call_stmt) & (ECF_PURE | ECF_CONST)
/* If calls have a vdef, subsequent calls won't have /* If calls have a vdef, subsequent calls won't have
the same incoming vuse. So, if 2 calls with vdef have the the same incoming vuse. So, if 2 calls with vdef have the
same vuse, we know they're not subsequent. same vuse, we know they're not subsequent.
...@@ -3500,7 +3484,7 @@ visit_use (tree use) ...@@ -3500,7 +3484,7 @@ visit_use (tree use)
same vuse and the same operands which are not subsequent same vuse and the same operands which are not subsequent
the same, because there is no code in the program that can the same, because there is no code in the program that can
compare the 2 values... */ compare the 2 values... */
|| (gimple_vdef (stmt) || (gimple_vdef (call_stmt)
/* ... unless the call returns a pointer which does /* ... unless the call returns a pointer which does
not alias with anything else. In which case the not alias with anything else. In which case the
information that the values are distinct are encoded information that the values are distinct are encoded
...@@ -3511,11 +3495,10 @@ visit_use (tree use) ...@@ -3511,11 +3495,10 @@ visit_use (tree use)
&& default_vn_walk_kind == VN_WALK))) && default_vn_walk_kind == VN_WALK)))
changed = visit_reference_op_call (lhs, call_stmt); changed = visit_reference_op_call (lhs, call_stmt);
else else
changed = defs_to_varying (stmt); changed = defs_to_varying (call_stmt);
} }
else else
changed = defs_to_varying (stmt); changed = defs_to_varying (stmt);
}
done: done:
return changed; return changed;
} }
...@@ -4001,8 +3984,7 @@ free_scc_vn (void) ...@@ -4001,8 +3984,7 @@ free_scc_vn (void)
{ {
tree name = ssa_name (i); tree name = ssa_name (i);
if (name if (name
&& SSA_NAME_VERSION (name) < vn_ssa_aux_table.length () && has_VN_INFO (name)
&& vn_ssa_aux_table[SSA_NAME_VERSION (name)]
&& VN_INFO (name)->needs_insertion) && VN_INFO (name)->needs_insertion)
release_ssa_name (name); release_ssa_name (name);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment