This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR21602
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 30 Aug 2010 15:44:37 +0200 (CEST)
- Subject: [PATCH] Fix PR21602
This adds memmove to memcpy folding using points-to information.
The testcase in the PR isn't fixed because context insensitive
PTA cannot handle it.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
Richard.
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.
Index: gcc/builtins.c
===================================================================
*** gcc/builtins.c (revision 163637)
--- gcc/builtins.c (working copy)
*************** fold_builtin_memory_op (location_t loc,
*** 8467,8472 ****
--- 8467,8493 ----
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;
}