https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127745
Bug ID: 127745
Summary: SRA scalarizes aggregate copy using x87 flds/fsts
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: rguenth at gcc dot gnu.org
Target Milestone: ---
Target: i?86-*-*
struct F { float a, b, c, d; };
void copy (struct F *dst, const struct F *src)
{
struct F s = *src;
*dst = s;
}
is altering the values of src->{a,b,c,d}. On x86 with -O2 -mno-sse -m32 you
get
copy:
.LFB0:
.cfi_startproc
movl 8(%esp), %edx
movl 4(%esp), %eax
flds (%edx)
flds 4(%edx)
flds 8(%edx)
flds 12(%edx)
fxch %st(3)
fstps (%eax)
fxch %st(1)
fstps 4(%eax)
fstps 8(%eax)
fstps 12(%eax)
ret
while w/ -fno-tree-sra we correctly use integer registers for the transfer:
movl 32(%esp), %edx
movl 28(%esp), %eax
movl (%edx), %esi
movl 4(%edx), %ebx
movl 8(%edx), %ecx
movl 12(%edx), %edx
movl %esi, (%eax)
movl %ebx, 4(%eax)
movl %ecx, 8(%eax)
movl %edx, 12(%eax)
There is partial mitigation against this issue with calls of
types_risk_mangled_binary_repr_p in tree-sra.cc but it seems incomplete.