https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82014
Bug ID: 82014
Summary: worse code emitted for a valid memove than for
undefined memcpy
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
GCC folds overlapping (and thus strictly undefined) calls to memcpy to
efficient series of assignments with the same semantics as memmove but it fails
to do the same fow the well-defined calls to memmove. This could encourage
users who notice to rely on undefined code.
$ cat a.c && gcc -O2 -S -Wall -Wextra -Wpedantic -o/dev/stdout a.c
char a[8] = "12345678";
void f (void)
{
__builtin_memcpy (a, a + 3, sizeof a - 3); // strictly undefined
}
void g (void)
{
__builtin_memmove (a, a + 3, sizeof a - 3); // well-defined
}
.file "a.c"
.text
.p2align 4,,15
.globl f
.type f, @function
f:
.LFB0:
.cfi_startproc
movl a+3(%rip), %eax
movl %eax, a(%rip)
movzbl a+7(%rip), %eax
movb %al, a+4(%rip)
ret
.cfi_endproc
.LFE0:
.size f, .-f
.p2align 4,,15
.globl g
.type g, @function
g:
.LFB1:
.cfi_startproc
movl $5, %edx
movl $a+3, %esi
movl $a, %edi
jmp memmove
.cfi_endproc
.LFE1:
.size g, .-g
.globl a
.data
.align 8
.type a, @object
.size a, 8
a:
.ascii "12345678"
.ident "GCC: (GNU) 8.0.0 20170824 (experimental)"
.section .note.GNU-stack,"",@progbits