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: broken arithmetic operations on vectors (c and c++)


> Why not just the moral equivalent of:
> 
>   same_type_p (langhooks.signed_type(t1), langhooks.signed_type(t2))

Oooo.  Nice.

Ok, I used the equality operator, since that's how it seems we compare
types throughout the FEs.

Here is an updated patch which I'm testing.  It's for the C and C++
front ends.  C was borked as well.

In testing I noticed gcc.dg/simd-1b.c had most of the tests
XFAILed.  They now work.  I've re-enabled them.

How does this look?

	* c-common.h (same_type_ignoring_signedness): Protoize.

	* c-common.c (same_type_ignoring_signedness): New.

	* c-typeck.c (build_binary_op): Check compatability of vector
	types.

	* cp/typeck.c (build_binary_op): Same.
	* testsuite/gcc.dg/simd-3.c: New.
	* testsuite/g++.dg/conversion/simd3.C: New.
	* testsuite/gcc.dg/simd-1b.c: Re-enable tests.

Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.294
diff -c -p -r1.294 c-common.h
*** c-common.h	28 May 2005 01:38:07 -0000	1.294
--- c-common.h	13 Jun 2005 19:37:32 -0000
*************** extern tree convert_and_check (tree, tre
*** 657,662 ****
--- 657,663 ----
  extern void overflow_warning (tree);
  extern void unsigned_conversion_warning (tree, tree);
  extern bool c_determine_visibility (tree);
+ extern bool same_type_ignoring_signedness (tree, tree);
  
  #define c_sizeof(T)  c_sizeof_or_alignof_type (T, true, 1)
  #define c_alignof(T) c_sizeof_or_alignof_type (T, false, 1)
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.634
diff -c -p -r1.634 c-common.c
*** c-common.c	6 Jun 2005 19:31:24 -0000	1.634
--- c-common.c	13 Jun 2005 19:37:36 -0000
*************** resolve_overloaded_builtin (tree functio
*** 6030,6033 ****
--- 6030,6041 ----
      }
  }
  
+ /* Return true if two types are the same, if we ignore their sign.  */
+ bool
+ same_type_ignoring_signedness (tree t1, tree t2)
+ {
+   return lang_hooks.types.signed_type (t1)
+     == lang_hooks.types.signed_type (t2);
+ }
+ 
  #include "gt-c-common.h"
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.450
diff -c -p -r1.450 c-typeck.c
*** c-typeck.c	7 Jun 2005 10:10:22 -0000	1.450
--- c-typeck.c	13 Jun 2005 19:37:40 -0000
*************** build_binary_op (enum tree_code code, tr
*** 7490,7495 ****
--- 7490,7510 ----
    if (code0 == ERROR_MARK || code1 == ERROR_MARK)
      return error_mark_node;
  
+   if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE)
+     {
+       if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1)))
+ 	{
+ 	  error ("can't convert between vector values of different size");
+ 	  return error_mark_node;
+ 	}
+       if (!same_type_ignoring_signedness (TREE_TYPE (type0),
+ 					  TREE_TYPE (type1)))
+ 	{
+ 	  error ("can't convert between vector values of different types");
+ 	  return error_mark_node;
+ 	}
+     }
+ 
    objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
  
    switch (code)
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.634
diff -c -p -r1.634 typeck.c
*** cp/typeck.c	10 Jun 2005 17:35:35 -0000	1.634
--- cp/typeck.c	13 Jun 2005 19:37:42 -0000
*************** build_binary_op (enum tree_code code, tr
*** 3182,3188 ****
        if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE)
  	{
  	  if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1)))
! 	    error ("can't convert between vector values of different size");
  	  arithmetic_types_p = 1;
  	}
      }
--- 3182,3197 ----
        if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE)
  	{
  	  if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1)))
! 	    {
! 	      error ("can't convert between vector values of different size");
! 	      return error_mark_node;
! 	    }
! 	  if (!same_type_ignoring_signedness (TREE_TYPE (type0),
! 					      TREE_TYPE (type1)))
! 	    {
! 	      error ("can't convert between vector values of different types");
! 	      return error_mark_node;
! 	    }
  	  arithmetic_types_p = 1;
  	}
      }
