[patch]: delete redundant code in expand_builtin_strcpy
Kaveh R. Ghazi
ghazi@caip.rutgers.edu
Wed Oct 6 02:58:00 GMT 2004
This patch deletes redundant code in expand_builtin_strcpy.
The fold_builtin_strcpy function does the tree stuff.
Note, the folder expected an `exp' argument, so I propagated that back
out.
Also, there was a discrepancy in that the folder honored
`optimize_size' before converting strcpy to memcpy, whereas the
expander failed to do so. In consolidating the two, I kept the
folder's behavior, but then had to modify one of the testcases do
account for this.
Bootstrapped on sparc-sun-solaris2.9 (minus libgcj cause it doesn't
build), no regressions.
Ok for mainline?
Thanks,
--Kaveh
2004-10-05 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* builtins.c (expand_builtin_strcpy): Delete duplicate code.
Accept an expression instead of an arglist.
(expand_builtin_stpcpy): Accept an expression instead of an
arglist.
testsuite:
* gcc.c-torture/execute/builtins/lib/strcpy.c: Don't abort when
optimizing for size.
diff -rcp orig/egcc-CVS20041005/gcc/builtins.c egcc-CVS20041005/gcc/builtins.c
*** orig/egcc-CVS20041005/gcc/builtins.c Tue Oct 5 13:11:49 2004
--- egcc-CVS20041005/gcc/builtins.c Tue Oct 5 14:15:06 2004
*************** expand_movstr (tree dest, tree src, rtx
*** 2891,2926 ****
convenient). */
static rtx
! expand_builtin_strcpy (tree arglist, rtx target, enum machine_mode mode)
{
! tree fn, len, src, dst;
!
! if (!validate_arglist (arglist, POINTER_TYPE, POINTER_TYPE, VOID_TYPE))
! return 0;
!
! src = TREE_VALUE (TREE_CHAIN (arglist));
! dst = TREE_VALUE (arglist);
!
! /* If SRC and DST are equal (and not volatile), return DST. */
! if (operand_equal_p (src, dst, 0))
! return expand_expr (dst, target, mode, EXPAND_NORMAL);
!
! len = c_strlen (src, 1);
! if (len == 0 || TREE_SIDE_EFFECTS (len))
! return expand_movstr (TREE_VALUE (arglist),
! TREE_VALUE (TREE_CHAIN (arglist)),
! target, /*endp=*/0);
!
! fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
! if (!fn)
! return 0;
! len = size_binop (PLUS_EXPR, len, ssize_int (1));
! arglist = build_tree_list (NULL_TREE, len);
! arglist = tree_cons (NULL_TREE, src, arglist);
! arglist = tree_cons (NULL_TREE, dst, arglist);
! return expand_expr (build_function_call_expr (fn, arglist),
! target, mode, EXPAND_NORMAL);
}
/* Expand a call to the stpcpy builtin, with arguments in ARGLIST.
--- 2891,2910 ----
convenient). */
static rtx
! expand_builtin_strcpy (tree exp, rtx target, enum machine_mode mode)
{
! tree arglist = TREE_OPERAND (exp, 1);
! if (validate_arglist (arglist, POINTER_TYPE, POINTER_TYPE, VOID_TYPE))
! {
! tree result = fold_builtin_strcpy (exp, 0);
! if (result)
! return expand_expr (result, target, mode, EXPAND_NORMAL);
! return expand_movstr (TREE_VALUE (arglist),
! TREE_VALUE (TREE_CHAIN (arglist)),
! target, /*endp=*/0);
! }
! return 0;
}
/* Expand a call to the stpcpy builtin, with arguments in ARGLIST.
*************** expand_builtin_strcpy (tree arglist, rtx
*** 2929,2936 ****
mode MODE if that's convenient). */
static rtx
! expand_builtin_stpcpy (tree arglist, rtx target, enum machine_mode mode)
{
/* If return value is ignored, transform stpcpy into strcpy. */
if (target == const0_rtx)
{
--- 2913,2921 ----
mode MODE if that's convenient). */
static rtx
! expand_builtin_stpcpy (tree exp, rtx target, enum machine_mode mode)
{
+ tree arglist = TREE_OPERAND (exp, 1);
/* If return value is ignored, transform stpcpy into strcpy. */
if (target == const0_rtx)
{
*************** expand_builtin_stpcpy (tree arglist, rtx
*** 2976,2982 ****
if (GET_CODE (len_rtx) == CONST_INT)
{
! ret = expand_builtin_strcpy (arglist, target, mode);
if (ret)
{
--- 2961,2967 ----
if (GET_CODE (len_rtx) == CONST_INT)
{
! ret = expand_builtin_strcpy (exp, target, mode);
if (ret)
{
*************** expand_builtin (tree exp, rtx target, rt
*** 5400,5406 ****
break;
case BUILT_IN_STRCPY:
! target = expand_builtin_strcpy (arglist, target, mode);
if (target)
return target;
break;
--- 5385,5391 ----
break;
case BUILT_IN_STRCPY:
! target = expand_builtin_strcpy (exp, target, mode);
if (target)
return target;
break;
*************** expand_builtin (tree exp, rtx target, rt
*** 5412,5418 ****
break;
case BUILT_IN_STPCPY:
! target = expand_builtin_stpcpy (arglist, target, mode);
if (target)
return target;
break;
--- 5397,5403 ----
break;
case BUILT_IN_STPCPY:
! target = expand_builtin_stpcpy (exp, target, mode);
if (target)
return target;
break;
diff -rup orig/egcc-CVS20041005/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcpy.c egcc-CVS20041005/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcpy.c
--- orig/egcc-CVS20041005/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcpy.c 2004-07-02 22:16:50.000000000 -0400
+++ egcc-CVS20041005/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcpy.c 2004-10-05 18:36:15.510129000 -0400
@@ -4,7 +4,7 @@ char *
strcpy (char *d, const char *s)
{
char *r = d;
-#ifdef __OPTIMIZE__
+#if defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__
if (inside_main)
abort ();
#endif
More information about the Gcc-patches
mailing list