Bug 21602 - builtin memmove could be memcpy if src and dst don't alias
builtin memmove could be memcpy if src and dst don't alias
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: middle-end
4.1.0
: P2 enhancement
: ---
Assigned To: Richard Biener
: alias, missed-optimization
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-05-16 02:08 UTC by Kaveh Ghazi
Modified: 2010-08-30 13:46 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-05-09 16:54:18


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kaveh Ghazi 2005-05-16 02:08:56 UTC
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);
}
Comment 1 Andrew Pinski 2005-05-16 02:19:01 UTC
Confirmed.
Comment 2 Richard Biener 2010-05-09 16:54:18 UTC
Mine.
Comment 3 Richard Biener 2010-08-30 13:46:47 UTC
Fixed.
Comment 4 Richard Biener 2010-08-30 13:46:57 UTC
Subject: Bug 21602

Author: rguenth
Date: Mon Aug 30 13:46:31 2010
New Revision: 163646

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=163646
Log:
2010-08-30  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/21602
	* builtins.c (fold_builtin_memory_op): Fold memmove to memcpy
	using points-to information.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/builtins.c