[gcc/devel/omp/gcc-16] openmp: Disable strided target updates when iterators are used

Sandra Loosemore via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:f9b688be25d266f85a9eb745954998346685f361

commit f9b688be25d266f85a9eb745954998346685f361
Author: Kwok Cheung Yeung <[email protected]>
Date:   Thu Apr 23 22:34:40 2026 +0000

    openmp: Disable strided target updates when iterators are used
    
    Non-contiguous target updates result in the new strided target updates code
    being used, resulting in new clauses such as GOMP_MAP_GRID_DIM,
    GOMP_MAP_GRID_STRIDE etc. These are not currently supported in conjunction
    with iterators, so this code-path is disabled when used together with
    iterators.
    
    The older target updates supports non-contiguous updates as long as a stride
    is not applied.
    
    gcc/c/
    
            * c-typeck.cc (handle_omp_array_sections): Add extra argument.  Set
            argument to true if array section has a stride that is not one.
            (c_finish_omp_clauses): Disable strided updates when iterators are
            used in the clause.  Emit sorry if strided.
    
    gcc/cp/
    
            * semantics.cc (handle_omp_array_sections): Add extra argument.  Set
            argument to true if array section has a stride that is not one.
            (finish_omp_clauses): Disable strided updates when iterators are
            used in the clause.  Emit sorry if strided.
    
    gcc/fortran/
    
            * trans-openmp.cc (gfc_trans_omp_clauses): Disable strided updates
            when iterators are used in the clause.

Diff:
---
 gcc/c/c-typeck.cc           | 17 ++++++++++++++---
 gcc/cp/semantics.cc         | 18 ++++++++++++++----
 gcc/fortran/trans-openmp.cc |  3 +++
 3 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 9b1967ef9262..672f55c2f996 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -16310,7 +16310,7 @@ omp_array_section_low_bound (location_t loc, tree node)
 
 static bool
 handle_omp_array_sections (tree *pc, tree **pnext, enum c_omp_region_type ort,
-			   int *discontiguous)
+			   int *discontiguous, bool *strided = NULL)
 {
   tree c = *pc;
   bool maybe_zero_len = false;
@@ -16399,6 +16399,8 @@ handle_omp_array_sections (tree *pc, tree **pnext, enum c_omp_region_type ort,
 
 	  if (stride == NULL_TREE)
 	    stride = size_one_node;
+	  if (strided && !integer_onep (stride))
+	    *strided = true;
 	  if (discontiguous && *discontiguous)
 	    {
 	      /* This condition is similar to the error check below, but
@@ -17889,13 +17891,22 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 		grp_sentinel = OMP_CLAUSE_CHAIN (c);
 
 		tree *pnext = NULL;
+		/* FIXME: Strided target updates not supported together with
+		   iterators yet.  */
 		int discontiguous
 		  = (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
-		     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM);
-		if (handle_omp_array_sections (pc, &pnext, ort, &discontiguous))
+		     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM)
+		    && !OMP_CLAUSE_ITERATORS (c);
+		bool strided = false;
+		if (handle_omp_array_sections (pc, &pnext, ort, &discontiguous,
+					       &strided))
 		  remove = true;
 		else
 		  {
+		    if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
+			 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM)
+			&& OMP_CLAUSE_ITERATORS (c) && strided)
+		      sorry ("strided target updates with iterators");
 		    c = *pc;
 		    t = OMP_CLAUSE_DECL (c);
 		    if (!omp_mappable_type (TREE_TYPE (t)))
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 50e4493bcf4b..24e3bd9b82d7 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -6515,7 +6515,7 @@ omp_array_section_low_bound (location_t loc, tree node)
 
 static bool
 handle_omp_array_sections (tree *pc, tree **pnext, enum c_omp_region_type ort,
-			   int *discontiguous)
+			   int *discontiguous, bool *strided = NULL)
 {
   tree c = *pc;
   bool maybe_zero_len = false;
@@ -6609,6 +6609,8 @@ handle_omp_array_sections (tree *pc, tree **pnext, enum c_omp_region_type ort,
 
 	  if (stride == NULL_TREE)
 	    stride = size_one_node;
+	  if (strided && !integer_onep (stride))
+	    *strided = true;
 	  if (discontiguous && *discontiguous)
 	    {
 	      /* This condition is similar to the error check below, but
@@ -9546,15 +9548,23 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 	      {
 		grp_start_p = pc;
 		grp_sentinel = OMP_CLAUSE_CHAIN (c);
-
+		/* FIXME: Strided target updates not supported together with
+		   iterators yet.  */
 		int discontiguous
 		  = (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
-		     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM);
+		     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM)
+		    && !OMP_CLAUSE_ITERATORS (c);
+		bool strided = false;
 		tree *pnext = NULL;
-		if (handle_omp_array_sections (pc, &pnext, ort, &discontiguous))
+		if (handle_omp_array_sections (pc, &pnext, ort, &discontiguous,
+					       &strided))
 		  remove = true;
 		else
 		  {
+		    if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
+			 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM)
+			&& OMP_CLAUSE_ITERATORS (c) && strided)
+		      sorry ("strided target updates with iterators");
 		    /* We might have replaced the clause, so refresh C.  */
 		    c = *pc;
 		    t = OMP_CLAUSE_DECL (c);
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index 743e63767944..d2895b05e9ec 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -5852,7 +5852,10 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses,
 		  gcc_unreachable ();
 		}
 
+	      /* FIXME: Currently no support for strided target updates with
+		 iterators.  */
 	      if ((list == OMP_LIST_TO || list == OMP_LIST_FROM)
+		  && !iterator
 		  && (!n->expr
 		       || (n->expr
 			   && n->expr->ref
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.