diff mbox

[2/5] Add missing phis in expand_omp_for_generic

Message ID 5618FB46.2020903@mentor.com
State New
Headers show

Commit Message

Tom de Vries Oct. 10, 2015, 11:49 a.m. UTC
On 10/10/15 13:06, Tom de Vries wrote:
> OK, I'll repost with the patch split up, as follows:
>
>       1    Handle simple latch in expand_omp_for_generic
>       2    Add missing phis in expand_omp_for_generic
>       3    Handle original loop tree in expand_omp_for_generic
>       4    Support DEFPARAMENUM in params.def
>       5    Add param parloops-schedule

Hi,

this patch adds missing phis in expand_omp_for_generic.

In expand_omp_for_generic, we add an outer loop around an inner loop. 
That means we need to:
- add the necessary phis on the outer loop, and
- move the loop entry value of the inner phi to the loop entry value of
   the outer phi

Thanks,
- Tom

Comments

Bernd Schmidt Oct. 12, 2015, 2:05 p.m. UTC | #1
On 10/10/2015 01:49 PM, Tom de Vries wrote:
> On 10/10/15 13:06, Tom de Vries wrote:
>> OK, I'll repost with the patch split up, as follows:
>>
>>       1    Handle simple latch in expand_omp_for_generic
>>       2    Add missing phis in expand_omp_for_generic
>>       3    Handle original loop tree in expand_omp_for_generic
>>       4    Support DEFPARAMENUM in params.def
>>       5    Add param parloops-schedule
>
> Hi,
>
> this patch adds missing phis in expand_omp_for_generic.
>
> In expand_omp_for_generic, we add an outer loop around an inner loop.
> That means we need to:
> - add the necessary phis on the outer loop, and
> - move the loop entry value of the inner phi to the loop entry value of
>    the outer phi

Also ok, I think. This seems to be slightly different from the one 
originally submitted?


Bernd
Tom de Vries Oct. 12, 2015, 2:11 p.m. UTC | #2
On 12/10/15 16:05, Bernd Schmidt wrote:
> This seems to be slightly different from the one originally submitted?

Hi Bernd,

As I mentioned here  ( 
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg01043.html ),  I've moved 
the ssa-support bit into the !broken_loop condition. I think that's the 
only difference.

Thanks,
- Tom
diff mbox

Patch

Add missing phis in expand_omp_for_generic

2015-09-10  Tom de Vries  <tom@codesourcery.com>

	PR tree-optimization/67476
	* omp-low.c (expand_omp_for_generic): Add missing phis.
---
 gcc/omp-low.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index f59a6a4..b2a93b9 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -238,6 +238,7 @@  static vec<omp_context *> taskreg_contexts;
 
 static void scan_omp (gimple_seq *, omp_context *);
 static tree scan_omp_1_op (tree *, int *, void *);
+static gphi *find_phi_with_arg_on_edge (tree, edge);
 
 #define WALK_SUBSTMTS  \
     case GIMPLE_BIND: \
@@ -6469,6 +6470,43 @@  expand_omp_for_generic (struct omp_region *region,
 	}
       make_edge (l2_bb, l0_bb, EDGE_TRUE_VALUE);
 
+      if (gimple_in_ssa_p (cfun))
+	{
+	  /* Add phis to the outer loop that connect to the phis in the inner,
+	     original loop, and move the loop entry value of the inner phi to
+	     the loop entry value of the outer phi.  */
+	  gphi_iterator psi;
+	  for (psi = gsi_start_phis (l3_bb); !gsi_end_p (psi); gsi_next (&psi))
+	    {
+	      source_location locus;
+	      gphi *nphi;
+	      gphi *exit_phi = psi.phi ();
+
+	      edge l2_to_l3 = find_edge (l2_bb, l3_bb);
+	      tree exit_res = PHI_ARG_DEF_FROM_EDGE (exit_phi, l2_to_l3);
+
+	      basic_block latch = BRANCH_EDGE (cont_bb)->dest;
+	      edge latch_to_l1 = find_edge (latch, l1_bb);
+	      gphi *inner_phi
+		= find_phi_with_arg_on_edge (exit_res, latch_to_l1);
+
+	      tree t = gimple_phi_result (exit_phi);
+	      tree new_res = copy_ssa_name (t, NULL);
+	      nphi = create_phi_node (new_res, l0_bb);
+
+	      edge l0_to_l1 = find_edge (l0_bb, l1_bb);
+	      t = PHI_ARG_DEF_FROM_EDGE (inner_phi, l0_to_l1);
+	      locus = gimple_phi_arg_location_from_edge (inner_phi, l0_to_l1);
+	      edge entry_to_l0 = find_edge (entry_bb, l0_bb);
+	      add_phi_arg (nphi, t, entry_to_l0, locus);
+
+	      edge l2_to_l0 = find_edge (l2_bb, l0_bb);
+	      add_phi_arg (nphi, exit_res, l2_to_l0, UNKNOWN_LOCATION);
+
+	      add_phi_arg (inner_phi, new_res, l0_to_l1, UNKNOWN_LOCATION);
+	    };
+	}
+
       set_immediate_dominator (CDI_DOMINATORS, l2_bb,
 			       recompute_dominator (CDI_DOMINATORS, l2_bb));
       set_immediate_dominator (CDI_DOMINATORS, l3_bb,
-- 
1.9.1