https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100077
Bug ID: 100077
Summary: x86: by-value floating point array in struct - xmm
regs spilling to stack
Product: gcc
Version: 10.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: michaeljclark at mac dot com
Target Milestone: ---
Hi,
compiling a vec3 cross product using struct by-value on msvc,
clang and gcc. gcc is going through memory on the stack.
operands are by-value so I can't use restrict. same with -O2 and -Os.
i vaguely remember seeing this a couple of times but i searched
to see if i had reported it and couldn't find a duplicate report.
link with the 3 compilers here: https://godbolt.org/z/YWWfYxbM3
MSVC: /O2 /fp:fast /arch:AVX2
Clang: -Os -mavx -x c
GCC: -Os -mavx -x c
--- BEGIN EXAMPLE ---
struct vec3a { float v[3]; };
typedef struct vec3a vec3a;
vec3a vec3f_cross_0(vec3a v1, vec3a v2)
{
vec3a dest = {
v1.v[1]*v2.v[2]-v1.v[2]*v2.v[1],
v1.v[2]*v2.v[0]-v1.v[0]*v2.v[2],
v1.v[0]*v2.v[1]-v1.v[1]*v2.v[0]
};
return dest;
}
struct vec3f { float x, y, z; };
typedef struct vec3f vec3f;
vec3f vec3f_cross_1(vec3f v1, vec3f v2)
{
vec3f dest = {
v1.y*v2.z-v1.z*v2.y,
v1.z*v2.x-v1.x*v2.z,
v1.x*v2.y-v1.y*v2.x
};
return dest;
}
void vec3f_cross_2(float dest[3], float v1[3], float v2[3])
{
dest[0]=v1[1]*v2[2]-v1[2]*v2[1];
dest[1]=v1[2]*v2[0]-v1[0]*v2[2];
dest[2]=v1[0]*v2[1]-v1[1]*v2[0];
}
--- END EXAMPLE ---