Index: testsuite/gcc.dg/simd-1b.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/simd-1b.c,v
retrieving revision 1.1
diff -c -p -r1.1 simd-1b.c
*** testsuite/gcc.dg/simd-1b.c	9 Jul 2004 23:20:36 -0000	1.1
--- testsuite/gcc.dg/simd-1b.c	13 Jun 2005 19:37:42 -0000
*************** void
*** 14,36 ****
  hanneke ()
  {
    /* Operators on compatible SIMD types.  */
!   a %= b; /* { dg-bogus "invalid operands to binary %" "" { xfail *-*-* } } */
    c &= d;
    a |= b;
    c ^= d;
!   a >>= b; /* { dg-bogus "invalid operands to binary >>" "" { xfail *-*-* } } */
!   c <<= d; /* { dg-bogus "invalid operands to binary <<" "" { xfail *-*-* } } */
    a = +b;
    c = ~d;
  
    /* Operators on incompatible SIMD types.  */
! /*  a = b % c;  { dg*error "can't convert between vector values of different size" } */
!   a = b % c; /* { dg-bogus "invalid operands to binary %" "" { xfail *-*-* } } */
    d = c & b; /* { dg-error "can't convert between vector values of different size" } */
    a = b | c; /* { dg-error "can't convert between vector values of different size" } */
    d = c ^ b; /* { dg-error "can't convert between vector values of different size" } */
! /*  a = b >> c;  { dg*error "can't convert between vector values of different size" } */
!   a = b >> c; /* { dg-bogus "invalid operands to binary >>" "" { xfail *-*-* } } */
! /*  d = c << b;  { dg*error "can't convert between vector values of different size" } */
!   d = c << b; /* { dg-bogus "invalid operands to binary <<" "" { xfail *-*-* } } */
  }
--- 14,36 ----
  hanneke ()
  {
    /* Operators on compatible SIMD types.  */
!   a %= b; /* { dg-error "invalid operands to binary %" } */
    c &= d;
    a |= b;
    c ^= d;
!   a >>= b; /* { dg-error "invalid operands to binary >>" } */
!   c <<= d; /* { dg-error "invalid operands to binary <<" } */
    a = +b;
    c = ~d;
  
    /* Operators on incompatible SIMD types.  */
!   a = b % c; /* { dg-error "can't convert between vector values of different size" } */
!   a = b % c; /* { dg-error "can't convert between vector values of different size" } */
    d = c & b; /* { dg-error "can't convert between vector values of different size" } */
    a = b | c; /* { dg-error "can't convert between vector values of different size" } */
    d = c ^ b; /* { dg-error "can't convert between vector values of different size" } */
!   a = b >> c; /*  { dg-error "can't convert between vector values of different size" } */
!   a = b >> c; /* { dg-error "can't convert between vector values of different size" } */
!   d = c << b; /* { dg-error "can't convert between vector values of different size" } */
!   d = c << b; /* { dg-error "can't convert between vector values of different size" } */
  }
Index: testsuite/g++.dg/conversion/simd3.C
===================================================================
RCS file: testsuite/g++.dg/conversion/simd3.C
diff -N testsuite/g++.dg/conversion/simd3.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/conversion/simd3.C	13 Jun 2005 19:37:42 -0000
***************
*** 0 ****
--- 1,15 ----
+ /* { dg-do compile } */
+ 
+ typedef int myint;
+ 
+ float __attribute__((vector_size(16))) b;
+ int __attribute__((vector_size(16))) d;
+ myint __attribute__((vector_size(16))) d2;
+ unsigned int __attribute__((vector_size(16))) e;
+ 
+ void foo()
+ {
+ 	b + d; /* { dg-error "can't convert between vector values of different types" } */
+ 	d += e;
+ 	d2 += d;
+ }


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