aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/builtins.c21
2 files changed, 27 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f0e5b25..685c2f6 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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 ||.
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 6d755a1..e4e3f9c 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;
}