re PR middle-end/21602 (builtin memmove could be memcpy if src and dst don't alias)

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.

From-SVN: r163646
This commit is contained in:
Richard Guenther 2010-08-30 13:46:31 +00:00 committed by Richard Biener
parent 3727f43413
commit 2e481a2ff5
2 changed files with 27 additions and 0 deletions

View File

@ -1,3 +1,9 @@
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.
2010-08-30 H.J. Lu <hongjiu.lu@intel.com>
* config/linux.h (TARGET_HAS_SINCOS): Replace | with ||.

View File

@ -8467,6 +8467,27 @@ fold_builtin_memory_op (location_t loc, tree dest, tree src,
return NULL_TREE;
return build_call_expr_loc (loc, fn, 3, dest, src, len);
}
/* If the destination and source do not alias optimize into
memcpy as well. */
if ((is_gimple_min_invariant (dest)
|| TREE_CODE (dest) == SSA_NAME)
&& (is_gimple_min_invariant (src)
|| TREE_CODE (src) == SSA_NAME))
{
ao_ref destr, srcr;
ao_ref_init_from_ptr_and_size (&destr, dest, len);
ao_ref_init_from_ptr_and_size (&srcr, src, len);
if (!refs_may_alias_p_1 (&destr, &srcr, false))
{
tree fn;
fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
if (!fn)
return NULL_TREE;
return build_call_expr_loc (loc, fn, 3, dest, src, len);
}
}
return NULL_TREE;
}