Backports to 9.2
diff mbox series

Message ID 20190714083200.GJ2125@tucnak
State New
Headers show
Series
  • Backports to 9.2
Related show

Commit Message

Jakub Jelinek July 14, 2019, 8:32 a.m. UTC
Hi!

I've backported 3 patches from trunk to gcc-9-branch, bootstrapped/regtested
them on x86_64-linux and i686-linux, committed to gcc-9-branch.

	Jakub
2019-07-14  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2019-07-04  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/90756
	* explow.c (promote_ssa_mode): Always use TYPE_MODE, don't bypass it
	for VECTOR_TYPE_P.

	* gcc.dg/pr90756.c: New test.
2019-07-14  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2019-07-04  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/78884
	* gimplify.c (struct gimplify_omp_ctx): Add add_safelen1 member.
	(gimplify_bind_expr): If seeing TREE_ADDRESSABLE VLA inside of simd
	loop body, set ctx->add_safelen1 instead of making it GOVD_PRIVATE.
	(gimplify_adjust_omp_clauses): Add safelen (1) clause if
	ctx->add_safelen1 is set.

	* gcc.dg/gomp/pr78884.c: New test.

--- gcc/gimplify.c	(revision 273095)
+++ gcc/gimplify.c	(revision 273096)
@@ -210,6 +210,7 @@ struct gimplify_omp_ctx
   bool combined_loop;
   bool distribute;
   bool target_firstprivatize_array_bases;
+  bool add_safelen1;
   int defaultmap[4];
 };
 
@@ -1319,12 +1320,17 @@ gimplify_bind_expr (tree *expr_p, gimple
 		  || splay_tree_lookup (ctx->variables,
 					(splay_tree_key) t) == NULL))
 	    {
+	      int flag = GOVD_LOCAL;
 	      if (ctx->region_type == ORT_SIMD
 		  && TREE_ADDRESSABLE (t)
 		  && !TREE_STATIC (t))
-		omp_add_variable (ctx, t, GOVD_PRIVATE | GOVD_SEEN);
-	      else
-		omp_add_variable (ctx, t, GOVD_LOCAL | GOVD_SEEN);
+		{
+		  if (TREE_CODE (DECL_SIZE_UNIT (t)) != INTEGER_CST)
+		    ctx->add_safelen1 = true;
+		  else
+		    flag = GOVD_PRIVATE;
+		}
+	      omp_add_variable (ctx, t, flag | GOVD_SEEN);
 	    }
 
 	  DECL_SEEN_IN_BIND_EXPR_P (t) = 1;
@@ -9684,6 +9690,19 @@ gimplify_adjust_omp_clauses (gimple_seq
 			   omp_find_stores_op, &wi);
 	}
     }
+
+  if (ctx->add_safelen1)
+    {
+      /* If there are VLAs in the body of simd loop, prevent
+	 vectorization.  */
+      gcc_assert (ctx->region_type == ORT_SIMD);
+      c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_SAFELEN);
+      OMP_CLAUSE_SAFELEN_EXPR (c) = integer_one_node;
+      OMP_CLAUSE_CHAIN (c) = *list_p;
+      *list_p = c;
+      list_p = &OMP_CLAUSE_CHAIN (c);
+    }
+
   while ((c = *list_p) != NULL)
     {
       splay_tree_node n;
--- gcc/testsuite/gcc.dg/gomp/pr78884.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/gomp/pr78884.c	(revision 273096)
@@ -0,0 +1,16 @@
+/* PR middle-end/78884 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fopenmp" } */
+
+void bar (int *);
+
+void
+foo (int n)
+{
+#pragma omp simd
+  for (int i = 0; i < 1024; i++)
+    {
+      int vla[n];
+      bar (vla);
+    }
+}
2019-07-14  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2019-07-13  Jakub Jelinek  <jakub@redhat.com>

	PR c/91149
	* c-omp.c (c_omp_split_clauses): Fix a pasto in
	OMP_CLAUSE_REDUCTION_TASK handling.

	* c-c++-common/gomp/reduction-task-3.c: New test.

--- gcc/c-family/c-omp.c	(revision 273464)
+++ gcc/c-family/c-omp.c	(revision 273465)
@@ -1667,7 +1667,7 @@ c_omp_split_clauses (location_t loc, enu
 		}
 	      else if (code != OMP_SECTIONS
 		       && (mask & (OMP_CLAUSE_MASK_1
-				   << PRAGMA_OMP_CLAUSE_SCHEDULE)) == 0
+				   << PRAGMA_OMP_CLAUSE_NUM_THREADS)) == 0
 		       && (mask & (OMP_CLAUSE_MASK_1
 				   << PRAGMA_OMP_CLAUSE_SCHEDULE)) == 0)
 		{
--- gcc/testsuite/c-c++-common/gomp/reduction-task-3.c	(nonexistent)
+++ gcc/testsuite/c-c++-common/gomp/reduction-task-3.c	(revision 273465)
@@ -0,0 +1,12 @@
+/* PR c/91149 */
+
+int r;
+
+void
+foo (void)
+{
+  #pragma omp parallel reduction(task, +: r)
+  r++;
+  #pragma omp target parallel reduction(task, +: r)
+  r++;
+}

Patch
diff mbox series

--- gcc/explow.c	(revision 273035)
+++ gcc/explow.c	(revision 273036)
@@ -892,16 +892,7 @@  promote_ssa_mode (const_tree name, int *
 
   tree type = TREE_TYPE (name);
   int unsignedp = TYPE_UNSIGNED (type);
-  machine_mode mode = TYPE_MODE (type);
-
-  /* Bypass TYPE_MODE when it maps vector modes to BLKmode.  */
-  if (mode == BLKmode)
-    {
-      gcc_assert (VECTOR_TYPE_P (type));
-      mode = type->type_common.mode;
-    }
-
-  machine_mode pmode = promote_mode (type, mode, &unsignedp);
+  machine_mode pmode = promote_mode (type, TYPE_MODE (type), &unsignedp);
   if (punsignedp)
     *punsignedp = unsignedp;
 
--- gcc/testsuite/gcc.dg/pr90756.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/pr90756.c	(revision 273036)
@@ -0,0 +1,26 @@ 
+/* PR rtl-optimization/90756 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wno-psabi" } */
+/* { dg-additional-options "-mno-sse" { target ia32 } } */
+
+typedef float B __attribute__((vector_size(4 * sizeof (float))));
+typedef unsigned long long C __attribute__((vector_size(4 * sizeof (long long))));
+typedef short D __attribute__((vector_size(4 * sizeof (short))));
+B z;
+void foo (C);
+C bar (D);
+B baz ();
+D qux (B);
+
+void
+quux (int x)
+{
+  B n = z, b = z;
+  while (1)
+    switch (x)
+      {
+      case 0: n = baz (); /* FALLTHRU */
+      case 1: { B o = n; n = b; b = o; } /* FALLTHRU */
+      case 2: { D u = qux (b); C v = bar (u); foo (v); }
+      }
+}