The current builtin memmove optimizes to memcpy if it can prove that the source
pointer is in readonly memory, under the assumption that the destination
pointer must be writable and therefore couldn't overlap. However we could
generalize this such that if we can prove the source and dest don't alias, then
we can do the transformation. E.g. given the following code, we should
optimize the memmove call in both foo() and bar(), however we only do foo() in
mainline.
typedef __SIZE_TYPE__ size_t;
extern void *malloc (size_t);
extern void *memmove (void *, const void *, size_t);
void *foo (void)
{
void *dst = malloc (13);
return memmove (dst, "hello world\n", 13);
}
void *bar (void *src)
{
void *dst = malloc(13);
return memmove (dst, src, 13);
}
--
Summary: builtin memmove could be memcpy is src and dst don't
alias
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P2
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ghazi at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21602