[gomp5] Fix handling of task_reduction with variable length array sections

Message ID 20181009130800.GO11625@tucnak
State New
Headers show
Series
  • [gomp5] Fix handling of task_reduction with variable length array sections
Related show

Commit Message

Jakub Jelinek Oct. 9, 2018, 1:08 p.m.
Hi!

As the following testcase additions show, even the TYPE_MAX_VALUE var needs
to be forced into temporary if it is a user variable, otherwise if that
variable is changed by the user before taskgroup ends, we don't handle it
correctly.

In addition to that, this patch removes useless NULL second argument from
create_tmp_var, forgot we do have a default argument here.

Tested on x86_64-linux, committed to gomp-5_0-branch.

2018-10-09  Jakub Jelinek  <jakub@redhat.com>

	* omp-low.c (lower_omp_task_reductions): Force TYPE_MAX_VALUE into
	a temporary in the start sequence and even when it is a decl already.

	* omp-low.c (lower_rec_input_clauses, lower_reduction_clauses,
	lower_omp_task_reductions): Remove second argument create_tmp_var
	if it is NULL.
	* gimplify.c (gimplify_omp_depend): Likewise.

	* testsuite/libgomp.c-c++-common/task-reduction-5.c: Add further test
	to verify the array bound var can be changed in taskgroup.


	Jakub

Patch

--- gcc/omp-low.c.jj	2018-10-08 17:30:42.147353172 +0200
+++ gcc/omp-low.c	2018-10-09 14:19:54.672380754 +0200
@@ -4091,7 +4091,7 @@  lower_rec_input_clauses (tree clauses, g
 		  gimple_seq_add_stmt (ilist, g);
 		}
 
-	      tree y1 = create_tmp_var (ptype, NULL);
+	      tree y1 = create_tmp_var (ptype);
 	      gimplify_assign (y1, y, ilist);
 	      tree i2 = NULL_TREE, y2 = NULL_TREE;
 	      tree body2 = NULL_TREE, end2 = NULL_TREE;
@@ -4102,14 +4102,14 @@  lower_rec_input_clauses (tree clauses, g
 				     size_int (task_reduction_cnt_full
 					       + task_reduction_cntorig - 1),
 				     NULL_TREE, NULL_TREE);
-		  y3 = create_tmp_var (ptype, NULL);
+		  y3 = create_tmp_var (ptype);
 		  gimplify_assign (y3, ref, ilist);
 		}
 	      else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) || is_simd)
 		{
 		  if (pass != 3)
 		    {
-		      y2 = create_tmp_var (ptype, NULL);
+		      y2 = create_tmp_var (ptype);
 		      gimplify_assign (y2, y, ilist);
 		    }
 		  if (is_simd || OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
@@ -4126,23 +4126,23 @@  lower_rec_input_clauses (tree clauses, g
 		      if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
 			  && OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
 			{
-			  y3 = create_tmp_var (ptype, NULL);
+			  y3 = create_tmp_var (ptype);
 			  gimplify_assign (y3, unshare_expr (ref), ilist);
 			}
 		      if (is_simd)
 			{
-			  y4 = create_tmp_var (ptype, NULL);
+			  y4 = create_tmp_var (ptype);
 			  gimplify_assign (y4, ref, dlist);
 			}
 		    }
 		}
-	      tree i = create_tmp_var (TREE_TYPE (v), NULL);
+	      tree i = create_tmp_var (TREE_TYPE (v));
 	      gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), ilist);
 	      tree body = create_artificial_label (UNKNOWN_LOCATION);
 	      gimple_seq_add_stmt (ilist, gimple_build_label (body));
 	      if (y2)
 		{
-		  i2 = create_tmp_var (TREE_TYPE (v), NULL);
+		  i2 = create_tmp_var (TREE_TYPE (v));
 		  gimplify_assign (i2, build_int_cst (TREE_TYPE (v), 0), dlist);
 		  body2 = create_artificial_label (UNKNOWN_LOCATION);
 		  end2 = create_artificial_label (UNKNOWN_LOCATION);
@@ -5603,7 +5603,7 @@  lower_reduction_clauses (tree clauses, g
 	  tree d = OMP_CLAUSE_DECL (c);
 	  tree type = TREE_TYPE (d);
 	  tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
-	  tree i = create_tmp_var (TREE_TYPE (v), NULL);
+	  tree i = create_tmp_var (TREE_TYPE (v));
 	  tree ptype = build_pointer_type (TREE_TYPE (type));
 	  tree bias = TREE_OPERAND (d, 1);
 	  d = TREE_OPERAND (d, 0);
@@ -5667,10 +5667,10 @@  lower_reduction_clauses (tree clauses, g
 	    }
 	  new_var = fold_convert_loc (clause_loc, ptype, new_var);
 	  ref = fold_convert_loc (clause_loc, ptype, ref);
-	  tree m = create_tmp_var (ptype, NULL);
+	  tree m = create_tmp_var (ptype);
 	  gimplify_assign (m, new_var, stmt_seqp);
 	  new_var = m;
-	  m = create_tmp_var (ptype, NULL);
+	  m = create_tmp_var (ptype);
 	  gimplify_assign (m, ref, stmt_seqp);
 	  ref = m;
 	  gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), stmt_seqp);
