public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/98658] New: Loop idiom recognization for memcpy/memmove
@ 2021-01-13 13:59 david.bolvansky at gmail dot com
  2021-01-13 14:04 ` [Bug c/98658] " david.bolvansky at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: david.bolvansky at gmail dot com @ 2021-01-13 13:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98658
           Summary: Loop idiom recognization for memcpy/memmove
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david.bolvansky at gmail dot com
  Target Milestone: ---

void copy(int *__restrict__ d, int * s, __SIZE_TYPE__ sz) {
    __SIZE_TYPE__ i;
    for (i = 0; i < sz; i++) {
        *d++ = *s++;
    }
}

gcc emits call to memcpy.



void copy(int * d, int * s, __SIZE_TYPE__ sz) {
    __SIZE_TYPE__ i;
    for (i = 0; i < sz; i++) {
        *d++ = *s++;
    }
}


gcc could emit memmove, but currently does not:
https://godbolt.org/z/5n1rnh

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

* [Bug c/98658] Loop idiom recognization for memcpy/memmove
  2021-01-13 13:59 [Bug c/98658] New: Loop idiom recognization for memcpy/memmove david.bolvansky at gmail dot com
@ 2021-01-13 14:04 ` david.bolvansky at gmail dot com
  2021-01-13 15:37 ` rguenth at gcc dot gnu.org
  2021-01-13 16:40 ` david.bolvansky at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: david.bolvansky at gmail dot com @ 2021-01-13 14:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Dávid Bolvanský <david.bolvansky at gmail dot com> ---
ICC produces memcpy:
https://godbolt.org/z/oKxxTM

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

* [Bug c/98658] Loop idiom recognization for memcpy/memmove
  2021-01-13 13:59 [Bug c/98658] New: Loop idiom recognization for memcpy/memmove david.bolvansky at gmail dot com
  2021-01-13 14:04 ` [Bug c/98658] " david.bolvansky at gmail dot com
@ 2021-01-13 15:37 ` rguenth at gcc dot gnu.org
  2021-01-13 16:40 ` david.bolvansky at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-01-13 15:37 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
it's because

(gdb) p debug_data_dependence_relation (ddr)
(Data Dep: 
#(Data Ref: 
#  bb: 3 
#  stmt: _1 = *s_19;
#  ref: *s_19;
#  base_object: *s_7(D);
#  Access function 0: {0B, +, 4}_1
#)
#(Data Ref: 
#  bb: 3 
#  stmt: *d_18 = _1;
#  ref: *d_18;
#  base_object: *d_6(D);
#  Access function 0: {0B, +, 4}_1
#)
    (don't know)
)

and we say

  /* Can't do memmove in case of unknown dependence or dependence without
     classical distance vector.  */
  if (DDR_ARE_DEPENDENT (ddr) == chrec_dont_know
      || DDR_NUM_DIST_VECTS (ddr) == 0)
    return;

which is because we need to check the depdenence is not backwards
(*s++ loads an earlier stored value).  I don't see how that is
guaranteed in the 'copy' case and ICC either miscompiles this
or has a runtime check doing the memcpy only conditionally.

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

* [Bug c/98658] Loop idiom recognization for memcpy/memmove
  2021-01-13 13:59 [Bug c/98658] New: Loop idiom recognization for memcpy/memmove david.bolvansky at gmail dot com
  2021-01-13 14:04 ` [Bug c/98658] " david.bolvansky at gmail dot com
  2021-01-13 15:37 ` rguenth at gcc dot gnu.org
@ 2021-01-13 16:40 ` david.bolvansky at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: david.bolvansky at gmail dot com @ 2021-01-13 16:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Dávid Bolvanský <david.bolvansky at gmail dot com> ---
Yes, runtime check.

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

end of thread, other threads:[~2021-01-13 16:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13 13:59 [Bug c/98658] New: Loop idiom recognization for memcpy/memmove david.bolvansky at gmail dot com
2021-01-13 14:04 ` [Bug c/98658] " david.bolvansky at gmail dot com
2021-01-13 15:37 ` rguenth at gcc dot gnu.org
2021-01-13 16:40 ` david.bolvansky at gmail dot com

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).