]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/21602 (builtin memmove could be memcpy if src and dst don't alias)
authorRichard Guenther <rguenther@suse.de>
Mon, 30 Aug 2010 13:46:31 +0000 (13:46 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 30 Aug 2010 13:46:31 +0000 (13:46 +0000)
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

gcc/ChangeLog
gcc/builtins.c

index f0e5b25a6e6cdab265b6886229d659e305273a22..685c2f6918a9490b2a9d9cfc467fae93cba1b7d8 100644 (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 ||.
index 6d755a1b5c7fde5653ac591e75b646d6b36a9942..e4e3f9cac8b89f58f729a5ce58d12dcdf684b60f 100644 (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;
        }