https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119294
Bug ID: 119294 Summary: Strange (buggy?) codegen when passing cleared vector as argument Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gcc at haasn dot dev Target Milestone: --- ### Description For some reason, in this program, GCC extraneously writes the vector argument, normally passed in xmm0, to the stack - sometimes without even incrementing the stack pointer. It's furthermore strange that `set_indirect()` compiles to different code than `set()`, even though the former (should) just directly inline the latter. You can see that the problem goes away when the value to write is a compile time constant, rather than taken from a register argument. ### Code typedef char vec_t __attribute__((vector_size(16))); void func(vec_t x); void set(vec_t x, const char val) { for (int i = 0; i < 16; i++) x[i] = val; func(x); } void set_indirect(vec_t x, const char val) { set(x, val); } void setFF(vec_t x) { set(x, 0xFF); } void set123(vec_t x) { set(x, 123); } void set0(vec_t x) { set(x, 0); } ### Expected Output set: vmovd xmm0, edi vpbroadcastb xmm0, xmm0 jmp func@PLT set_indirect: vmovd xmm0, edi vpbroadcastb xmm0, xmm0 jmp func@PLT setFF: vpcmpeqd xmm0, xmm0, xmm0 jmp func@PLT .LCPI3_1: .zero 4,123 set123: vbroadcastss xmm0, dword ptr [rip + .LCPI3_1] jmp func@PLT set0: vxorps xmm0, xmm0, xmm0 jmp func@PLT ### Actual Output set: vmovd xmm0, edi sub rsp, 24 vpbroadcastb xmm0, xmm0 vmovdqa XMMWORD PTR [rsp], xmm0 call func add rsp, 24 ret set_indirect: vmovd xmm0, edi vpbroadcastb xmm0, xmm0 vmovdqa XMMWORD PTR [rsp-24], xmm0 jmp func setFF: vpcmpeqd xmm0, xmm0, xmm0 jmp func set123: mov eax, 2071690107 vmovd xmm0, eax vpbroadcastd xmm0, xmm0 jmp func set0: vpxor xmm0, xmm0, xmm0 jmp func ### See Also: https://godbolt.org/z/1hrjKqf8Y