https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70055

--- Comment #8 from H.J. Lu <hjl.tools at gmail dot com> ---
Inlining mempcpy uses a callee-saved register:


hjl@gnu-6 tmp]$ cat m.c 
extern char *src, *dst;

char *
foo (unsigned long i)
{
  return __builtin_mempcpy (dst, src, i);
}

char *
bar (unsigned long i)
{
  return __builtin_memcpy (dst, src, i) + i;
}
[hjl@gnu-6 tmp]$ gcc -S -O2 m.c
[hjl@gnu-6 tmp]$ cat m.s
        .file   "m.c"
        .section        .text.unlikely,"ax",@progbits
.LCOLDB0:
        .text
.LHOTB0:
        .p2align 4,,15
        .globl  foo
        .type   foo, @function
foo:
.LFB0:
        .cfi_startproc
        movq    %rdi, %rdx
        movq    src(%rip), %rsi
        movq    dst(%rip), %rdi
        jmp     mempcpy
        .cfi_endproc
.LFE0:
        .size   foo, .-foo
        .section        .text.unlikely
.LCOLDE0:
        .text
.LHOTE0:
        .section        .text.unlikely
.LCOLDB1:
        .text
.LHOTB1:
        .p2align 4,,15
        .globl  bar
        .type   bar, @function
bar:
.LFB1:
        .cfi_startproc
        pushq   %rbx
        .cfi_def_cfa_offset 16
        .cfi_offset 3, -16
        movq    %rdi, %rdx
        movq    %rdi, %rbx
        movq    src(%rip), %rsi
        movq    dst(%rip), %rdi
        call    memcpy
        addq    %rbx, %rax
        popq    %rbx
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc
.LFE1:
        .size   bar, .-bar
        .section        .text.unlikely
.LCOLDE1:
        .text
.LHOTE1:
        .ident  "GCC: (GNU) 5.3.1 20160212 (Red Hat 5.3.1-4)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-6 tmp]$ 

Not inlining mempcpy is preferred.

Reply via email to