public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [gomp4.1] Fix up ordered threads handling and initial step towards ordered simd
@ 2015-09-02  9:29 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2015-09-02  9:29 UTC (permalink / raw)
  To: gcc-patches; +Cc: Aldy Hernandez

Hi!

This fixes ICE with ordered simd (broken with the doacross changes; the
second chunk) and allows ordered simd inside of simd regions.
As it is still unclear whether ordered simd is required to be only closely
nested inside of simd construct or declare simd functions (i.e. lexically
nested), or only closely nested region (i.e. dynamically nested), I'm
deferring further implementation until that is settled.

Committed to gomp 4.1 branch.

2015-09-02  Jakub Jelinek  <jakub@redhat.com>

	* omp-low.c (check_omp_nesting_restrictions): Allow ordered simd
	instead of simd region.  Don't assume that all ordered construct
	clauses must be depend clauses.

	* testsuite/libgomp.c/ordered-4.c: New test.
	* testsuite/libgomp.c++/ordered-1.C: New test.

--- gcc/omp-low.c.jj	2015-08-31 16:57:23.000000000 +0200
+++ gcc/omp-low.c	2015-09-01 17:39:05.114232692 +0200
@@ -3118,8 +3118,16 @@ check_omp_nesting_restrictions (gimple s
       if (gimple_code (ctx->stmt) == GIMPLE_OMP_FOR
 	  && gimple_omp_for_kind (ctx->stmt) & GF_OMP_FOR_SIMD)
 	{
+	  c = NULL_TREE;
+	  if (gimple_code (stmt) == GIMPLE_OMP_ORDERED)
+	    {
+	      c = gimple_omp_ordered_clauses (as_a <gomp_ordered *> (stmt));
+	      if (c && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SIMD)
+		return true;
+	    }
 	  error_at (gimple_location (stmt),
-		    "OpenMP constructs may not be nested inside simd region");
+		    "OpenMP constructs other than %<#pragma omp ordered simd%>"
+		    " may not be nested inside simd region");
 	  return false;
 	}
       else if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS)
@@ -3337,6 +3345,13 @@ check_omp_nesting_restrictions (gimple s
       for (c = gimple_omp_ordered_clauses (as_a <gomp_ordered *> (stmt));
 	   c; c = OMP_CLAUSE_CHAIN (c))
 	{
+	  if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
+	    {
+	      gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREADS
+			  || (ctx == NULL
+			      && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SIMD));
+	      continue;
+	    }
 	  enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_KIND (c);
 	  if (kind == OMP_CLAUSE_DEPEND_SOURCE
 	      || kind == OMP_CLAUSE_DEPEND_SINK)
--- libgomp/testsuite/libgomp.c/ordered-4.c.jj	2015-09-01 15:04:14.419283225 +0200
+++ libgomp/testsuite/libgomp.c/ordered-4.c	2015-09-01 15:04:37.612966738 +0200
@@ -0,0 +1,83 @@
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void abort (void);
+
+void
+foo (int i, char *j)
+{
+  #pragma omp atomic
+  j[i]++;
+  #pragma omp ordered threads
+  {
+    int t;
+    #pragma omp atomic read
+    t = j[i];
+    if (t != 3)
+      abort ();
+    if (i > 1)
+      {
+	#pragma omp atomic read
+	t = j[i - 1];
+	if (t == 2)
+	  abort ();
+      }
+    if (i < 127)
+      {
+	#pragma omp atomic read
+	t = j[i + 1];
+	if (t == 4)
+	  abort ();
+      }
+  }
+  #pragma omp atomic
+  j[i]++;
+}
+
+int
+main ()
+{
+  int i;
+  char j[128];
+  #pragma omp parallel
+  {
+    #pragma omp for
+    for (i = 0; i < 128; i++)
+      j[i] = 0;
+    #pragma omp for ordered schedule(dynamic, 1)
+    for (i = 0; i < 128; i++)
+      {
+	#pragma omp atomic
+	j[i]++;
+	#pragma omp ordered threads
+	{
+	  int t;
+	  #pragma omp atomic read
+	  t = j[i];
+	  if (t != 1)
+	    abort ();
+	  if (i > 1)
+	    {
+	      #pragma omp atomic read
+	      t = j[i - 1];
+	      if (t == 0)
+		abort ();
+	    }
+	  if (i < 127)
+	    {
+	      #pragma omp atomic read
+	      t = j[i + 1];
+	      if (t == 2)
+		abort ();
+	    }
+	}
+	#pragma omp atomic
+	j[i]++;
+      }
+    #pragma omp for ordered schedule(static, 1)
+    for (i = 0; i < 128; i++)
+      foo (i, j);
+  }
+  return 0;
+}
--- libgomp/testsuite/libgomp.c++/ordered-1.C.jj	2015-09-01 15:05:23.432341517 +0200
+++ libgomp/testsuite/libgomp.c++/ordered-1.C	2015-09-01 15:05:18.289411694 +0200
@@ -0,0 +1 @@
+#include "../libgomp.c/ordered-4.c"

	Jakub

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-09-02  9:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-02  9:29 [gomp4.1] Fix up ordered threads handling and initial step towards ordered simd Jakub Jelinek

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).