What is the type of vector signed + vector unsigned?
Richard Biener
richard.guenther@gmail.com
Tue Dec 29 18:44:24 GMT 2020
On December 29, 2020 6:42:30 PM GMT+01:00, Marc Glisse <marc.glisse@inria.fr> wrote:
>On Tue, 29 Dec 2020, Richard Sandiford via Gcc wrote:
>
>> Any thoughts on what f should return in the following testcase, given
>the
>> usual GNU behaviour of treating signed >> as arithmetic shift right?
>>
>> typedef int vs4 __attribute__((vector_size(16)));
>> typedef unsigned int vu4 __attribute__((vector_size(16)));
>> int
>> f (void)
>> {
>> vs4 x = { -1, -1, -1, -1 };
>> vu4 y = { 0, 0, 0, 0 };
>> return ((x + y) >> 1)[0];
>> }
>>
>> The C frontend takes the type of x+y from the first operand, so x+y
>> is signed and f returns -1.
>
>Symmetry is an important property of addition in C/C++.
>
>> The C++ frontend applies similar rules to x+y as it would to scalars,
>> with unsigned T having a higher rank than signed T, so x+y is
>unsigned
>> and f returns 0x7fffffff.
>
>That looks like the most natural choice.
>
>> FWIW, Clang treats x+y as signed, so f returns -1 for both C and C++.
>
>I think clang follows gcc and uses the type of the first operand.
The desired behavior is the one that OpenCL specifies. If it is implementation defined we should document behavior. I agree symmetry is nice but eventually the current C behavior is what OpenCL specifies.
Richard.
More information about the Gcc
mailing list