Commit c0503346 by Patrick Palka

Avoid recomputing the defining predicate chains for the same PHI

gcc/ChangeLog:

	* tree-ssa-uninit.c (find_uninit_use): Declare and pass to
	is_use_properly_guarded the variable def_preds.  Free its
	contents before returning.
	(prune_uninit_phi_opnds_in_unrealizable_paths): Same.
	(is_use_properly_guarded): Replace local variable def_preds with
	a parameter.  Adjust accordingly.  Only update *def_preds if it's
	the empty vector.

From-SVN: r226511
parent 420a9d9b
2015-08-03 Patrick Palka <ppalka@gcc.gnu.org>
* tree-ssa-uninit.c (find_uninit_use): Declare and pass to
is_use_properly_guarded the variable def_preds. Free its
contents before returning.
(prune_uninit_phi_opnds_in_unrealizable_paths): Same.
(is_use_properly_guarded): Replace local variable def_preds with
a parameter. Adjust accordingly. Only update *def_preds if it's
the empty vector.
2015-08-03 Richard Biener <rguenther@suse.de> 2015-08-03 Richard Biener <rguenther@suse.de>
* genmatch.c (simplify::for_subst_vec): New member. * genmatch.c (simplify::for_subst_vec): New member.
......
...@@ -980,6 +980,7 @@ is_use_properly_guarded (gimple use_stmt, ...@@ -980,6 +980,7 @@ is_use_properly_guarded (gimple use_stmt,
basic_block use_bb, basic_block use_bb,
gphi *phi, gphi *phi,
unsigned uninit_opnds, unsigned uninit_opnds,
pred_chain_union *def_preds,
hash_set<gphi *> *visited_phis); hash_set<gphi *> *visited_phis);
/* Returns true if all uninitialized opnds are pruned. Returns false /* Returns true if all uninitialized opnds are pruned. Returns false
...@@ -1098,14 +1099,19 @@ prune_uninit_phi_opnds_in_unrealizable_paths (gphi *phi, ...@@ -1098,14 +1099,19 @@ prune_uninit_phi_opnds_in_unrealizable_paths (gphi *phi,
edge opnd_edge; edge opnd_edge;
unsigned uninit_opnds2 unsigned uninit_opnds2
= compute_uninit_opnds_pos (opnd_def_phi); = compute_uninit_opnds_pos (opnd_def_phi);
pred_chain_union def_preds = vNULL;
bool ok;
gcc_assert (!MASK_EMPTY (uninit_opnds2)); gcc_assert (!MASK_EMPTY (uninit_opnds2));
opnd_edge = gimple_phi_arg_edge (phi, i); opnd_edge = gimple_phi_arg_edge (phi, i);
if (!is_use_properly_guarded (phi, ok = is_use_properly_guarded (phi,
opnd_edge->src, opnd_edge->src,
opnd_def_phi, opnd_def_phi,
uninit_opnds2, uninit_opnds2,
visited_phis)) &def_preds,
return false; visited_phis);
destroy_predicate_vecs (def_preds);
if (!ok)
return false;
} }
else else
return false; return false;
...@@ -2158,23 +2164,31 @@ normalize_preds (pred_chain_union preds, gimple use_or_def, bool is_use) ...@@ -2158,23 +2164,31 @@ normalize_preds (pred_chain_union preds, gimple use_or_def, bool is_use)
true if it can be determined that the use of PHI's def in true if it can be determined that the use of PHI's def in
USE_STMT is guarded with a predicate set not overlapping with USE_STMT is guarded with a predicate set not overlapping with
predicate sets of all runtime paths that do not have a definition. predicate sets of all runtime paths that do not have a definition.
Returns false if it is not or it can not be determined. USE_BB is Returns false if it is not or it can not be determined. USE_BB is
the bb of the use (for phi operand use, the bb is not the bb of the bb of the use (for phi operand use, the bb is not the bb of
the phi stmt, but the src bb of the operand edge). UNINIT_OPNDS the phi stmt, but the src bb of the operand edge).
is a bit vector. If an operand of PHI is uninitialized, the
corresponding bit in the vector is 1. VISIED_PHIS is a pointer UNINIT_OPNDS is a bit vector. If an operand of PHI is uninitialized, the
set of phis being visted. */ corresponding bit in the vector is 1. VISITED_PHIS is a pointer
set of phis being visited.
*DEF_PREDS contains the (memoized) defining predicate chains of PHI.
If *DEF_PREDS is the empty vector, the defining predicate chains of
PHI will be computed and stored into *DEF_PREDS as needed.
VISITED_PHIS is a pointer set of phis being visited. */
static bool static bool
is_use_properly_guarded (gimple use_stmt, is_use_properly_guarded (gimple use_stmt,
basic_block use_bb, basic_block use_bb,
gphi *phi, gphi *phi,
unsigned uninit_opnds, unsigned uninit_opnds,
pred_chain_union *def_preds,
hash_set<gphi *> *visited_phis) hash_set<gphi *> *visited_phis)
{ {
basic_block phi_bb; basic_block phi_bb;
pred_chain_union preds = vNULL; pred_chain_union preds = vNULL;
pred_chain_union def_preds = vNULL;
bool has_valid_preds = false; bool has_valid_preds = false;
bool is_properly_guarded = false; bool is_properly_guarded = false;
...@@ -2205,25 +2219,26 @@ is_use_properly_guarded (gimple use_stmt, ...@@ -2205,25 +2219,26 @@ is_use_properly_guarded (gimple use_stmt,
return true; return true;
} }
has_valid_preds = find_def_preds (&def_preds, phi); if (def_preds->is_empty ())
if (!has_valid_preds)
{ {
destroy_predicate_vecs (preds); has_valid_preds = find_def_preds (def_preds, phi);
destroy_predicate_vecs (def_preds);
return false; if (!has_valid_preds)
{
destroy_predicate_vecs (preds);
return false;
}
simplify_preds (def_preds, phi, false);
*def_preds = normalize_preds (*def_preds, phi, false);
} }
simplify_preds (&preds, use_stmt, true); simplify_preds (&preds, use_stmt, true);
preds = normalize_preds (preds, use_stmt, true); preds = normalize_preds (preds, use_stmt, true);
simplify_preds (&def_preds, phi, false); is_properly_guarded = is_superset_of (*def_preds, preds);
def_preds = normalize_preds (def_preds, phi, false);
is_properly_guarded = is_superset_of (def_preds, preds);
destroy_predicate_vecs (preds); destroy_predicate_vecs (preds);
destroy_predicate_vecs (def_preds);
return is_properly_guarded; return is_properly_guarded;
} }
...@@ -2245,6 +2260,8 @@ find_uninit_use (gphi *phi, unsigned uninit_opnds, ...@@ -2245,6 +2260,8 @@ find_uninit_use (gphi *phi, unsigned uninit_opnds,
use_operand_p use_p; use_operand_p use_p;
gimple use_stmt; gimple use_stmt;
imm_use_iterator iter; imm_use_iterator iter;
pred_chain_union def_preds = vNULL;
gimple ret = NULL;
phi_result = gimple_phi_result (phi); phi_result = gimple_phi_result (phi);
...@@ -2264,7 +2281,7 @@ find_uninit_use (gphi *phi, unsigned uninit_opnds, ...@@ -2264,7 +2281,7 @@ find_uninit_use (gphi *phi, unsigned uninit_opnds,
hash_set<gphi *> visited_phis; hash_set<gphi *> visited_phis;
if (is_use_properly_guarded (use_stmt, use_bb, phi, uninit_opnds, if (is_use_properly_guarded (use_stmt, use_bb, phi, uninit_opnds,
&visited_phis)) &def_preds, &visited_phis))
continue; continue;
if (dump_file && (dump_flags & TDF_DETAILS)) if (dump_file && (dump_flags & TDF_DETAILS))
...@@ -2274,7 +2291,10 @@ find_uninit_use (gphi *phi, unsigned uninit_opnds, ...@@ -2274,7 +2291,10 @@ find_uninit_use (gphi *phi, unsigned uninit_opnds,
} }
/* Found one real use, return. */ /* Found one real use, return. */
if (gimple_code (use_stmt) != GIMPLE_PHI) if (gimple_code (use_stmt) != GIMPLE_PHI)
return use_stmt; {
ret = use_stmt;
break;
}
/* Found a phi use that is not guarded, /* Found a phi use that is not guarded,
add the phi to the worklist. */ add the phi to the worklist. */
...@@ -2291,7 +2311,8 @@ find_uninit_use (gphi *phi, unsigned uninit_opnds, ...@@ -2291,7 +2311,8 @@ find_uninit_use (gphi *phi, unsigned uninit_opnds,
} }
} }
return NULL; destroy_predicate_vecs (def_preds);
return ret;
} }
/* Look for inputs to PHI that are SSA_NAMEs that have empty definitions /* Look for inputs to PHI that are SSA_NAMEs that have empty definitions
......
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