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]

Re: PING^2 for PR c/10735, PR c++/16882, PR rtl-optimization/17860[3.4]


I don't like this patch much at all.  In particular, you disallow conversions
of floating-point vectors to or from anything useful at all.  Which pretty
much sucks.  Indeed, it confuses me that x86 <xmmintrin.h> works at all with
this change.

IIRC, xmmintrin.h uses only a floating point vector type, even for integers (I was surprised as well).


Ok changing it to a warning, like this?

Paolo
2004-09-24  Paolo Bonzini  <bonzini@gnu.org>

	PR c/10735

	* convert.c (convert_to_integer): Diagnose conversions of
	non-integer vectors to scalar integers.
	(convert_to_vector): Diagnose conversions between integer and
	non-integer vectors of different size, and fail for unimplemented
	conversions between vectors with different element type

2004-09-24  Paolo Bonzini  <bonzini@gnu.org>

	PR c/10735

	* gcc.dg/simd-2.c: Add dg-error mark on a wrong cast.
	* gcc.dg/simd-3.c: New.

Index: convert.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/convert.c,v
retrieving revision 1.54
diff -u -r1.54 convert.c
--- convert.c	22 Sep 2004 18:02:03 -0000	1.54
+++ convert.c	28 Oct 2004 07:34:50 -0000
@@ -655,6 +655,12 @@
 				    TREE_TYPE (TREE_TYPE (expr)), expr)));
 
     case VECTOR_TYPE:
