llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.96k stars 11.94k forks source link

[AARCH64] [ABI] disagreement with GCC on returning 4 element vector of char #78662

Open pinskia opened 9 months ago

pinskia commented 9 months ago

Take:

#define vector __attribute__((vector_size(4) ))

vector unsigned char f(vector unsigned char a)
{
  return a + 4;
}

GCC passes the argument via w0 and returns in w0. While clang/LLVM passes the argument via w0 but returns in v0 which seems wrong.

llvmbot commented 9 months ago

@llvm/issue-subscribers-backend-aarch64

Author: Andrew Pinski (pinskia)

Take: ``` #define vector __attribute__((vector_size(4) )) vector unsigned char f(vector unsigned char a) { return a + 4; } ``` GCC passes the argument via `w0` and returns in `w0`. While clang/LLVM passes the argument via `w0` but returns in `v0` which seems wrong.
pinskia commented 9 months ago

I also find which elements that are used for V2short is just really interesting. That is:

#define vector __attribute__((vector_size(4)))

vector unsigned short f(vector unsigned short* __restrict b, int n)
{
  return *b;
}

Produces:

        ld1     { v0.h }[0], [x0]
        add     x8, x0, #2
        ld1     { v0.h }[2], [x8]

so v0.4h[1] and v0.4h[3] are undefined rather than chosing 0,1 as the element.

davemgreen commented 9 months ago

I hadn't realized there was a way to define these "illegal" vector types in gcc. It looks like the clang frontend is coercing the input value, but doesn't do the same for the return: https://godbolt.org/z/E4q8Taf45