[gcc/devel/omp/gcc-9] backport: omp-low.c (lower_rec_input_clauses): For if (0) or simdlen (1) set max_vf to 1.

Tobias Burnus burnus@gcc.gnu.org
Thu Mar 5 13:50:00 GMT 2020


https://gcc.gnu.org/g:0d50662086f2f32855051ef50310086fdf5d46b6

commit 0d50662086f2f32855051ef50310086fdf5d46b6
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri May 17 21:52:55 2019 +0200

    backport: omp-low.c (lower_rec_input_clauses): For if (0) or simdlen (1) set max_vf to 1.
    
    	Backported from mainline
    	2019-05-15  Jakub Jelinek  <jakub@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.
    
    From-SVN: r271354

Diff:
---
 gcc/ChangeLog                           |  7 +++++++
 gcc/omp-expand.c                        | 13 ++++++++++++
 gcc/omp-low.c                           |  8 +++++++
 gcc/testsuite/ChangeLog                 |  4 ++++
 gcc/testsuite/c-c++-common/gomp/simd8.c | 37 +++++++++++++++++++++++++++++++++
 5 files changed, 69 insertions(+)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ac65f1e..2d0a893 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,13 @@
 2019-05-17  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-05-15  Jakub Jelinek  <jakub@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.
+
 	2019-05-10  Jakub Jelinek  <jakub@redhat.com>
 
 	PR tree-optimization/90385
diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c
index 89a3a32..7415973 100644
--- a/gcc/omp-expand.c
+++ b/gcc/omp-expand.c
@@ -4664,10 +4664,15 @@ expand_omp_simd (struct omp_region *region, struct omp_for_data *fd)
   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 *region, struct omp_for_data *fd)
       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 *region, struct omp_for_data *fd)
 	  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;
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 874781a..3a3d09c 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -3811,6 +3811,14 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
 	      || 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;
 	}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 42955ca..eec3cc9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,10 @@
 2019-05-17  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-05-15  Jakub Jelinek  <jakub@redhat.com>
+
+	* c-c++-common/gomp/simd8.c: New test.
+
 	2019-05-10  Jakub Jelinek  <jakub@redhat.com>
 
 	PR tree-optimization/90385
diff --git a/gcc/testsuite/c-c++-common/gomp/simd8.c b/gcc/testsuite/c-c++-common/gomp/simd8.c
new file mode 100644
index 0000000..11f7411
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/simd8.c
@@ -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;
+}



More information about the Gcc-cvs mailing list