+      if (TREE_CODE (TREE_TYPE (expr)) == VECTOR_TYPE
+	  && TREE_CODE (TREE_TYPE (TREE_TYPE (expr))) != INTEGER_TYPE)
+	{
+	  error ("can't convert a non-integer vector to a scalar integer");
+	  return error_mark_node;
+	}
       if (!tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (expr))))
 	{
 	  error ("can't convert between vector values of different size");
@@ -729,8 +735,33 @@
 {
   switch (TREE_CODE (TREE_TYPE (expr)))
     {
-    case INTEGER_TYPE:
	     case VECTOR_TYPE:
+      if ((TREE_CODE (TREE_TYPE (TREE_TYPE (expr))) == INTEGER_TYPE
+	   && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE
+           && tree_int_cst_equal (TYPE_SIZE (type),
+				  TYPE_SIZE (TREE_TYPE (expr))))
+	  || lang_hooks.types_compatible_p (type, TREE_TYPE (expr)))
+        return build1 (NOP_EXPR, type, expr);
+
+      else if (TYPE_VECTOR_SUBPARTS (type)
+	       != TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)))
+	error ("can't convert between vector values of different size");
+
+      else
+	{
+	  warning ("conversion between vectors with different element type");
+	  warning ("using a bit-for-bit move, future versions may change this");
+	  return build1 (NOP_EXPR, type, expr);
+	}
+
+      return error_mark_node;
+
+    case INTEGER_TYPE:
+      if (TREE_CODE (TREE_TYPE (type)) != INTEGER_TYPE)
+	{
+	  error ("can't convert an integer to a non-integer vector");
+	  return error_mark_node;
+	}
       if (!tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (expr))))
 	{
 	  error ("can't convert between vector values of different size");
Index: testsuite/gcc.dg/simd-2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/simd-2.c,v
retrieving revision 1.1
diff -u -r1.1 simd-2.c
--- testsuite/gcc.dg/simd-2.c	9 Jul 2004 23:20:36 -0000	1.1
+++ testsuite/gcc.dg/simd-2.c	28 Oct 2004 07:34:59 -0000
@@ -26,8 +26,8 @@
   b = c; /* { dg-error "incompatible types in assignment" } */
   d = a; /* { dg-error "incompatible types in assignment" } */
 
-  /* Casting between SIMDs of the same size.  */
-  e = (typeof (e)) a;
+  /* Casting between floating-point SIMDs of the same size.  */
+  e = (typeof (e)) a;  /* { dg-error "can't convert between vector values of different size" } */
 
   /* Assignment between scalar and SIMD of different size.  */
   foo = a; /* { dg-error "incompatible types in assignment" } */
Index: testsuite/gcc.dg/simd-3.c
===================================================================
RCS file: testsuite/gcc.dg/simd-3.c
diff -N testsuite/gcc.dg/simd-3.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/simd-3.c	28 Oct 2004 07:34:59 -0000
@@ -0,0 +1,85 @@
+/* test error messages on conversions between vectors */
+
+typedef float v2sf_t __attribute__ ((vector_size (2 * sizeof (float))));
+typedef float v4sf_t __attribute__ ((vector_size (4 * sizeof (float))));
+typedef int v4si_t __attribute__ ((vector_size (4 * sizeof (int))));
+
+typedef char v4qi_t __attribute__ ((vector_size (4)));
+typedef short v4hi_t __attribute__ ((vector_size (8)));
+
+typedef int long_long __attribute__ ((mode (DI)));
+
+v2sf_t v2sf;
+v4sf_t v4sf;
+v4si_t v4si;
+v4qi_t v4qi;
+v4hi_t v4hi;
+short s;
+int i;
+long_long ll;
+
+/* keep these separate so we check that we do not ICE on RTL lowering.
+   ICEs in emit_move_insn are very common for incorrect vector code.  */
+void ok1 (void)
+{
+  v4qi = (v4qi_t) i;
+  i = (int) v4qi;
+  s = (int) v4qi;
+  ll = (int) v4qi;
+
+  v4hi = (v4hi_t) ll;
+  i = (long_long) v4hi;
+  s = (long_long) v4hi;
+  ll = (long_long) v4hi;
+}
+
+/* these do a bit-for-bit copy currently, but it may change.  */
+void ok2 (void)
+{
+  v4qi = (v4qi_t) v4si;   /* { dg-bogus "conversion between" "may change" { xfail *-*-* } } */
+/* { dg-bogus "may change" "may change" { xfail *-*-* } 39 } */
+  v4si = (v4si_t) v4qi;   /* { dg-bogus "conversion between" "may change" { xfail *-*-* } } */
+/* { dg-bogus "may change" "may change" { xfail *-*-* } 41 } */
+}
+
+void ok3 (void)
+{
+  v4sf = (v4sf_t) v4si;   /* { dg-bogus "conversion between" "may change" { xfail *-*-* } } */
+/* { dg-bogus "may change" "may change" { xfail *-*-* } 47 } */
+  v4si = (v4si_t) v4sf;   /* { dg-bogus "conversion between" "may change" { xfail *-*-* } } */
+/* { dg-bogus "may change" "may change" { xfail *-*-* } 49 } */
+}
+
+void bad (void)
+{
+  /* these simply need a cast.  */
+  v4qi = i;         /* { dg-error "incompatible types" } */
+  i = v4qi;         /* { dg-error "incompatible types" } */
+  v4qi = v4si;      /* { dg-error "incompatible types" } */
+  v4si = v4qi;      /* { dg-error "incompatible types" } */
+  v4sf = v4si;      /* { dg-error "incompatible types" } */
+  v4si = v4sf;      /* { dg-error "incompatible types" } */
+
+  /* these try to convert integer scalars to floating-point vectors.  */
+  v2sf = (v2sf_t) i;   /* { dg-error "integer to a non-integer vector" } */
+  v4sf = (v4sf_t) i;   /* { dg-error "integer to a non-integer vector" } */
+
+  /* these try to convert floating-point vectors to integer scalars.
+     the third is interesting because the size of the types is the same  */
+  s = (short) v2sf;      /* { dg-error "non-integer vector to a scalar" } */
+  i = (int) v2sf;        /* { dg-error "non-integer vector to a scalar" } */
+  ll = (long_long) v2sf; /* { dg-error "non-integer vector to a scalar" } */
+  s = (short) v4sf;      /* { dg-error "non-integer vector to a scalar" } */
+  i = (int) v4sf;        /* { dg-error "non-integer vector to a scalar" } */
+  ll = (long_long) v4sf; /* { dg-error "non-integer vector to a scalar" } */
+
+  /* these try to convert between integer vectors and scalars of different
+     size  */
+  v4si = (v4si_t) i;      /* { dg-error "vector values of different size" } */
+  s = (short) v4si;       /* { dg-error "vector values of different size" } */
+  i = (int) v4si;         /* { dg-error "vector values of different size" } */
+  ll = (long_long) v4si;  /* { dg-error "vector values of different size" } */
+
+  s = (short) v4qi;       /* { dg-error "vector values of different size" } */
+  ll = (long_long) v4qi;  /* { dg-error "vector values of different size" } */
+}

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