https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128077
Bug ID: 128077
Summary: wrong code at -O2/-O3 when default-ISA code calls a
static target("avx2") function through vector pointers
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: kyuwoncho18 at gmail dot com
Target Milestone: ---
Target: x86_64-pc-linux-gnu
typedef float v8sf __attribute__((vector_size(32)));
__attribute__((target("avx2"), noinline))
static float f(const v8sf *pa, const v8sf *pb)
{
v8sf s = *pa + *pb;
return s[0] + s[7];
}
int main(void)
{
volatile float k = 1;
v8sf a = {k, 2, 3, 4, 5, 6, 7, 8};
v8sf b = {10, 20, 30, 40, 50, 60, 70, 80};
if (__builtin_cpu_supports("avx2") && f(&a, &b) != 99)
__builtin_abort();
}
godbolt: https://godbolt.org/z/GYvzG6evc
f receives two pointers, so f(&a, &b) is (1 + 10) + (8 + 80) = 99 on any AVX2
machine. With -O0, -O1, -Os, -O2 -fno-ipa-sra or -O2 -mavx2 the program exits
normally; with -O2 or -O3 f returns a different value (95 on godbolt) and the
program aborts. At -O2 GCC also warns "AVX vector argument without AVX enabled
changes the ABI [-Wpsabi]" at the call in main, although that call passes only
pointers.