What is the type of vector signed + vector unsigned?

Marc Glisse marc.glisse@inria.fr
Tue Dec 29 17:42:30 GMT 2020


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.

-- 
Marc Glisse


More information about the Gcc mailing list