This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] use movstr in strcat
- From: Adrian Straetling <straetling at de dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: uweigand at de dot ibm dot com, krebbel1 at de dot ibm dot com
- Date: Thu, 25 Aug 2005 13:12:18 +0200
- Subject: [patch] use movstr in strcat
Hi,
defining the movstr pattern for S/390 I only found it used for strcpy.
Here is a patch to use movstr for strcat, too.
In the case of strcat(foo,"string") expand_movstr is called if expand_builtin_mempcopy fails to copy the string by pieces. In the other case of strcat(foo,bar)
expand_movstr is the only choice.
Bootstrapped and tested on s390x, s390, i686.
FAIL: libmudflap.cth/pass39-frag.c (-O3) (rerun 1x) ...
pops up preferably with the patch installed, but once without it, too.
I found no connection to my patch, so I think that's unrelated.
Ok for mainline?
Bye,
Adrian
2005-08-24 Adrian Straetling <straetling@de.ibm.com>
* builtins.c: (expand_builtin_strcat): Add support for
expand_movstr.
Index: gcc/builtins.c
===================================================================
*** gcc/builtins.c.orig 2005-08-24 09:34:50.823160285 +0200
--- gcc/builtins.c 2005-08-24 09:39:23.233160285 +0200
*************** expand_builtin_strcat (tree arglist, tre
*** 3877,3886 ****
--- 3877,3913 ----
dst, not the result of mempcpy. */
if (expand_builtin_mempcpy (arglist, type, /*target=*/0, mode, /*endp=*/0))
return expand_expr (dst, target, mode, EXPAND_NORMAL);
+
+ /* Try to expand a movstr pattern. If this was successful return
+ the original dst, not the result of movstr. */
+ else if (expand_movstr (newdst, src, target, /*endp=*/0))
+ return expand_expr (dst, target, mode, EXPAND_NORMAL);
else
return 0;
}
}
+ else if (HAVE_movstr && !optimize_size)
+ {
+ tree newdst,
+ strlen_fn = implicit_built_in_decls[BUILT_IN_STRLEN];
+
+ /* We're going to use dst more than once. */
+ dst = builtin_save_expr (dst);
+
+ /* Create strlen (dst). */
+ newdst = build_function_call_expr (strlen_fn,
+ build_tree_list (NULL_TREE, dst));
+ /* Create (dst + (cast) strlen (dst)). */
+ newdst = fold_convert (TREE_TYPE (dst), newdst);
+ newdst = fold_build2 (PLUS_EXPR, TREE_TYPE (dst), dst, newdst);
+
+ /* Try to expand a movstr pattern. If this was successful return
+ the original dst, not the result of movstr. */
+ if (expand_movstr (newdst, src, target, /*endp=*/0))
+ return expand_expr (dst, target, mode, EXPAND_NORMAL);
+ else
+ return 0;
+ }
return 0;
}