diff mbox

[hsa] Use gimplify_expr in gridification

Message ID 20151130232711.GC19649@virgil.suse.cz
State New
Headers show

Commit Message

Martin Jambor Nov. 30, 2015, 11:27 p.m. UTC
Hi,

doing some more testing of the branch and combining two of my
testcases I came accross a bug where temporaries created by
force_gimple_operand_gsi were not added to the proper bind and thus
were subsequently re-mapped to error_mark when the target construct
was within some other omp construct.  Fixed with this patch, where
pop_gimplify_context does the right thing like at other places in
omp-low.c.  Committed to the branch.

Thanks,

Martin



2015-11-30  Martin Jambor  <mjambor@suse.cz>

	* omp-low.c (attempt_target_gridification): Use gimplify_expr.
---
 gcc/omp-low.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
diff mbox

Patch

diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index bdf6539..7fbdcdf 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -17481,6 +17481,7 @@  attempt_target_gridification (gomp_target *target, gimple_stmt_iterator *gsi,
      gpukernel);
 
   walk_tree (&group_size, remap_prebody_decls, &wi, NULL);
+  push_gimplify_context ();
   size_t collapse = gimple_omp_for_collapse (inner_loop);
   for (size_t i = 0; i < collapse; i++)
     {
@@ -17499,30 +17500,32 @@  attempt_target_gridification (gomp_target *target, gimple_stmt_iterator *gsi,
       tree step;
       step = get_omp_for_step_from_incr (loc,
 					 gimple_omp_for_incr (inner_loop, i));
-      n1 = force_gimple_operand_gsi (gsi, fold_convert (type, n1), true,
-				     NULL_TREE, true, GSI_SAME_STMT);
-      n2 = force_gimple_operand_gsi (gsi, fold_convert (itype, n2), true,
-				     NULL_TREE,
-				     true, GSI_SAME_STMT);
+      gimple_seq tmpseq = NULL;
+      n1 = fold_convert (itype, n1);
+      n2 = fold_convert (itype, n2);
       tree t = build_int_cst (itype, (cond_code == LT_EXPR ? -1 : 1));
       t = fold_build2 (PLUS_EXPR, itype, step, t);
       t = fold_build2 (PLUS_EXPR, itype, t, n2);
-      t = fold_build2 (MINUS_EXPR, itype, t, fold_convert (itype, n1));
+      t = fold_build2 (MINUS_EXPR, itype, t, n1);
       if (TYPE_UNSIGNED (itype) && cond_code == GT_EXPR)
 	t = fold_build2 (TRUNC_DIV_EXPR, itype,
 			 fold_build1 (NEGATE_EXPR, itype, t),
 			 fold_build1 (NEGATE_EXPR, itype, step));
       else
 	t = fold_build2 (TRUNC_DIV_EXPR, itype, t, step);
-      t = fold_convert (uint32_type_node, t);
-      tree gs = force_gimple_operand_gsi (gsi, t, true, NULL_TREE, true,
-					  GSI_SAME_STMT);
+      tree gs = fold_convert (uint32_type_node, t);
+      gimplify_expr (&gs, &tmpseq, NULL, is_gimple_val, fb_rvalue);
+      if (!gimple_seq_empty_p (tmpseq))
+	gsi_insert_seq_before (gsi, tmpseq, GSI_SAME_STMT);
+
       tree ws;
       if (i == 0 && group_size)
 	{
 	  ws = fold_convert (uint32_type_node, group_size);
-	  ws = force_gimple_operand_gsi (gsi, ws, true, NULL_TREE, true,
-					 GSI_SAME_STMT);
+	  tmpseq = NULL;
+	  gimplify_expr (&ws, &tmpseq, NULL, is_gimple_val, fb_rvalue);
+	  if (!gimple_seq_empty_p (tmpseq))
+	    gsi_insert_seq_before (gsi, tmpseq, GSI_SAME_STMT);
 	}
       else
 	ws = build_zero_cst (uint32_type_node);
@@ -17534,7 +17537,7 @@  attempt_target_gridification (gomp_target *target, gimple_stmt_iterator *gsi,
       OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (target);
       gimple_omp_target_set_clauses (target, c);
     }
-
+  pop_gimplify_context (tgt_bind);
   delete declmap;
   return;
 }