Hi!

#pragma omp atomic is now allowed inside of simd regions.
Tested on x86_64-linux, committed to gomp-5_0-branch.

We will actually not vectorize it then though, so some further work will be
needed in the vectorizer to handle it.  Either, if we have hw atomics for both
the size of the scalar accesses and size of the whole vector type, the
accesses are adjacent and known to be aligned, we could replace it with
atomic on the whole vector, or emit as a small loop or unrolled loop doing
the extraction, scalar atomics and if needed insert result back into
vectors.  Richard, thoughts on that?

2018-06-14  Jakub Jelinek  <ja...@redhat.com>

        * omp-low.c (check_omp_nesting_restrictions): Allow OpenMP atomics
        inside of simd regions.

        * c-c++-common/gomp/simd7.c: New test.

--- gcc/omp-low.c.jj    2018-06-08 12:12:34.377111135 +0200
+++ gcc/omp-low.c       2018-06-14 11:09:55.439824132 +0200
@@ -2463,9 +2463,13 @@ check_omp_nesting_restrictions (gimple *
                  return true;
                }
            }
+         else if (gimple_code (stmt) == GIMPLE_OMP_ATOMIC_LOAD
+                  || gimple_code (stmt) == GIMPLE_OMP_ATOMIC_STORE)
+           return true;
          error_at (gimple_location (stmt),
                    "OpenMP constructs other than %<#pragma omp ordered simd%>"
-                   " may not be nested inside %<simd%> region");
+                   " or %<#pragma omp atomic%> may not be nested inside"
+                   " %<simd%> region");
          return false;
        }
       else if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS)
--- gcc/testsuite/c-c++-common/gomp/simd7.c.jj  2018-06-14 11:19:30.466274188 
+0200
+++ gcc/testsuite/c-c++-common/gomp/simd7.c     2018-06-14 10:55:52.520186067 
+0200
@@ -0,0 +1,21 @@
+int a[64];
+
+#pragma omp declare simd linear(x)
+int
+bar (int x, int y)
+{
+  int v;
+  #pragma omp atomic capture
+  v = a[x] += y;
+  return v;
+}
+
+void
+foo (void)
+{
+  int i;
+  #pragma omp simd
+  for (i = 0; i < 64; i++)
+    #pragma omp atomic
+    a[i] += 1;
+}

        Jakub

Reply via email to