Commit 1c8f7377 by Richard Guenther Committed by Richard Biener

re PR middle-end/54146 (Very slow compile with attribute((flatten)))

2012-08-14  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/54146
	* tree-ssa-pre.c (do_regular_insertion): Use a VEC
	indexed by pred edge index for avail.
	(do_partial_partial_insertion): Likewise.
	(insert_into_preds_of_block): Adjust.

From-SVN: r190382
parent 2ad728d2
2012-08-14 Richard Guenther <rguenther@suse.de> 2012-08-14 Richard Guenther <rguenther@suse.de>
PR tree-optimization/54146
* tree-ssa-pre.c (do_regular_insertion): Use a VEC
indexed by pred edge index for avail.
(do_partial_partial_insertion): Likewise.
(insert_into_preds_of_block): Adjust.
2012-08-14 Richard Guenther <rguenther@suse.de>
* gimplify.c (create_tmp_from_val): Mark temporary with * gimplify.c (create_tmp_from_val): Mark temporary with
DECL_GIMPLE_REG_P here ... DECL_GIMPLE_REG_P here ...
(internal_get_tmp_var): ... instead of here. If we go into (internal_get_tmp_var): ... instead of here. If we go into
......
...@@ -3188,7 +3188,7 @@ inhibit_phi_insertion (basic_block bb, pre_expr expr) ...@@ -3188,7 +3188,7 @@ inhibit_phi_insertion (basic_block bb, pre_expr expr)
static bool static bool
insert_into_preds_of_block (basic_block block, unsigned int exprnum, insert_into_preds_of_block (basic_block block, unsigned int exprnum,
pre_expr *avail) VEC(pre_expr, heap) *avail)
{ {
pre_expr expr = expression_for_id (exprnum); pre_expr expr = expression_for_id (exprnum);
pre_expr newphi; pre_expr newphi;
...@@ -3229,7 +3229,7 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum, ...@@ -3229,7 +3229,7 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum,
gimple_seq stmts = NULL; gimple_seq stmts = NULL;
tree builtexpr; tree builtexpr;
bprime = pred->src; bprime = pred->src;
eprime = avail[bprime->index]; eprime = VEC_index (pre_expr, avail, pred->dest_idx);
if (eprime->kind != NAME && eprime->kind != CONSTANT) if (eprime->kind != NAME && eprime->kind != CONSTANT)
{ {
...@@ -3239,14 +3239,14 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum, ...@@ -3239,14 +3239,14 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum,
type); type);
gcc_assert (!(pred->flags & EDGE_ABNORMAL)); gcc_assert (!(pred->flags & EDGE_ABNORMAL));
gsi_insert_seq_on_edge (pred, stmts); gsi_insert_seq_on_edge (pred, stmts);
avail[bprime->index] = get_or_alloc_expr_for_name (builtexpr); VEC_replace (pre_expr, avail, pred->dest_idx,
get_or_alloc_expr_for_name (builtexpr));
insertions = true; insertions = true;
} }
else if (eprime->kind == CONSTANT) else if (eprime->kind == CONSTANT)
{ {
/* Constants may not have the right type, fold_convert /* Constants may not have the right type, fold_convert
should give us back a constant with the right type. should give us back a constant with the right type. */
*/
tree constant = PRE_EXPR_CONSTANT (eprime); tree constant = PRE_EXPR_CONSTANT (eprime);
if (!useless_type_conversion_p (type, TREE_TYPE (constant))) if (!useless_type_conversion_p (type, TREE_TYPE (constant)))
{ {
...@@ -3278,11 +3278,13 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum, ...@@ -3278,11 +3278,13 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum,
} }
gsi_insert_seq_on_edge (pred, stmts); gsi_insert_seq_on_edge (pred, stmts);
} }
avail[bprime->index] = get_or_alloc_expr_for_name (forcedexpr); VEC_replace (pre_expr, avail, pred->dest_idx,
get_or_alloc_expr_for_name (forcedexpr));
} }
} }
else else
avail[bprime->index] = get_or_alloc_expr_for_constant (builtexpr); VEC_replace (pre_expr, avail, pred->dest_idx,
get_or_alloc_expr_for_constant (builtexpr));
} }
} }
else if (eprime->kind == NAME) else if (eprime->kind == NAME)
...@@ -3321,7 +3323,8 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum, ...@@ -3321,7 +3323,8 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum,
} }
gsi_insert_seq_on_edge (pred, stmts); gsi_insert_seq_on_edge (pred, stmts);
} }
avail[bprime->index] = get_or_alloc_expr_for_name (forcedexpr); VEC_replace (pre_expr, avail, pred->dest_idx,
get_or_alloc_expr_for_name (forcedexpr));
} }
} }
} }
...@@ -3344,14 +3347,13 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum, ...@@ -3344,14 +3347,13 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum,
bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (gimple_phi_result (phi))); bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (gimple_phi_result (phi)));
FOR_EACH_EDGE (pred, ei, block->preds) FOR_EACH_EDGE (pred, ei, block->preds)
{ {
pre_expr ae = avail[pred->src->index]; pre_expr ae = VEC_index (pre_expr, avail, pred->dest_idx);
gcc_assert (get_expr_type (ae) == type gcc_assert (get_expr_type (ae) == type
|| useless_type_conversion_p (type, get_expr_type (ae))); || useless_type_conversion_p (type, get_expr_type (ae)));
if (ae->kind == CONSTANT) if (ae->kind == CONSTANT)
add_phi_arg (phi, PRE_EXPR_CONSTANT (ae), pred, UNKNOWN_LOCATION); add_phi_arg (phi, PRE_EXPR_CONSTANT (ae), pred, UNKNOWN_LOCATION);
else else
add_phi_arg (phi, PRE_EXPR_NAME (avail[pred->src->index]), pred, add_phi_arg (phi, PRE_EXPR_NAME (ae), pred, UNKNOWN_LOCATION);
UNKNOWN_LOCATION);
} }
newphi = get_or_alloc_expr_for_name (gimple_phi_result (phi)); newphi = get_or_alloc_expr_for_name (gimple_phi_result (phi));
...@@ -3411,15 +3413,18 @@ static bool ...@@ -3411,15 +3413,18 @@ static bool
do_regular_insertion (basic_block block, basic_block dom) do_regular_insertion (basic_block block, basic_block dom)
{ {
bool new_stuff = false; bool new_stuff = false;
VEC (pre_expr, heap) *exprs = sorted_array_from_bitmap_set (ANTIC_IN (block)); VEC (pre_expr, heap) *exprs;
pre_expr expr; pre_expr expr;
VEC (pre_expr, heap) *avail = NULL;
int i; int i;
exprs = sorted_array_from_bitmap_set (ANTIC_IN (block));
VEC_safe_grow (pre_expr, heap, avail, EDGE_COUNT (block->preds));
FOR_EACH_VEC_ELT (pre_expr, exprs, i, expr) FOR_EACH_VEC_ELT (pre_expr, exprs, i, expr)
{ {
if (expr->kind != NAME) if (expr->kind != NAME)
{ {
pre_expr *avail;
unsigned int val; unsigned int val;
bool by_some = false; bool by_some = false;
bool cant_insert = false; bool cant_insert = false;
...@@ -3442,10 +3447,6 @@ do_regular_insertion (basic_block block, basic_block dom) ...@@ -3442,10 +3447,6 @@ do_regular_insertion (basic_block block, basic_block dom)
continue; continue;
} }
/* FIXME: This costs N_EXPR*N_BASIC_BLOCKS. Should use
a less costly data structure for avail (e.g. a VEC
indexed by edge index). */
avail = XCNEWVEC (pre_expr, last_basic_block);
FOR_EACH_EDGE (pred, ei, block->preds) FOR_EACH_EDGE (pred, ei, block->preds)
{ {
unsigned int vprime; unsigned int vprime;
...@@ -3468,6 +3469,7 @@ do_regular_insertion (basic_block block, basic_block dom) ...@@ -3468,6 +3469,7 @@ do_regular_insertion (basic_block block, basic_block dom)
rest of the results are. */ rest of the results are. */
if (eprime == NULL) if (eprime == NULL)
{ {
VEC_replace (pre_expr, avail, pred->dest_idx, NULL);
cant_insert = true; cant_insert = true;
break; break;
} }
...@@ -3478,12 +3480,12 @@ do_regular_insertion (basic_block block, basic_block dom) ...@@ -3478,12 +3480,12 @@ do_regular_insertion (basic_block block, basic_block dom)
vprime, NULL); vprime, NULL);
if (edoubleprime == NULL) if (edoubleprime == NULL)
{ {
avail[bprime->index] = eprime; VEC_replace (pre_expr, avail, pred->dest_idx, eprime);
all_same = false; all_same = false;
} }
else else
{ {
avail[bprime->index] = edoubleprime; VEC_replace (pre_expr, avail, pred->dest_idx, edoubleprime);
by_some = true; by_some = true;
/* We want to perform insertions to remove a redundancy on /* We want to perform insertions to remove a redundancy on
a path in the CFG we want to optimize for speed. */ a path in the CFG we want to optimize for speed. */
...@@ -3562,11 +3564,11 @@ do_regular_insertion (basic_block block, basic_block dom) ...@@ -3562,11 +3564,11 @@ do_regular_insertion (basic_block block, basic_block dom)
} }
} }
} }
free (avail);
} }
} }
VEC_free (pre_expr, heap, exprs); VEC_free (pre_expr, heap, exprs);
VEC_free (pre_expr, heap, avail);
return new_stuff; return new_stuff;
} }
...@@ -3582,15 +3584,18 @@ static bool ...@@ -3582,15 +3584,18 @@ static bool
do_partial_partial_insertion (basic_block block, basic_block dom) do_partial_partial_insertion (basic_block block, basic_block dom)
{ {
bool new_stuff = false; bool new_stuff = false;
VEC (pre_expr, heap) *exprs = sorted_array_from_bitmap_set (PA_IN (block)); VEC (pre_expr, heap) *exprs;
pre_expr expr; pre_expr expr;
VEC (pre_expr, heap) *avail = NULL;
int i; int i;
exprs = sorted_array_from_bitmap_set (PA_IN (block));
VEC_safe_grow (pre_expr, heap, avail, EDGE_COUNT (block->preds));
FOR_EACH_VEC_ELT (pre_expr, exprs, i, expr) FOR_EACH_VEC_ELT (pre_expr, exprs, i, expr)
{ {
if (expr->kind != NAME) if (expr->kind != NAME)
{ {
pre_expr *avail;
unsigned int val; unsigned int val;
bool by_all = true; bool by_all = true;
bool cant_insert = false; bool cant_insert = false;
...@@ -3605,10 +3610,6 @@ do_partial_partial_insertion (basic_block block, basic_block dom) ...@@ -3605,10 +3610,6 @@ do_partial_partial_insertion (basic_block block, basic_block dom)
if (bitmap_set_contains_value (AVAIL_OUT (dom), val)) if (bitmap_set_contains_value (AVAIL_OUT (dom), val))
continue; continue;
/* FIXME: This costs N_EXPR*N_BASIC_BLOCKS. Should use
a less costly data structure for avail (e.g. a VEC
indexed by edge index). */
avail = XCNEWVEC (pre_expr, last_basic_block);
FOR_EACH_EDGE (pred, ei, block->preds) FOR_EACH_EDGE (pred, ei, block->preds)
{ {
unsigned int vprime; unsigned int vprime;
...@@ -3633,6 +3634,7 @@ do_partial_partial_insertion (basic_block block, basic_block dom) ...@@ -3633,6 +3634,7 @@ do_partial_partial_insertion (basic_block block, basic_block dom)
rest of the results are. */ rest of the results are. */
if (eprime == NULL) if (eprime == NULL)
{ {
VEC_replace (pre_expr, avail, pred->dest_idx, NULL);
cant_insert = true; cant_insert = true;
break; break;
} }
...@@ -3641,13 +3643,12 @@ do_partial_partial_insertion (basic_block block, basic_block dom) ...@@ -3641,13 +3643,12 @@ do_partial_partial_insertion (basic_block block, basic_block dom)
vprime = get_expr_value_id (eprime); vprime = get_expr_value_id (eprime);
edoubleprime = bitmap_find_leader (AVAIL_OUT (bprime), edoubleprime = bitmap_find_leader (AVAIL_OUT (bprime),
vprime, NULL); vprime, NULL);
VEC_replace (pre_expr, avail, pred->dest_idx, edoubleprime);
if (edoubleprime == NULL) if (edoubleprime == NULL)
{ {
by_all = false; by_all = false;
break; break;
} }
else
avail[bprime->index] = edoubleprime;
} }
/* If we can insert it, it's not the same value /* If we can insert it, it's not the same value
...@@ -3701,11 +3702,11 @@ do_partial_partial_insertion (basic_block block, basic_block dom) ...@@ -3701,11 +3702,11 @@ do_partial_partial_insertion (basic_block block, basic_block dom)
new_stuff = true; new_stuff = true;
} }
} }
free (avail);
} }
} }
VEC_free (pre_expr, heap, exprs); VEC_free (pre_expr, heap, exprs);
VEC_free (pre_expr, heap, avail);
return new_stuff; return new_stuff;
} }
......
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