diff options
author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-04-16 15:32:26 +0000 |
---|---|---|
committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-04-16 15:32:26 +0000 |
commit | bc9af2dd1999bf9fed905fe5ba58c578ae157561 (patch) | |
tree | 06c4c358c5207acc9ab8ce629b72aa388bf6412e /gcc/tree-ssa-loop-im.c | |
parent | f6c9c56eee25b1877f8c1555906446e2617aca44 (diff) | |
download | gcc-bc9af2dd1999bf9fed905fe5ba58c578ae157561.tar.gz |
2013-04-16 Richard Biener <rguenther@suse.de>
PR tree-optimization/56756
* tree-ssa-loop-im.c (struct first_mem_ref_loc_1): New functor.
(first_mem_ref_loc): New.
(execute_sm): Place the load temporarily before a previous
access instead of in the latch edge to ensure its SSA dependencies
are defined at points dominating the load.
* gcc.dg/torture/pr56756.c: New testcase.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@198001 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-loop-im.c')
-rw-r--r-- | gcc/tree-ssa-loop-im.c | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index 085789165a2..188af0012a7 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -1718,6 +1718,32 @@ rewrite_mem_refs (struct loop *loop, mem_ref_p ref, tree tmp_var) for_all_locs_in_loop (loop, ref, rewrite_mem_ref_loc (tmp_var)); } +/* Stores the first reference location in LOCP. */ + +struct first_mem_ref_loc_1 +{ + first_mem_ref_loc_1 (mem_ref_loc_p *locp_) : locp (locp_) {} + bool operator()(mem_ref_loc_p loc); + mem_ref_loc_p *locp; +}; + +bool +first_mem_ref_loc_1::operator()(mem_ref_loc_p loc) +{ + *locp = loc; + return true; +} + +/* Returns the first reference location to REF in LOOP. */ + +static mem_ref_loc_p +first_mem_ref_loc (struct loop *loop, mem_ref_p ref) +{ + mem_ref_loc_p locp = NULL; + for_all_locs_in_loop (loop, ref, first_mem_ref_loc_1 (&locp)); + return locp; +} + /* The name and the length of the currently generated variable for lsm. */ #define MAX_LSM_NAME_LENGTH 40 @@ -2022,9 +2048,10 @@ execute_sm (struct loop *loop, vec<edge> exits, mem_ref_p ref) unsigned i; gimple load; struct fmt_data fmt_data; - edge ex, latch_edge; + edge ex; struct lim_aux_data *lim_data; bool multi_threaded_model_p = false; + gimple_stmt_iterator gsi; if (dump_file && (dump_flags & TDF_DETAILS)) { @@ -2049,9 +2076,10 @@ execute_sm (struct loop *loop, vec<edge> exits, mem_ref_p ref) rewrite_mem_refs (loop, ref, tmp_var); - /* Emit the load code into the latch, so that we are sure it will - be processed after all dependencies. */ - latch_edge = loop_latch_edge (loop); + /* Emit the load code on a random exit edge or into the latch if + the loop does not exit, so that we are sure it will be processed + by move_computations after all dependencies. */ + gsi = gsi_for_stmt (first_mem_ref_loc (loop, ref)->stmt); /* FIXME/TODO: For the multi-threaded variant, we could avoid this load altogether, since the store is predicated by a flag. We @@ -2060,7 +2088,7 @@ execute_sm (struct loop *loop, vec<edge> exits, mem_ref_p ref) lim_data = init_lim_data (load); lim_data->max_loop = loop; lim_data->tgt_loop = loop; - gsi_insert_on_edge (latch_edge, load); + gsi_insert_before (&gsi, load, GSI_SAME_STMT); if (multi_threaded_model_p) { @@ -2068,7 +2096,7 @@ execute_sm (struct loop *loop, vec<edge> exits, mem_ref_p ref) lim_data = init_lim_data (load); lim_data->max_loop = loop; lim_data->tgt_loop = loop; - gsi_insert_on_edge (latch_edge, load); + gsi_insert_before (&gsi, load, GSI_SAME_STMT); } /* Sink the store to every exit from the loop. */ |