--- gcc/omp-expand.c.jj	2021-10-09 10:07:51.913704546 +0200
+++ gcc/omp-expand.c	2021-10-26 16:24:53.209939548 +0200
@@ -1975,6 +1975,7 @@ expand_omp_for_init_counts (struct omp_f
 	  break;
       if (i == fd->last_nonrect
 	  && fd->loops[i].outer == fd->last_nonrect - fd->first_nonrect
+	  && !POINTER_TYPE_P (TREE_TYPE (fd->loops[i].v))
 	  && !TYPE_UNSIGNED (TREE_TYPE (fd->loops[i].v)))
 	{
 	  int o = fd->first_nonrect;
@@ -2250,15 +2251,22 @@ expand_omp_for_init_counts (struct omp_f
 	      gsi2 = gsi_after_labels (cur_bb);
 	      tree n1, n2;
 	      t = fold_convert (itype, unshare_expr (fd->loops[i].n1));
-	      if (fd->loops[i].m1)
+	      if (fd->loops[i].m1 == NULL_TREE)
+		n1 = t;
+	      else if (POINTER_TYPE_P (itype))
+		{
+		  gcc_assert (integer_onep (fd->loops[i].m1));
+		  t = fold_convert (sizetype,
+				    unshare_expr (fd->loops[i].n1));
+		  n1 = fold_build_pointer_plus (vs[i - fd->loops[i].outer], t);
+		}
+	      else
 		{
 		  n1 = fold_convert (itype, unshare_expr (fd->loops[i].m1));
 		  n1 = fold_build2 (MULT_EXPR, itype,
 				    vs[i - fd->loops[i].outer], n1);
 		  n1 = fold_build2 (PLUS_EXPR, itype, n1, t);
 		}
-	      else
-		n1 = t;
 	      n1 = force_gimple_operand_gsi (&gsi2, n1, true, NULL_TREE,
 					     true, GSI_SAME_STMT);
 	      if (i < fd->last_nonrect)
@@ -2267,17 +2275,26 @@ expand_omp_for_init_counts (struct omp_f
 		  expand_omp_build_assign (&gsi2, vs[i], n1);
 		}
 	      t = fold_convert (itype, unshare_expr (fd->loops[i].n2));
-	      if (fd->loops[i].m2)
+	      if (fd->loops[i].m2 == NULL_TREE)
+		n2 = t;
+	      else if (POINTER_TYPE_P (itype))
+		{
+		  gcc_assert (integer_onep (fd->loops[i].m2));
+		  t = fold_convert (sizetype,
+				    unshare_expr (fd->loops[i].n2));
+		  n2 = fold_build_pointer_plus (vs[i - fd->loops[i].outer], t);
+		}
+	      else
 		{
 		  n2 = fold_convert (itype, unshare_expr (fd->loops[i].m2));
 		  n2 = fold_build2 (MULT_EXPR, itype,
 				    vs[i - fd->loops[i].outer], n2);
 		  n2 = fold_build2 (PLUS_EXPR, itype, n2, t);
 		}
-	      else
-		n2 = t;
 	      n2 = force_gimple_operand_gsi (&gsi2, n2, true, NULL_TREE,
 					     true, GSI_SAME_STMT);
+	      if (POINTER_TYPE_P (itype))
+		itype = signed_type_for (itype);
 	      if (i == fd->last_nonrect)
 		{
 		  gcond *cond_stmt
@@ -2295,8 +2312,10 @@ expand_omp_for_init_counts (struct omp_f
 					     ? -1 : 1));
 		  t = fold_build2 (PLUS_EXPR, itype,
 				   fold_convert (itype, fd->loops[i].step), t);
-		  t = fold_build2 (PLUS_EXPR, itype, t, n2);
-		  t = fold_build2 (MINUS_EXPR, itype, t, n1);
+		  t = fold_build2 (PLUS_EXPR, itype, t,
+				   fold_convert (itype, n2));
+		  t = fold_build2 (MINUS_EXPR, itype, t,
+				   fold_convert (itype, n1));
 		  tree step = fold_convert (itype, fd->loops[i].step);
 		  if (TYPE_UNSIGNED (itype)
 		      && fd->loops[i].cond_code == GT_EXPR)
@@ -2323,7 +2342,11 @@ expand_omp_for_init_counts (struct omp_f
 	      gsi2 = gsi_after_labels (e->dest);
 	      tree step = fold_convert (itype,
 					unshare_expr (fd->loops[i].step));
-	      t = fold_build2 (PLUS_EXPR, itype, vs[i], step);
+	      if (POINTER_TYPE_P (TREE_TYPE (vs[i])))
+		t = fold_build_pointer_plus (vs[i],
+					     fold_convert (sizetype, step));
+	      else
+		t = fold_build2 (PLUS_EXPR, itype, vs[i], step);
 	      t = force_gimple_operand_gsi (&gsi2, t, true, NULL_TREE,
 					    true, GSI_SAME_STMT);
 	      expand_omp_build_assign (&gsi2, vs[i], t);
@@ -2761,17 +2784,22 @@ expand_omp_for_init_vars (struct omp_for
 			     && !fd->loops[j].non_rect_referenced);
 	      gsi2 = gsi_after_labels (cur_bb);
 	      t = fold_convert (itype, unshare_expr (fd->loops[j].n1));
-	      if (fd->loops[j].m1)
+	      if (fd->loops[j].m1 == NULL_TREE)
+		n1 = rect_p ? build_zero_cst (type) : t;
+	      else if (POINTER_TYPE_P (itype))
+		{
+		  gcc_assert (integer_onep (fd->loops[j].m1));
+		  t = fold_convert (sizetype,
+				    unshare_expr (fd->loops[j].n1));
+		  n1 = fold_build_pointer_plus (vs[j - fd->loops[j].outer], t);
+		}
+	      else
 		{
 		  n1 = fold_convert (itype, unshare_expr (fd->loops[j].m1));
 		  n1 = fold_build2 (MULT_EXPR, itype,
 				    vs[j - fd->loops[j].outer], n1);
 		  n1 = fold_build2 (PLUS_EXPR, itype, n1, t);
 		}
-	      else if (rect_p)
-		n1 = build_zero_cst (type);
-	      else
-		n1 = t;
 	      n1 = force_gimple_operand_gsi (&gsi2, n1, true, NULL_TREE,
 					     true, GSI_SAME_STMT);
 	      if (j < fd->last_nonrect)
@@ -2780,19 +2808,26 @@ expand_omp_for_init_vars (struct omp_for
 		  expand_omp_build_assign (&gsi2, vs[j], n1);
 		}
 	      t = fold_convert (itype, unshare_expr (fd->loops[j].n2));
-	      if (fd->loops[j].m2)
+	      if (fd->loops[j].m2 == NULL_TREE)
+		n2 = rect_p ? counts[j] : t;
+	      else if (POINTER_TYPE_P (itype))
+		{
+		  gcc_assert (integer_onep (fd->loops[j].m2));
+		  t = fold_convert (sizetype,
+				    unshare_expr (fd->loops[j].n2));
+		  n2 = fold_build_pointer_plus (vs[j - fd->loops[j].outer], t);
+		}
+	      else
 		{
 		  n2 = fold_convert (itype, unshare_expr (fd->loops[j].m2));
 		  n2 = fold_build2 (MULT_EXPR, itype,
 				    vs[j - fd->loops[j].outer], n2);
 		  n2 = fold_build2 (PLUS_EXPR, itype, n2, t);
 		}
-	      else if (rect_p)
-		n2 = counts[j];
-	      else
-		n2 = t;
 	      n2 = force_gimple_operand_gsi (&gsi2, n2, true, NULL_TREE,
 					     true, GSI_SAME_STMT);
+	      if (POINTER_TYPE_P (itype))
+		itype = signed_type_for (itype);
 	      if (j == fd->last_nonrect)
 		{
 		  gcond *cond_stmt
@@ -2810,8 +2845,10 @@ expand_omp_for_init_vars (struct omp_for
 					     ? -1 : 1));
 		  t = fold_build2 (PLUS_EXPR, itype,
 				   fold_convert (itype, fd->loops[j].step), t);
-		  t = fold_build2 (PLUS_EXPR, itype, t, n2);
-		  t = fold_build2 (MINUS_EXPR, itype, t, n1);
+		  t = fold_build2 (PLUS_EXPR, itype, t,
+				   fold_convert (itype, n2));
+		  t = fold_build2 (MINUS_EXPR, itype, t,
+				   fold_convert (itype, n1));
 		  tree step = fold_convert (itype, fd->loops[j].step);
 		  if (TYPE_UNSIGNED (itype)
 		      && fd->loops[j].cond_code == GT_EXPR)
@@ -2853,7 +2890,11 @@ expand_omp_for_init_vars (struct omp_for
 		{
 		  tree step
 		    = fold_convert (itype, unshare_expr (fd->loops[j].step));
-		  t = fold_build2 (PLUS_EXPR, itype, vs[j], step);
+		  if (POINTER_TYPE_P (vtype))
+		    t = fold_build_pointer_plus (vs[j], fold_convert (sizetype,
+								      step));
+		  else
+		    t = fold_build2 (PLUS_EXPR, itype, vs[j], step);
 		}
 	      t = force_gimple_operand_gsi (&gsi2, t, true, NULL_TREE,
 					    true, GSI_SAME_STMT);
@@ -2899,7 +2940,10 @@ expand_omp_for_init_vars (struct omp_for
 	    }
 	  for (int j = fd->last_nonrect; j >= fd->first_nonrect; j--)
 	    {
-	      tree itype = TREE_TYPE (fd->loops[j].v);
+	      tree vtype = TREE_TYPE (fd->loops[j].v);
+	      tree itype = vtype;
+	      if (POINTER_TYPE_P (itype))
+		itype = signed_type_for (itype);
 	      bool rect_p = (fd->loops[j].m1 == NULL_TREE
 			     && fd->loops[j].m2 == NULL_TREE
 			     && !fd->loops[j].non_rect_referenced);
@@ -2910,7 +2954,11 @@ expand_omp_for_init_vars (struct omp_for
 		  tree t2
 		    = fold_convert (itype, unshare_expr (fd->loops[j].step));
 		  t = fold_build2 (MULT_EXPR, itype, t, t2);
-		  t = fold_build2 (PLUS_EXPR, itype, n1, t);
+		  if (POINTER_TYPE_P (vtype))
+		    t = fold_build_pointer_plus (n1,
+						 fold_convert (sizetype, t));
+		  else
+		    t = fold_build2 (PLUS_EXPR, itype, n1, t);
 		}
 	      else if (rect_p)
 		{
@@ -2918,7 +2966,8 @@ expand_omp_for_init_vars (struct omp_for
 		  t = fold_build2 (MULT_EXPR, itype, t,
 				   fold_convert (itype, fd->loops[j].step));
 		  if (POINTER_TYPE_P (vtype))
-		    t = fold_build_pointer_plus (fd->loops[j].n1, t);
+		    t = fold_build_pointer_plus (fd->loops[j].n1,
+						 fold_convert (sizetype, t));
 		  else
 		    t = fold_build2 (PLUS_EXPR, itype, fd->loops[j].n1, t);
 		}
@@ -2978,12 +3027,23 @@ expand_omp_for_init_vars (struct omp_for
 	{
 	  tree itype = TREE_TYPE (fd->loops[i].v);
 
-	  tree t = fold_convert (itype, unshare_expr (fd->loops[i].m2));
-	  t = fold_build2 (MULT_EXPR, itype,
-			   fd->loops[i - fd->loops[i].outer].v, t);
-	  t = fold_build2 (PLUS_EXPR, itype, t,
-			   fold_convert (itype,
-					 unshare_expr (fd->loops[i].n2)));
+	  tree t;
+	  if (POINTER_TYPE_P (itype))
+	    {
+	      gcc_assert (integer_onep (fd->loops[i].m2));
+	      t = fold_convert (sizetype, unshare_expr (fd->loops[i].n2));
+	      t = fold_build_pointer_plus (fd->loops[i - fd->loops[i].outer].v,
+					   t);
+	    }
+	  else
+	    {
+	      t = fold_convert (itype, unshare_expr (fd->loops[i].m2));
+	      t = fold_build2 (MULT_EXPR, itype,
+			       fd->loops[i - fd->loops[i].outer].v, t);
+	      t = fold_build2 (PLUS_EXPR, itype, t,
+			       fold_convert (itype,
+					     unshare_expr (fd->loops[i].n2)));
+	    }
 	  nonrect_bounds[i] = create_tmp_reg (itype, ".bound");
 	  t = force_gimple_operand_gsi (gsi, t, false,
 					NULL_TREE, false,
@@ -3065,10 +3125,16 @@ extract_omp_for_update_vars (struct omp_
 	      t = l->n1;
 	      if (l->m1)
 		{
-		  tree t2
-		    = fold_build2 (MULT_EXPR, TREE_TYPE (t),
-				   fd->loops[i + 1 - l->outer].v, l->m1);
-		  t = fold_build2 (PLUS_EXPR, TREE_TYPE (t), t2, t);
+		  if (POINTER_TYPE_P (TREE_TYPE (l->v)))
+		    t = fold_build_pointer_plus (fd->loops[i + 1 - l->outer].v,
+						 fold_convert (sizetype, t));
+		  else
+		    {
+		      tree t2
+			= fold_build2 (MULT_EXPR, TREE_TYPE (t),
+				       fd->loops[i + 1 - l->outer].v, l->m1);
+		      t = fold_build2 (PLUS_EXPR, TREE_TYPE (t), t2, t);
+		    }
 		}
 	      t = force_gimple_operand_gsi (&gsi, t,
 					    DECL_P (l->v)
@@ -3116,9 +3182,17 @@ extract_omp_for_update_vars (struct omp_
 		  }
 		if (l->m1)
 		  {
-		    t = fold_build2 (MULT_EXPR, TREE_TYPE (l->m1), l->m1,
-				     fd->loops[i].v);
-		    t = fold_build2 (PLUS_EXPR, TREE_TYPE (l->v), t, l->n1);
+		    if (POINTER_TYPE_P (TREE_TYPE (l->v)))
+		      t = fold_build_pointer_plus (fd->loops[i].v,
+						   fold_convert (sizetype,
+								 l->n1));
+		    else
+		      {
+			t = fold_build2 (MULT_EXPR, TREE_TYPE (l->m1), l->m1,
+					 fd->loops[i].v);
+			t = fold_build2 (PLUS_EXPR, TREE_TYPE (l->v),
+					 t, l->n1);
+		      }
 		    n1 = force_gimple_operand_gsi (&gsi2, t, true, NULL_TREE,
 						   false,
 						   GSI_CONTINUE_LINKING);
@@ -3132,10 +3206,18 @@ extract_omp_for_update_vars (struct omp_
 						 GSI_CONTINUE_LINKING);
 		if (l->m2)
 		  {
-		    t = fold_build2 (MULT_EXPR, TREE_TYPE (l->m2), l->m2,
-				     fd->loops[i].v);
-		    t = fold_build2 (PLUS_EXPR, TREE_TYPE (nonrect_bounds[j]),
-				     t, unshare_expr (l->n2));
+		    if (POINTER_TYPE_P (TREE_TYPE (l->v)))
+		      t = fold_build_pointer_plus (fd->loops[i].v,
+						   fold_convert (sizetype,
+								 l->n2));
+		    else
+		      {
+			t = fold_build2 (MULT_EXPR, TREE_TYPE (l->m2), l->m2,
+					 fd->loops[i].v);
+			t = fold_build2 (PLUS_EXPR,
+					 TREE_TYPE (nonrect_bounds[j]),
+					 t, unshare_expr (l->n2));
+		      }
 		    n2 = force_gimple_operand_gsi (&gsi2, t, true, NULL_TREE,
 						   false,
 						   GSI_CONTINUE_LINKING);
--- gcc/c-family/c-omp.c	2021-10-21 18:31:29.967708593 +0200
+++ gcc/c-family/c-omp.c	2021-10-25 12:40:08.336995234 +0200
@@ -1358,6 +1358,7 @@ c_omp_check_loop_iv_r (tree *tp, int *wa
 	   && TREE_CODE (*tp) != PLUS_EXPR
 	   && TREE_CODE (*tp) != MINUS_EXPR
 	   && TREE_CODE (*tp) != MULT_EXPR
+	   && TREE_CODE (*tp) != POINTER_PLUS_EXPR
 	   && !CONVERT_EXPR_P (*tp))
     {
       *walk_subtrees = 0;
@@ -1477,6 +1478,18 @@ c_omp_check_nonrect_loop_iv (tree *tp, s
 	}
       a2 = integer_zero_node;
       break;
+    case POINTER_PLUS_EXPR:
+      a1 = TREE_OPERAND (t, 0);
+      a2 = TREE_OPERAND (t, 1);
+      while (CONVERT_EXPR_P (a1))
+	a1 = TREE_OPERAND (a1, 0);
+      if (DECL_P (a1) && c_omp_is_loop_iterator (a1, d) >= 0)
+	{
+	  a2 = TREE_OPERAND (t, 1);
+	  t = a1;
+	  break;
+	}
+      break;
     default:
       break;
     }
@@ -1599,10 +1612,7 @@ c_omp_check_loop_iv (tree stmt, tree dec
 	  data.fail = true;
 	}
       /* Handle non-rectangular loop nests.  */
-      if (TREE_CODE (stmt) != OACC_LOOP
-	  && (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC
-	      || INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 1))))
-	  && i > 0)
+      if (TREE_CODE (stmt) != OACC_LOOP && i > 0)
 	kind = 4;
       data.kind = kind;
       data.idx = i;
--- gcc/testsuite/c-c++-common/gomp/loop-8.c.jj	2021-10-25 18:30:15.301000256 +0200
+++ gcc/testsuite/c-c++-common/gomp/loop-8.c	2021-10-21 16:57:26.963432294 +0200
@@ -0,0 +1,10 @@
+void
+foo (void)
+{
+  int a[1024];
+  int *p, *q;
+  #pragma omp parallel for collapse(2)
+  for (p = &a[0]; p < &a[512]; p++)
+    for (q = p + 64; q < p + 128; q++)
+      ;
+}
--- gcc/testsuite/c-c++-common/gomp/loop-9.c.jj	2021-10-26 17:07:08.686192027 +0200
+++ gcc/testsuite/c-c++-common/gomp/loop-9.c	2021-10-26 17:24:37.497409254 +0200
@@ -0,0 +1,38 @@
+int *qux (int *);
+
+void
+foo (void)
+{
+  int a[1024];
+  int *p;
+  short *q;
+  __PTRDIFF_TYPE__ r;
+  #pragma omp parallel for collapse(2)
+  for (p = &a[0]; p < &a[512]; p++)
+    for (q = (short *) p + 64; q < (short *) p + 128; q++)	/* { dg-error "outer iteration variable 'p' used in initializer expression has type other than 'short int ?\\\*'" } */
+      ;
+  #pragma omp parallel for collapse(2)
+  for (p = &a[0]; p < &a[512]; p++)
+    for (r = &a[32] - p; r < 32; r++)				/* { dg-error "initializer expression refers to iteration variable 'p'" } */
+      ;
+  #pragma omp parallel for collapse(2)
+  for (r = 0; r < 64; r++)
+    for (p = &a[0] + r; p < &a[32] + 3 * r; p++)		/* { dg-error "initializer expression refers to iteration variable 'r'" } */
+      ;
+}
+
+void
+bar (void)
+{
+  int a[1024];
+  int *p, *q, *r;
+  #pragma omp parallel for collapse(2)
+  for (p = &a[0]; p < &a[512]; p++)
+    for (q = p + (&a[16] - qux (p)); q < &a[32]; q++)		/* { dg-error "initializer expression refers to iteration variable 'p'" } */
+      ;
+  #pragma omp parallel for collapse(3)
+  for (p = &a[0]; p < &a[512]; p++)
+    for (q = &a[0]; q < &a[512]; q++)
+      for (r = p; r < q + 32; r++)				/* { dg-error "two different outer iteration variables 'p' and 'q' used in a single loop" } */
+	;
+}
--- libgomp/testsuite/libgomp.c/loop-26.c.jj	2021-10-25 18:28:42.335313472 +0200
+++ libgomp/testsuite/libgomp.c/loop-26.c	2021-10-25 17:10:05.027897550 +0200
@@ -0,0 +1,196 @@
+/* { dg-do run } */
+
+extern void abort (void);
+
+signed char v[5][7][9][21][4][42][3];
+int a[84];
+int *volatile zero = &a[42];
+int *volatile two = &a[42 + 2];
+int *volatile three = &a[42 + 3];
+int *volatile five = &a[42 + 5];
+int *volatile seven = &a[42 + 7];
+int *volatile nine = &a[42 + 9];
+int *volatile eleven = &a[42 + 11];
+int *volatile minusone = &a[42 - 1];
+volatile int zeroi = 0, onei = 1, twoi = 2, threei = 3, fivei = 5;
+
+int
+main ()
+{
+  for (int i = 0; i < 5; i++)
+  for (int j = 0; j < 7; j++)
+  for (int k = 0; k < 9; k++)
+  for (int l = j; l < 5 + j; l++)
+  for (int m = 7; m < 11; m++)
+  for (int n = 0; n < l - 2; n++)
+  for (int o = 0; o < 3; o++)
+    v[i][j][k][l][m - 7][n][o] = 1;
+
+  int niters = 0;
+  #pragma omp parallel
+  #pragma omp for collapse(7) reduction(+:niters)
+  for (int i = 0; i < 5; i++)
+  for (int *j = &a[42]; j < &a[42 + 7]; j++)
+  for (int *k = &a[42]; k < &a[42 + 9]; k++)
+  for (int *l = j; l < 5 + j; l++)
+  for (int *m = &a[42 + 7]; m < &a[42 + 11]; m++)
+  for (int *n = &a[42]; n < l - 2; n++)
+  for (int *o = &a[42]; o < &a[42 + 3]; o++)
+    {
+      niters++;
+      if (i < 0 || i >= 5
+	  || j - &a[42] < 0 || j - &a[42] >= 7
+	  || k - &a[42] < 0 || k - &a[42] >= 9
+	  || l - &a[42] < 0 || l >= j + 5
+	  || m - &a[42] < 7 || m - &a[42] >= 11
+	  || n - &a[42] < 0 || n >= l - 2
+	  || o - &a[42] < 0 || o - &a[42] >= 3)
+	abort ();
+      if (v[i][j - &a[42]][k - &a[42]][l - &a[42]][m - &a[42 + 7]][n - &a[42]][o - &a[42]] != 1)
+	abort ();
+      v[i][j - &a[42]][k - &a[42]][l - &a[42]][m - &a[42 + 7]][n - &a[42]][o - &a[42]]++;
+    }
+
+  if (niters != 58860)
+    abort ();
+  int niters2 = 0;
+  #pragma omp parallel
+  #pragma omp for collapse(7) reduction(+:niters2)
+  for (int *i = zero; i < five; i += onei)
+  for (int *j = seven - onei; j >= zero; j -= onei)
+  for (int *k = nine - onei; k >= zero; k += -onei)
+  for (int *l = j + zeroi; l < fivei + j; l += onei)
+  for (int *m = eleven - onei; m >= seven; m -= onei)
+  for (int *n = l - threei; n >= zero; n -= onei)
+  for (int *o = zero; o < three; o += onei)
+    {
+      niters2++;
+      if (i - &a[42] < 0 || i - &a[42] >= 5
+	  || j - &a[42] < 0 || j - &a[42] >= 7
+	  || k - &a[42] < 0 || k - &a[42] >= 9
+	  || l < j || l >= j + 5
+	  || m - &a[42] < 7 || m - &a[42] >= 11
+	  || n - &a[42] < 0 || n >= l - 2
+	  || o - &a[42] < 0 || o - &a[42] >= 3)
+	abort ();
+      if (v[i - &a[42]][j - &a[42]][k - &a[42]][l - &a[42]][m - &a[42 + 7]][n - &a[42]][o - &a[42]] != 2)
+	abort ();
+      v[i - &a[42]][j - &a[42]][k - &a[42]][l - &a[42]][m - &a[42 + 7]][n - &a[42]][o - &a[42]]++;
+    }
+
+  if (niters2 != 58860)
+    abort ();
+
+  for (int i = 0; i < 5; i++)
+  for (int j = 0; j < 7; j++)
+  for (int k = 0; k < 9; k++)
+  for (int l = j; l < 5 + j; l++)
+  for (int m = 7; m < 11; m++)
+  for (int n = 0; n < l - 2; n++)
+  for (int o = 0; o < 3; o++)
+    if (v[i][j][k][l][m - 7][n][o] != 3)
+      abort ();
+
+  int niters3 = 0;
+  #pragma omp parallel
+  #pragma omp for collapse(5) reduction(+:niters3)
+  for (int *i = &a[42 + 4]; i >= &a[42 + 0]; i--)
+  for (int *j = &a[42 + 6]; j >= &a[42 + 0]; --j)
+  for (int *l = j + 4; l >= j; l--)
+  for (int *n = l - 3; n >= &a[42]; --n)
+  for (int *o = &a[42 + 2]; o >= &a[42 + 0]; o--)
+    {
+      niters3++;
+      if (i - &a[42] < 0 || i - &a[42] >= 5
+	  || j - &a[42] < 0 || j - &a[42] >= 7
+	  || l < j || l >= j + 5
+	  || n - &a[42] < 0 || n >= l - 2
+	  || o - &a[42] < 0 || o - &a[42] >= 3)
+	abort ();
+      if (v[i - &a[42]][j - &a[42]][0][l - &a[42]][0][n - &a[42]][o - &a[42]] != 3)
+	abort ();
+      v[i - &a[42]][j - &a[42]][0][l - &a[42]][0][n - &a[42]][o - &a[42]]++;
+    }
+
+  if (niters3 != 1635)
+    abort ();
+
+  int niters4 = 0;
+  #pragma omp parallel
+  #pragma omp for collapse(5) reduction(+:niters4)
+  for (int *i = zero; i < five; i += onei)
+  for (int *j = zero; j <= seven - onei; j += onei)
+  for (int *l = zeroi + j; l < j + fivei; l += onei)
+  for (int *n = zero; n <= l - threei; n += onei)
+  for (int o = zeroi; o < threei; o += onei)
+    {
+      niters4++;
+      if (i - &a[42] < 0 || i - &a[42] >= 5
+	  || j - &a[42] < 0 || j - &a[42] >= 7
+	  || l < j || l >= j + 5
+	  || n - &a[42] < 0 || n >= l - 2
+	  || o < 0 || o >= 3)
+	abort ();
+      if (v[i - &a[42]][j - &a[42]][0][l - &a[42]][0][n - &a[42]][o] != 4)
+	abort ();
+      v[i - &a[42]][j - &a[42]][0][l - &a[42]][0][n - &a[42]][o]++;
+    }
+
+  if (niters4 != 1635)
+    abort ();
+
+  for (int i = 0; i < 5; i++)
+  for (int j = 0; j < 7; j++)
+  for (int l = j; l < j + 5; l++)
+  for (int n = 0; n < l - 2; n++)
+  for (int o = 0; o < 3; o++)
+    if (v[i][j][0][l][0][n][o] != 5)
+      abort ();
+
+  int niters5 = 0;
+  #pragma omp parallel
+  #pragma omp for collapse(3) reduction(+:niters5)
+  for (int *j = &a[42 + 6]; j >= &a[42]; --j)
+  for (int *l = j + 0; l <= j + 4; l++)
+  for (int *n = l - 3; n > &a[42 - 1]; --n)
+    {
+      niters5++;
+      if (j - &a[42] < 0 || j - &a[42] >= 7
+	  || l < j || l >= j + 5
+	  || n < &a[42] || n >= l - 2)
+	abort ();
+      if (v[0][j - &a[42]][0][l - &a[42]][0][n - &a[42]][0] != 5)
+	abort ();
+      v[0][j - &a[42]][0][l - &a[42]][0][n - &a[42]][0]++;
+    }
+
+  if (niters5 != 109)
+    abort ();
+
+  int niters6 = 0;
+  #pragma omp parallel
+  #pragma omp for collapse(3) reduction(+:niters6)
+  for (int *j = seven - onei; j > minusone; j -= onei)
+  for (int *l = j + threei + onei; l >= j; l += -onei)
+  for (int *n = l - threei; n > minusone; n -= onei)
+    {
+      niters6++;
+      if (j - &a[42] < 0 || j - &a[42] >= 7
+	  || l < j || l >= j + 5
+	  || n < &a[42] || n >= l - 2)
+	abort ();
+      if (v[0][j - &a[42]][0][l - &a[42]][0][n - &a[42]][0] != 6)
+	abort ();
+      v[0][j - &a[42]][0][l - &a[42]][0][n - &a[42]][0]++;
+    }
+
+  if (niters6 != 109)
+    abort ();
+
+  for (int j = 0; j < 7; j++)
+  for (int l = j; l < j + 5; l++)
+  for (int n = 0; n < l - 2; n++)
+    if (v[0][j][0][l][0][n][0] != 7)
+      abort ();
+  return 0;
+}
--- libgomp/testsuite/libgomp.c/loop-27.c.jj	2021-10-25 18:28:42.335313472 +0200
+++ libgomp/testsuite/libgomp.c/loop-27.c	2021-10-26 12:56:50.522017340 +0200
@@ -0,0 +1,180 @@
+/* { dg-do run } */
+
+extern void abort (void);
+
+int x;
+short *i, *j;
+int ii, jj;
+short *volatile a;
+short *volatile b;
+volatile int c, e, f, g;
+short *volatile d;
+int k[11][20];
+short v[84];
+
+int
+main ()
+{
+  int niters;
+  for (ii = 1; ii <= 10; ii++)
+    for (jj = 1; jj <= ii + 5; jj++)
+      k[ii][jj] = 1;
+  a = &v[42 + 1]; b = &v[42 + 11]; c = 1; d = &v[42 + 1]; e = 6; f = 1;
+  niters = 0; i = &v[0]; j = &v[0]; x = -100;
+  #pragma omp parallel for collapse(2) lastprivate (i, j, x) reduction(+:niters)
+  for (i = &v[42 + 1]; i <= &v[42 + 10]; i++)
+    for (j = &v[42 + 1]; j <= i + 5; j++)
+      {
+	if (i < &v[42 + 1] || i > &v[42 + 10] || j < &v[42 + 1] || j > i + 5 || k[i - &v[42]][j - &v[42]] != 1)
+	  abort ();
+	k[i - &v[42]][j - &v[42]]++;
+	x = (i - &v[42]) * 1024 + ((j - &v[42]) & 1023);
+	niters++;
+      }
+  if (i != &v[42 + 11] || j != &v[42 + 16] || x != 10255 || niters != 105)
+    abort ();
+  niters = 0; i = &v[0]; j = &v[0]; x = -100;
+  #pragma omp parallel for collapse(2) lastprivate (i, j, x) reduction(+:niters)
+  for (i = a; i < b; i += c)
+    for (j = d; j < e + i; j += f)
+      {
+	if (i < &v[42 + 1] || i > &v[42 + 10] || j < &v[42 + 1] || j > i + 5 || k[i - &v[42]][j - &v[42]] != 2)
+	  abort ();
+	k[i - &v[42]][j - &v[42]]++;
+	x = (i - &v[42]) * 1024 + ((j - &v[42]) & 1023);
+	niters++;
+      }
+  if (i != &v[42 + 11] || j != &v[42 + 16] || x != 10255 || niters != 105)
+    abort ();
+  for (ii = 1; ii <= 10; ii++)
+    for (jj = 1; jj <= ii + 5; jj++)
+      if (k[ii][jj] == 3)
+	k[ii][jj] = 0;
+      else
+	abort ();
+  for (ii = 0; ii < 11; ii++)
+    for (jj = 0; jj < 20; jj++)
+      if (k[ii][jj] != 0)
+	abort ();
+  for (ii = 0; ii < 10; ii++)
+    for (jj = 0; jj < ii; jj++)
+      k[ii][jj] = 1;
+  a = &v[42]; b = &v[42 + 10]; c = 1; d = &v[42]; e = 0; f = 1;
+  niters = 0; i = &v[0]; j = &v[0]; x = -100;
+  #pragma omp parallel for collapse(2) lastprivate (i, j, x) reduction(+:niters)
+  for (i = &v[42]; i < &v[42 + 10]; i++)
+    for (j = &v[42]; j < i; j++)
+      {
+	if (i < &v[42] || i >= &v[42 + 10] || j < &v[42] || j >= i || k[i - &v[42]][j - &v[42]] != 1)
+	  abort ();
+	k[i - &v[42]][j - &v[42]]++;
+	x = (i - &v[42]) * 1024 + ((j - &v[42]) & 1023);
+	niters++;
+      }
+  if (i != &v[42 + 10] || j != &v[42 + 9] || x != 9224 || niters != 45)
+    abort ();
+  niters = 0; i = &v[0]; j = &v[0]; x = -100;
+  #pragma omp parallel for collapse(2) lastprivate (i, j, x) reduction(+:niters)
+  for (i = a; i < b; i += c)
+    for (j = d; j < i - e; j += f)
+      {
+	if (i < &v[42] || i >= &v[42 + 10] || j < &v[42] || j >= i || k[i - &v[42]][j - &v[42]] != 2)
+	  abort ();
+	k[i - &v[42]][j - &v[42]]++;
+	x = (i - &v[42]) * 1024 + ((j - &v[42]) & 1023);
+	niters++;
+      }
+  if (i != &v[42 + 10] || j != &v[42 + 9] || x != 9224 || niters != 45)
+    abort ();
+  for (ii = 0; ii < 10; ii++)
+    for (jj = 0; jj < ii; jj++)
+      if (k[ii][jj] == 3)
+	k[ii][jj] = 0;
+      else
+	abort ();
+  for (ii = 0; ii < 11; ii++)
+    for (jj = 0; jj < 20; jj++)
+      if (k[ii][jj] != 0)
+	abort ();
+  for (ii = 0; ii < 10; ii++)
+    for (jj = ii + 1; jj < ii + 4; jj++)
+      k[ii][jj] = 1;
+  a = &v[42]; b = &v[42 + 10]; c = 1; e = 1; f = 1; g = -4;
+  niters = 0; i = &v[0]; j = &v[0]; x = -100;
+  #pragma omp parallel for collapse(2) lastprivate (i, j, x) reduction(+:niters)
+  for (i = &v[42]; i < &v[42 + 10]; i++)
+    for (j = i + 1; j < i + 4; j++)
+      {
+	if (i < &v[42] || i >= &v[42 + 10] || j < i + 1 || j >= i + 4 || k[i - &v[42]][j - &v[42]] != 1)
+	  abort ();
+	k[i - &v[42]][j - &v[42]]++;
+	x = (i - &v[42]) * 1024 + ((j - &v[42]) & 1023);
+	niters++;
+      }
+  if (i != &v[42 + 10] || j != &v[42 + 13] || x != 9228 || niters != 30)
+    abort ();
+  niters = 0; i = &v[0]; j = &v[0]; x = -100;
+  #pragma omp parallel for collapse(2) lastprivate (i, j, x) reduction(+:niters)
+  for (i = a; i < b; i += c)
+    for (j = i + e; j < i - g; j += f)
+      {
+	if (i < &v[42] || i >= &v[42 + 10] || j < i + 1 || j >= i + 4 || k[i - &v[42]][j - &v[42]] != 2)
+	  abort ();
+	k[i - &v[42]][j - &v[42]]++;
+	x = (i - &v[42]) * 1024 + ((j - &v[42]) & 1023);
+	niters++;
+      }
+  if (i != &v[42 + 10] || j != &v[42 + 13] || x != 9228 || niters != 30)
+    abort ();
+  for (ii = 0; ii < 10; ii++)
+    for (jj = ii + 1; jj < ii + 4; jj++)
+      if (k[ii][jj] == 3)
+	k[ii][jj] = 0;
+      else
+	abort ();
+  for (ii = 0; ii < 11; ii++)
+    for (jj = 0; jj < 20; jj++)
+      if (k[ii][jj] != 0)
+	abort ();
+  for (ii = 1; ii < 10; ii += 2)
+    for (jj = 1; jj < ii + 1; jj++)
+      k[ii][jj] = 1;
+  a = &v[42 + 1]; b = &v[42 + 10]; c = 2; d = &v[42 + 1]; e = 1; f = 1;
+  niters = 0; i = &v[0]; j = &v[0]; x = -100;
+  #pragma omp parallel for collapse(2) lastprivate (i, j, x) reduction(+:niters)
+  for (i = &v[42 + 1]; i < &v[42 + 10]; i += 2)
+    for (j = &v[42 + 1]; j < i + 1; j++)
+      {
+	if (i < &v[42 + 1] || i >= &v[42 + 10] || j < &v[42 + 1] || j >= i + 1 || k[i - &v[42]][j - &v[42]] != 1)
+	  abort ();
+	k[i - &v[42]][j - &v[42]]++;
+	x = (i - &v[42]) * 1024 + ((j - &v[42]) & 1023);
+	niters++;
+      }
+  if (i != &v[42 + 11] || j != &v[42 + 10] || x != 9225 || niters != 25)
+    abort ();
+  niters = 0; i = &v[0]; j = &v[0]; x = -100;
+  #pragma omp parallel for collapse(2) lastprivate (i, j, x) reduction(+:niters)
+  for (i = a; i < b; i += c)
+    for (j = d; j < i + e; j += f)
+      {
+	if (i < &v[42 + 1] || i >= &v[42 + 10] || j < &v[42 + 1] || j >= i + 1 || k[i - &v[42]][j - &v[42]] != 2)
+	  abort ();
+	k[i - &v[42]][j - &v[42]]++;
+	x = (i - &v[42]) * 1024 + ((j - &v[42]) & 1023);
+	niters++;
+      }
+  if (i != &v[42 + 11] || j != &v[42 + 10] || x != 9225 || niters != 25)
+    abort ();
+  for (ii = 1; ii < 10; ii += 2)
+    for (jj = 1; jj < ii + 1; jj++)
+      if (k[ii][jj] == 3)
+	k[ii][jj] = 0;
+      else
+	abort ();
+  for (ii = 0; ii < 11; ii++)
+    for (jj = 0; jj < 20; jj++)
+      if (k[ii][jj] != 0)
+	abort ();
+  return 0;
+}
