This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed] Allow non-integer/pointer references in linear(ref()) (PR c++/71257)


Hi!

Something I've discovered only when looking at the standard again while
working on Fortran changes - linear clause with ref modifier should
in C++ accept all arguments with reference type, not just those where
it references integer or pointer (that is the restriction of all the other
kinds).

The simd-clone-6.cc testcase ICEd also due to missing
vectorizable_simd_clone_call hunks, fixed that as well.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk
and 6.2.

2016-05-24  Jakub Jelinek  <jakub@redhat.com>

	PR c++/71257
	* tree-vect-stmts.c (vectorizable_simd_clone_call): Handle
	SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP like
	SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP.  Add
	SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP and
	SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP cases explicitly.

	* semantics.c (finish_omp_clauses) <case OMP_CLAUSE_LINEAR>:
	For OMP_CLAUSE_LINEAR_REF don't require type to be
	integral or pointer.

	* g++.dg/vect/simd-clone-6.cc: New test.
	* g++.dg/gomp/declare-simd-6.C: New test.

--- gcc/tree-vect-stmts.c.jj	2016-05-20 09:05:08.000000000 +0200
+++ gcc/tree-vect-stmts.c	2016-05-24 12:49:49.257147827 +0200
@@ -3012,8 +3012,10 @@ vectorizable_simd_clone_call (gimple *st
     {
       STMT_VINFO_SIMD_CLONE_INFO (stmt_info).safe_push (bestn->decl);
       for (i = 0; i < nargs; i++)
-	if (bestn->simdclone->args[i].arg_type
-	    == SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP)
+	if ((bestn->simdclone->args[i].arg_type
+	     == SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP)
+	    || (bestn->simdclone->args[i].arg_type
+		== SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP))
 	  {
 	    STMT_VINFO_SIMD_CLONE_INFO (stmt_info).safe_grow_cleared (i * 3
 									+ 1);
@@ -3148,6 +3150,7 @@ vectorizable_simd_clone_call (gimple *st
 	      vargs.safe_push (op);
 	      break;
 	    case SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP:
+	    case SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP:
 	      if (j == 0)
 		{
 		  gimple_seq stmts;
@@ -3211,6 +3214,8 @@ vectorizable_simd_clone_call (gimple *st
 		  vargs.safe_push (new_temp);
 		}
 	      break;
+	    case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP:
+	    case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP:
 	    case SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP:
 	    case SIMD_CLONE_ARG_TYPE_LINEAR_REF_VARIABLE_STEP:
 	    case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_VARIABLE_STEP:
--- gcc/cp/semantics.c.jj	2016-05-13 22:23:03.000000000 +0200
+++ gcc/cp/semantics.c	2016-05-24 11:04:15.160634109 +0200
@@ -5881,7 +5881,7 @@ finish_omp_clauses (tree clauses, enum c
 		      break;
 		    }
 		}
-	      else
+	      else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
 		{
 		  if (!INTEGRAL_TYPE_P (type)
 		      && TREE_CODE (type) != POINTER_TYPE)
--- gcc/testsuite/g++.dg/vect/simd-clone-6.cc.jj	2016-05-24 12:58:46.321054736 +0200
+++ gcc/testsuite/g++.dg/vect/simd-clone-6.cc	2016-05-24 13:33:16.261767563 +0200
@@ -0,0 +1,43 @@
+// PR c++/71257
+// { dg-require-effective-target vect_simd_clones }
+// { dg-additional-options "-fopenmp-simd -fno-inline" }
+// { dg-additional-options "-mavx" { target avx_runtime } }
+
+#include "../../gcc.dg/vect/tree-vect.h"
+
+#define N 1024
+struct S { int a; };
+int c[N], e[N], f[N];
+S d[N];
+
+#pragma omp declare simd linear(ref(b, c) : 1)
+int
+foo (int a, S &b, int &c)
+{
+  return a + b.a + c;
+}
+
+void
+do_main ()
+{
+  int i;
+  for (i = 0; i < N; i++)
+    {
+      c[i] = i;
+      d[i].a = 2 * i;
+      f[i] = 3 * i;
+    }
+  #pragma omp simd
+  for (i = 0; i < N; i++)
+    e[i] = foo (c[i], d[i], f[i]);
+  for (i = 0; i < N; i++)
+    if (e[i] != 6 * i)
+      __builtin_abort ();
+}
+
+int
+main ()
+{
+  check_vect ();
+  return 0;
+}
--- gcc/testsuite/g++.dg/gomp/declare-simd-6.C.jj	2016-05-24 11:21:39.591853711 +0200
+++ gcc/testsuite/g++.dg/gomp/declare-simd-6.C	2016-05-24 13:33:43.016416143 +0200
@@ -0,0 +1,37 @@
+// PR c++/71257
+// { dg-do compile }
+// { dg-options "-fopenmp-simd" }
+
+struct S { int a; };
+#pragma omp declare simd linear(val(a):2)
+int f1 (int &a);
+#pragma omp declare simd linear(uval(a):2)
+unsigned short f2 (unsigned short &a);
+#pragma omp declare simd linear(ref(a):1)
+int f3 (long long int &a);
+#pragma omp declare simd linear(a:1)
+int f4 (int &a);
+#pragma omp declare simd linear(val(a))
+int f5 (int a);
+#pragma omp declare simd linear(uval(a):2)		// { dg-error "modifier applied to non-reference variable" }
+int f6 (unsigned short a);
+#pragma omp declare simd linear(ref(a):1)		// { dg-error "modifier applied to non-reference variable" }
+int f7 (unsigned long int a);
+#pragma omp declare simd linear(a:1)
+int f8 (int a);
+#pragma omp declare simd linear(val(a):2)		// { dg-error "applied to non-integral non-pointer variable" }
+int f9 (S &a);
+#pragma omp declare simd linear(uval(a):2)		// { dg-error "applied to non-integral non-pointer variable" }
+int f10 (S &a);
+#pragma omp declare simd linear(ref(a):1)		// { dg-bogus "applied to non-integral non-pointer variable" }
+int f11 (S &a);
+#pragma omp declare simd linear(a:1)			// { dg-error "applied to non-integral non-pointer variable" }
+int f12 (S &a);
+#pragma omp declare simd linear(val(a))			// { dg-error "applied to non-integral non-pointer variable" }
+int f13 (S a);
+#pragma omp declare simd linear(uval(a):2)		// { dg-error "modifier applied to non-reference variable" }
+int f14 (S a);
+#pragma omp declare simd linear(ref(a):1)		// { dg-error "modifier applied to non-reference variable" }
+int f15 (S a);
+#pragma omp declare simd linear(a:1)			// { dg-error "applied to non-integral non-pointer variable" }
+int f16 (S a);

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]