This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add builtin memmove and bcopy
> From: Jakub Jelinek <jakub at redhat dot com>
>
> On Sun, Apr 27, 2003 at 10:01:37PM -0400, Kaveh R. Ghazi wrote:
> > > + /* If src is a string constant and strings are not writable,
> > > + we can use normal memcpy. */
> > > + if (!flag_writable_strings && c_getstr (src))
> > > + return expand_builtin_memcpy (arglist, target, mode, 0);
> >
> > More generally, can't we call memcpy if we're sure src and dest don't
> > alias each other?
>
> Probably yes, I'm just not sure what all programs will suddenly mysteriously
> break and whether the gains justify it.
> Certainly it can be done in a different patch.
Yes it should be a different patch. I'm just proposing/asking.
I would disagree that anything could break. By first detecting that
src and dst cannot alias each other (e.g. dst was obtained through a
fresh malloc,) we prove that the overlap scenario cannot happen and
therefore using memcpy is safe. I tried to do this once but it was
beyond my abilities.
Perhaps a simpler generalization would be to detect that src is
located in a readonly section. Then any static const data used as src
could be optimized, not just strings. Is there a straighforward way
to detect this?
--Kaveh
--
Kaveh R. Ghazi ghazi at caip dot rutgers dot edu