diff mbox

RFA: Consider int and same-size short as equivalent vector components

Message ID 20130826121845.hp0ac9mlhc4ccwsw-nzlynne@webmail.spamcop.net
State New
Headers show

Commit Message

Joern Rennecke Aug. 26, 2013, 4:18 p.m. UTC
avr currently shows the following failure:
FAIL: c-c++-common/vector-scalar.c  -Wc++-compat  (test for excess errors)
Excess errors:
/home/amylaar/atmel/4.8/unisrc-mainline/gcc/testsuite/c-c++-common/vector-scalar
.c:9:34: error: invalid operands to binary | (have '__vector(8) int'  
and 'veci')

The issue is that when we compute the result of an operatiopn of a veci and an
int, we get a __vector(8) int result (int is the same size as short),
yet the typechecking later does not accept the vectors as compatible.
Fixed by relaxing the latter for the case that int and short are the  
same size.

bootstrapped / regtested on i686-pc-linux-gnu.

OK to apply?
2013-07-17  Joern Rennecke  <joern.rennecke@embecosm.com>

	* c-common.c (same_scalar_type_ignoring_signedness): Also
	accept short/int as equivalent if they have the same precision.

Comments

Marc Glisse Aug. 26, 2013, 6:52 p.m. UTC | #1
On Mon, 26 Aug 2013, Joern Rennecke wrote:

> avr currently shows the following failure:
> FAIL: c-c++-common/vector-scalar.c  -Wc++-compat  (test for excess errors)
> Excess errors:
> /home/amylaar/atmel/4.8/unisrc-mainline/gcc/testsuite/c-c++-common/vector-scalar
> .c:9:34: error: invalid operands to binary | (have '__vector(8) int' and 
> 'veci')
>
> The issue is that when we compute the result of an operatiopn of a veci and 
> an int, we get a __vector(8) int result (int is the same size as short),

Maybe we could change that?

> yet the typechecking later does not accept the vectors as compatible.
> Fixed by relaxing the latter for the case that int and short are the same 
> size.

If you do this, maybe rename the function, or at least expand the comment, 
to make it clear that it should only be used for comparison operators with 
vectors?

The issue seems larger than just short/int. On x86, (l<l)<l fails to 
compile for a vector of long, with l<l that has opaque type vector of int, 
that seems wrong.
Joern Rennecke Aug. 26, 2013, 7:17 p.m. UTC | #2
Quoting Marc Glisse <marc.glisse@inria.fr>:

> The issue seems larger than just short/int. On x86, (l<l)<l fails to
> compile for a vector of long, with l<l that has opaque type vector of
> int, that seems wrong.

I don't understand what you mean here.  Could you post the actual code sample?
Marc Glisse Aug. 26, 2013, 7:27 p.m. UTC | #3
On Mon, 26 Aug 2013, Joern Rennecke wrote:

> Quoting Marc Glisse <marc.glisse@inria.fr>:
>
>> The issue seems larger than just short/int. On x86, (l<l)<l fails to
>> compile for a vector of long, with l<l that has opaque type vector of
>> int, that seems wrong.
>
> I don't understand what you mean here.  Could you post the actual code 
> sample?

typedef long vl __attribute__((vector_size(16)));

void f(vl l){
   (l<l)<l;
}

it compiles fine on x86_64 but not on x86.
(btw, my sentence was ambiguous, what I find wrong is the failure to 
compile, not the type of l<l)
diff mbox

Patch

Index: c-family/c-common.c
===================================================================
--- c-family/c-common.c	(revision 201992)
+++ c-family/c-common.c	(working copy)
@@ -10700,10 +10700,22 @@  same_scalar_type_ignoring_signedness (tr
 	      && (c2 == INTEGER_TYPE || c2 == REAL_TYPE
 		  || c2 == FIXED_POINT_TYPE));
 
+  t1 = c_common_signed_type (t1);
+  t2 = c_common_signed_type (t2);
   /* Equality works here because c_common_signed_type uses
      TYPE_MAIN_VARIANT.  */
-  return c_common_signed_type (t1)
-    == c_common_signed_type (t2);
+  if (t1 == t2)
+    return true;
+  if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2))
+    return false;
+  /* When short and int are the same size, we promote vectors of short
+     to vectors of int when doing arithmetic with scalars.  Hence,
+     we also have to accept mixing short / int vectors in this case.
+     Example: c-c++-common/vector-scalar.c for target avr.  */
+  if ((t1 == integer_type_node && t2 == short_integer_type_node)
+      || (t2 == integer_type_node && t1 == short_integer_type_node))
+    return true;
+  return false;
 }
 
 /* Check for missing format attributes on function pointers.  LTYPE is