Hi!

If simdlen clause is specified, it is the preferred number of concurrent
simd lanes in the loop, though if if clause is specified and evaluates to
false, the preferred number of simd lanes is 1 (i.e. no vectorization).

This patch handles just the easy part, when simdlen argument is 1 or when
if clause has constant argument which is false.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk,
queued for eventual backport to 9.2.

2019-05-15  Jakub Jelinek  <ja...@redhat.com>

        * omp-low.c (lower_rec_input_clauses): For if (0) or simdlen (1) set
        max_vf to 1.
        * omp-expand.c (expand_omp_simd): For if (0) or simdlen (1) clear
        safelen_int and set loop->dont_vectorize.

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

--- gcc/omp-low.c.jj    2019-03-28 23:32:44.813393829 +0100
+++ gcc/omp-low.c       2019-05-15 14:56:19.564136934 +0200
@@ -3811,6 +3811,14 @@ lower_rec_input_clauses (tree clauses, g
              || is_variable_sized (OMP_CLAUSE_DECL (c)))
            sctx.max_vf = 1;
          break;
+       case OMP_CLAUSE_IF:
+         if (integer_zerop (OMP_CLAUSE_IF_EXPR (c)))
+           sctx.max_vf = 1;
+         break;
+        case OMP_CLAUSE_SIMDLEN:
+         if (integer_onep (OMP_CLAUSE_SIMDLEN_EXPR (c)))
+           sctx.max_vf = 1;
+         break;
        default:
          continue;
        }
--- gcc/omp-expand.c.jj 2019-03-07 20:45:39.170938327 +0100
+++ gcc/omp-expand.c    2019-05-15 14:55:22.493079461 +0200
@@ -4664,10 +4664,15 @@ expand_omp_simd (struct omp_region *regi
   tree *counts = NULL;
   int i;
   int safelen_int = INT_MAX;
+  bool dont_vectorize = false;
   tree safelen = omp_find_clause (gimple_omp_for_clauses (fd->for_stmt),
                                  OMP_CLAUSE_SAFELEN);
   tree simduid = omp_find_clause (gimple_omp_for_clauses (fd->for_stmt),
                                  OMP_CLAUSE__SIMDUID_);
+  tree ifc = omp_find_clause (gimple_omp_for_clauses (fd->for_stmt),
+                             OMP_CLAUSE_IF);
+  tree simdlen = omp_find_clause (gimple_omp_for_clauses (fd->for_stmt),
+                                 OMP_CLAUSE_SIMDLEN);
   tree n1, n2;
 
   if (safelen)
@@ -4681,6 +4686,12 @@ expand_omp_simd (struct omp_region *regi
       if (safelen_int == 1)
        safelen_int = 0;
     }
+  if ((ifc && integer_zerop (OMP_CLAUSE_IF_EXPR (ifc)))
+      || (simdlen && integer_onep (OMP_CLAUSE_SIMDLEN_EXPR (simdlen))))
+    {
+      safelen_int = 0;
+      dont_vectorize = true;
+    }
   type = TREE_TYPE (fd->loop.v);
   entry_bb = region->entry;
   cont_bb = region->cont;
@@ -4965,6 +4976,8 @@ expand_omp_simd (struct omp_region *regi
          loop->force_vectorize = true;
          cfun->has_force_vectorize_loops = true;
        }
+      else if (dont_vectorize)
+       loop->dont_vectorize = true;
     }
   else if (simduid)
     cfun->has_simduid_loops = true;
--- gcc/testsuite/c-c++-common/gomp/simd8.c.jj  2019-05-15 14:24:44.656430757 
+0200
+++ gcc/testsuite/c-c++-common/gomp/simd8.c     2019-05-15 15:44:08.161617663 
+0200
@@ -0,0 +1,37 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -O3 -fdump-tree-vect-details" } */
+/* { dg-final { scan-tree-dump-times "vectorized 0 loops in function" 4 "vect" 
} } */
+
+int a[1024];
+
+void
+foo (void)
+{
+  #pragma omp simd if (0)
+  for (int i = 0; i < 1024; ++i)
+    a[i] = a[i] + 1;
+}
+
+void
+bar (void)
+{
+  #pragma omp simd if (0) safelen (256) simdlen (8)
+  for (int i = 0; i < 512; ++i)
+    a[i] = a[i] + 1;
+}
+
+void
+baz (void)
+{
+  #pragma omp simd safelen (256) simdlen (1)
+  for (int i = 0; i < 512; ++i)
+    a[i] = a[i] + 1;
+}
+
+void
+qux (void)
+{
+  #pragma omp simd simdlen (1) if (1)
+  for (int i = 0; i < 512; ++i)
+    a[i] = a[i] + 1;
+}

        Jakub

Reply via email to