This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] parloops exit phi fixes
- From: Tom de Vries <Tom_deVries at mentor dot com>
- To: Richard Biener <rguenther at suse dot de>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 22 Jun 2015 19:59:45 +0200
- Subject: [PATCH] parloops exit phi fixes
- Authentication-results: sourceware.org; auth=none
Hi,
the gomp-4_0-branch contains the kernels oacc pass group. I've run into
trouble before with this pass group due to the fact that it uses passes
in an unusual location or order (pass_lim before pass_stdarg,
https://gcc.gnu.org/ml/gcc/2015-01/msg00282.html ).
In an attempt to find this sort of issue pro-actively, I've modified the
pass list in the following way (similar to the oacc kernels pass group,
but always functional, not just for functions with kernel regions or
loops in kernels regions), and bootstrapped and reg-tested on x86_64 on
top of gomp-4_-0-branch:
...
NEXT_PASS (pass_build_ealias);
NEXT_PASS (pass_fre);
+ NEXT_PASS (pass_ch);
+ NEXT_PASS (pass_tree_loop_init);
+ NEXT_PASS (pass_lim);
+ NEXT_PASS (pass_tree_loop_done);
+ NEXT_PASS (pass_fre);
+ NEXT_PASS (pass_tree_loop_init);
+ NEXT_PASS (pass_scev_cprop);
+ NEXT_PASS (pass_parallelize_loops);
+ NEXT_PASS (pass_expand_omp_ssa);
+ NEXT_PASS (pass_tree_loop_done);
NEXT_PASS (pass_merge_phi);
NEXT_PASS (pass_dse);
...
Apart from running into PR66616, I found two issues with the parloops pass:
1. handling of loop header phi, when there's no corresponding loop exit
phi (unused reduction result)
2. handling of loop exit phi, when there's no corresponding loop header
phi (value not modified in loop)
The two attached patches fix these problems.
Bootstrapped and reg-tested on x864_64 on top of gomp-4_0-branch in
combination with the patch series that triggered the problem.
Bootstrapped and reg-tested on x864_64 on top of trunk.
OK for trunk?
Thanks,
- Tom
Handle unused reduction in create_loads_for_reductions
2015-06-22 Tom de Vries <tom@codesourcery.com>
* tree-parloops.c (create_loads_for_reductions): Handle case that
reduction is unused.
---
gcc/tree-parloops.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index 48c143d..28112b2 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -1162,6 +1162,10 @@ create_loads_for_reductions (reduction_info **slot, struct clsn_data *clsn_data)
tree name;
tree x;
+ /* If there's no exit phi, the result of the reduction is unused. */
+ if (red->keep_res == NULL)
+ return 1;
+
gsi = gsi_after_labels (clsn_data->load_bb);
load_struct = build_simple_mem_ref (clsn_data->load);
load_struct = build3 (COMPONENT_REF, type, load_struct, red->field,
--
1.9.1
Handle exit phi without header phi in create_parallel_loop
2015-06-22 Tom de Vries <tom@codesourcery.com>
* tree-parloops.c (create_parallel_loop): Handle case that exit phi does
not have a corresponding loop header phi.
---
gcc/tree-parloops.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index 7123c27..0693b9e 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -2061,13 +2061,17 @@ create_parallel_loop (struct loop *loop, tree loop_fn, tree data,
!gsi_end_p (gpi); gsi_next (&gpi))
{
source_location locus;
- tree def;
gphi *phi = gpi.phi ();
- gphi *stmt;
+ tree def = PHI_ARG_DEF_FROM_EDGE (phi, exit);
+ gimple def_stmt = SSA_NAME_DEF_STMT (def);
- stmt = as_a <gphi *> (
- SSA_NAME_DEF_STMT (PHI_ARG_DEF_FROM_EDGE (phi, exit)));
+ /* If the exit phi is not connected to a header phi in the same loop, this
+ value is not modified in the loop, and we're done with this phi. */
+ if (!(gimple_code (def_stmt) == GIMPLE_PHI
+ && gimple_bb (def_stmt) == loop->header))
+ continue;
+ gphi *stmt = as_a <gphi *> (def_stmt);
def = PHI_ARG_DEF_FROM_EDGE (stmt, loop_preheader_edge (loop));
locus = gimple_phi_arg_location_from_edge (stmt,
loop_preheader_edge (loop));
--
1.9.1