public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [committed] Fix OpenMP array reduction handling in orphaned workshare (PR middle-end/80853)
Date: Mon, 22 May 2017 19:03:00 -0000	[thread overview]
Message-ID: <20170522185829.GF8499@tucnak> (raw)

Hi!

For pointer based array sections, we are not requiring the pointer to be
shared in outer context and it might be not shared (e.g. function argument
or just a private pointer initialized to point to something shared etc.),
which is right, but we shouldn't require it during lowering either.

This patch fixes ICE on it.  Bootstrapped/regtested on x86_64-linux and
i686-linux, committed to trunk, queued for release branches.

2017-05-22  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/80853
	* omp-low.c (lower_reduction_clauses): Pass OMP_CLAUSE_PRIVATE
	as last argument to build_outer_var_ref for pointer bases of array
	section reductions.

	* testsuite/libgomp.c/pr80853.c: New test.

--- gcc/omp-low.c.jj	2017-04-21 08:14:29.436790613 +0200
+++ gcc/omp-low.c	2017-05-22 11:34:51.085746641 +0200
@@ -5140,15 +5140,25 @@ lower_reduction_clauses (tree clauses, g
       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
 	continue;
 
+      enum omp_clause_code ccode = OMP_CLAUSE_REDUCTION;
       orig_var = var = OMP_CLAUSE_DECL (c);
       if (TREE_CODE (var) == MEM_REF)
 	{
 	  var = TREE_OPERAND (var, 0);
 	  if (TREE_CODE (var) == POINTER_PLUS_EXPR)
 	    var = TREE_OPERAND (var, 0);
-	  if (TREE_CODE (var) == INDIRECT_REF
-	      || TREE_CODE (var) == ADDR_EXPR)
+	  if (TREE_CODE (var) == ADDR_EXPR)
 	    var = TREE_OPERAND (var, 0);
+	  else
+	    {
+	      /* If this is a pointer or referenced based array
+		 section, the var could be private in the outer
+		 context e.g. on orphaned loop construct.  Pretend this
+		 is private variable's outer reference.  */
+	      ccode = OMP_CLAUSE_PRIVATE;
+	      if (TREE_CODE (var) == INDIRECT_REF)
+		var = TREE_OPERAND (var, 0);
+	    }
 	  orig_var = var;
 	  if (is_variable_sized (var))
 	    {
@@ -5162,7 +5172,7 @@ lower_reduction_clauses (tree clauses, g
       new_var = lookup_decl (var, ctx);
       if (var == OMP_CLAUSE_DECL (c) && omp_is_reference (var))
 	new_var = build_simple_mem_ref_loc (clause_loc, new_var);
-      ref = build_outer_var_ref (var, ctx);
+      ref = build_outer_var_ref (var, ctx, ccode);
       code = OMP_CLAUSE_REDUCTION_CODE (c);
 
       /* reduction(-:var) sums up the partial results, so it acts
--- libgomp/testsuite/libgomp.c/pr80853.c.jj	2017-05-22 11:28:50.060287195 +0200
+++ libgomp/testsuite/libgomp.c/pr80853.c	2017-05-22 11:28:29.000000000 +0200
@@ -0,0 +1,29 @@
+/* PR middle-end/80853 */
+/* { dg-do run } */
+
+__attribute__((noinline, noclone)) void
+foo (int *p)
+{
+  #pragma omp for reduction(+:p[:4])
+  for (int i = 0; i < 64; i++)
+    {
+      p[0] += i;
+      p[1] += i / 2;
+      p[2] += 2 * i;
+      p[3] += 3 * i;
+    }
+}
+
+int
+main ()
+{
+  int p[4] = { 0, 0, 0, 0 };
+  #pragma omp parallel
+  foo (p);
+  if (p[0] != 63 * 64 / 2
+      || p[1] != 31 * 32
+      || p[2] != 63 * 64
+      || p[3] != 3 * 63 * 64 / 2)
+    __builtin_abort ();
+  return 0;
+}

	Jakub

                 reply	other threads:[~2017-05-22 18:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170522185829.GF8499@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).