@@ -6896,22 +6896,24 @@  lower_omp_task_reductions (omp_context *
 	    {
 	      tree type = TREE_TYPE (new_var);
 	      tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
-	      tree i = create_tmp_var (TREE_TYPE (v), NULL);
+	      tree i = create_tmp_var (TREE_TYPE (v));
 	      tree ptype = build_pointer_type (TREE_TYPE (type));
 	      if (DECL_P (v))
 		{
 		  v = maybe_lookup_decl_in_outer_ctx (v, ctx);
-		  gimplify_expr (&v, end, NULL, is_gimple_val, fb_rvalue);
+		  tree vv = create_tmp_var (TREE_TYPE (v));
+		  gimplify_assign (vv, v, start);
+		  v = vv;
 		}
 	      ref = build4 (ARRAY_REF, pointer_sized_int_node, avar,
 			    size_int (7 + cnt * 3), NULL_TREE, NULL_TREE);
 	      new_var = build_fold_addr_expr (new_var);
 	      new_var = fold_convert (ptype, new_var);
 	      ref = fold_convert (ptype, ref);
-	      tree m = create_tmp_var (ptype, NULL);
+	      tree m = create_tmp_var (ptype);
 	      gimplify_assign (m, new_var, end);
 	      new_var = m;
-	      m = create_tmp_var (ptype, NULL);
+	      m = create_tmp_var (ptype);
 	      gimplify_assign (m, ref, end);
 	      ref = m;
 	      gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), end);
--- gcc/gimplify.c.jj	2018-08-02 17:59:48.980047042 +0200
+++ gcc/gimplify.c	2018-10-09 14:13:25.243928507 +0200
@@ -7736,7 +7736,7 @@  gimplify_omp_depend (tree *list_p, gimpl
 	  cnts[i] = cnts[i - 1];
 	  continue;
 	}
-      cnts[i] = create_tmp_var (sizetype, NULL);
+      cnts[i] = create_tmp_var (sizetype);
       if (i == 0)
 	g = gimple_build_assign (cnts[i], size_int (is_old ? 2 : 5));
       else
--- libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c.jj	2018-10-08 17:22:33.200531039 +0200
+++ libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c	2018-10-09 13:56:38.907851288 +0200
@@ -7,49 +7,58 @@  void abort (void);
 int *q;
 
 void
-bar (int *p, int *r, int s)
+bar (int *p, int *r, int *t, int s, __SIZE_TYPE__ u)
 {
-  #pragma omp task in_reduction (*: p[0], q[0], r[s - 1])
+  #pragma omp task in_reduction (*: p[0], q[0], r[s - 1], t[0:u + 1])
   {
     *p *= 4;
     *q *= 5;
     r[s - 1] *= 6;
+    t[0] *= 8;
+    t[1] *= 9;
   }
 }
 
 void
-foo (int *p, int *r, int s)
+foo (int *p, int *r, int *t, int s, __SIZE_TYPE__ u)
 {
   int *p2 = p;
-  #pragma omp taskgroup task_reduction (*: p[0], q[0], r[s])
+  #pragma omp taskgroup task_reduction (*: p[0], q[0], r[s], t[0:u + 1])
   {
     p = (int *) 0;
     s++;
-    bar (p2, r, s);
+    bar (p2, r, t, s, u);
     r++;
     #pragma omp taskwait
-    #pragma omp task in_reduction (*: p2[0], q[0], r[s - 2])
+    #pragma omp task in_reduction (*: p2[0], q[0], r[s - 2], t[0:u + 1])
     {
       *p2 *= 2;
       *q *= 3;
       r[s - 2] *= 7;
+      t[0] *= 10;
+      t[1] *= 11;
     }
+    u = __SIZE_MAX__ / 4;
     s++;
     p2 = (int *) 0;
     q = (int *) 0;
     r = (int *) 0;
+    t = (int *) 0;
   }
 }
 
 int
 main ()
 {
-  int a = 1, b = 1, c[2] = { 1, 0 };
+  int a = 1, b = 1, c[2] = { 1, 0 }, d[3] = { 1, 1, -1 };
+  volatile int zero;
+  zero = 0;
   q = &b;
   #pragma omp parallel num_threads (2)
   #pragma omp master
-  foo (&a, &c[0], 0);
-  if (a != 8 || b != 15 || c[0] != 42 || c[1] != 0)
+  foo (&a, &c[0], &d[0], zero, zero + 1);
+  if (a != 8 || b != 15 || c[0] != 42 || c[1] != 0
+      || d[0] != 80 || d[1] != 99 || d[2] != -1)
     abort ();
   return 0;
 }