public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96966] New: redundant memcpy not eliminated after pointer subtraction
@ 2020-09-07 23:40 msebor at gcc dot gnu.org
  2020-09-07 23:46 ` [Bug tree-optimization/96966] [8/9/10/11 Regression] " msebor at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-09-07 23:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96966
           Summary: redundant memcpy not eliminated after pointer
                    subtraction
           Product: gcc
           Version: 11.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: ---

The second call to memcpy and mempcpy, respectively, is redundant in each of
the functions below and can be eliminated.  GCC doesn't notice the redundancy
and emits both pairs of copies.  Clang emits just one call to memcpy but it too
fails to eliminate the redundant call to mempcpy.

$ cat z.c && gcc -O2 -S -o /dev/stdout z.c
extern char a[32];

void f (const void *s)
{
  char *p = (char*)__builtin_memcpy (a, s, 16) + 16;
  __builtin_memcpy (p - 16, s, 16);
}


void g (const void *s)
{
  char *p = (char*)__builtin_mempcpy (a, s, 16);
  __builtin_mempcpy (p - 16, s, 16);
}
        .file   "z.c"
        .text
        .p2align 4
        .globl  f
        .type   f, @function
f:
.LFB0:
        .cfi_startproc
        movdqu  (%rdi), %xmm0
        movups  %xmm0, a(%rip)
        movdqu  (%rdi), %xmm1
        movups  %xmm1, a(%rip)
        ret
        .cfi_endproc
.LFE0:
        .size   f, .-f
        .p2align 4
        .globl  g
        .type   g, @function
g:
.LFB3:
        .cfi_startproc
        movdqu  (%rdi), %xmm0
        movups  %xmm0, a(%rip)
        movdqu  (%rdi), %xmm1
        movups  %xmm1, a(%rip)
        ret
        .cfi_endproc
.LFE3:
        .size   g, .-g
        .ident  "GCC: (GNU) 11.0.0 20200902 (experimental)"
        .section        .note.GNU-stack,"",@progbits

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-07-07 10:38 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-07 23:40 [Bug tree-optimization/96966] New: redundant memcpy not eliminated after pointer subtraction msebor at gcc dot gnu.org
2020-09-07 23:46 ` [Bug tree-optimization/96966] [8/9/10/11 Regression] " msebor at gcc dot gnu.org
2020-09-08  7:00 ` rguenth at gcc dot gnu.org
2021-01-14  9:20 ` rguenth at gcc dot gnu.org
2021-02-12  0:40 ` msebor at gcc dot gnu.org
2021-02-18 10:06 ` jakub at gcc dot gnu.org
2021-02-19  9:24 ` rguenth at gcc dot gnu.org
2021-05-14  9:53 ` [Bug tree-optimization/96966] [9/10/11/12 " jakub at gcc dot gnu.org
2021-06-01  8:18 ` rguenth at gcc dot gnu.org
2022-05-27  9:43 ` [Bug tree-optimization/96966] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:41 ` jakub at gcc dot gnu.org
2023-07-07 10:38 ` [Bug tree-optimization/96966] [11/12/13/14 " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).