https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125132
Bug ID: 125132
Summary: builtin-memmove-12.c fails with --enable-default-pie
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: xry111 at gcc dot gnu.org
Target Milestone: ---
The expected assembly of the test is:
movdqu a+20(%rip), %xmm5
movdqu a+36(%rip), %xmm4
movdqu a+52(%rip), %xmm3
movdqu a+68(%rip), %xmm2
movdqu a+84(%rip), %xmm1
movdqu a+100(%rip), %xmm0
movups %xmm5, a+24(%rip)
movq a+116(%rip), %rax
movdqu a+4(%rip), %xmm6
movups %xmm4, a+40(%rip)
movl %edi, a+4(%rip)
movq %rax, a+120(%rip)
movups %xmm6, a+8(%rip)
movups %xmm3, a+56(%rip)
movups %xmm2, a+72(%rip)
movups %xmm1, a+88(%rip)
movups %xmm0, a+104(%rip)
ret
But with -fpie, the address of "a + 4" is materialized first:
leaq 4+a(%rip), %rax
movdqu 4+a(%rip), %xmm6
movdqu 16(%rax), %xmm5
movdqu 32(%rax), %xmm4
movdqu 48(%rax), %xmm3
movdqu 64(%rax), %xmm2
movdqu 80(%rax), %xmm1
movdqu 96(%rax), %xmm0
... ...
However the expected output is actually fine as PIE code. Thus it seems a
missed-optimization with -fpie.