From: Richard Guenther Date: Mon, 30 Aug 2010 13:46:31 +0000 (+0000) Subject: re PR middle-end/21602 (builtin memmove could be memcpy if src and dst don't alias) X-Git-Tag: releases/gcc-4.6.0~4781 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e481a2ff50e75ef3b8efb6644b41a260f813d3a;p=thirdparty%2Fgcc.git re PR middle-end/21602 (builtin memmove could be memcpy if src and dst don't alias) 2010-08-30 Richard Guenther PR tree-optimization/21602 * builtins.c (fold_builtin_memory_op): Fold memmove to memcpy using points-to information. From-SVN: r163646 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f0e5b25a6e6c..685c2f6918a9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2010-08-30 Richard Guenther + + PR tree-optimization/21602 + * builtins.c (fold_builtin_memory_op): Fold memmove to memcpy + using points-to information. + 2010-08-30 H.J. Lu * config/linux.h (TARGET_HAS_SINCOS): Replace | with ||. diff --git a/gcc/builtins.c b/gcc/builtins.c index 6d755a1b5c7f..e4e3f9cac8b8 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -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; }