This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch]: delete redundant code in expand_builtin_strncpy


Same as previous cleanups, kills tree mucking in the expander and
calls the folder instead.  Zaps another 20 lines of code.

Bootstrapped on sparc-sun-solaris2.9 (minus libgcj due to PR17265), no
regressions.

Ok for mainline?

		Thanks,
		--Kaveh


2004-10-07  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* builtins.c (expand_builtin_strncpy): Delete duplicate code.
	Accept an `exp' instead of an `arglist'.

diff -rcp orig/egcc-CVS20041006/gcc/builtins.c egcc-CVS20041006/gcc/builtins.c
*** orig/egcc-CVS20041006/gcc/builtins.c	Wed Oct  6 09:35:47 2004
--- egcc-CVS20041006/gcc/builtins.c	Thu Oct  7 11:12:22 2004
*************** builtin_strncpy_read_str (void *data, HO
*** 3010,3044 ****
     if we failed the caller should emit a normal call.  */
  
  static rtx
! expand_builtin_strncpy (tree arglist, rtx target, enum machine_mode mode)
  {
!   if (!validate_arglist (arglist,
! 			 POINTER_TYPE, POINTER_TYPE, INTEGER_TYPE, VOID_TYPE))
!     return 0;
!   else
      {
        tree slen = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)), 1);
        tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
!       tree fn;
! 
!       /* We must be passed a constant len parameter.  */
!       if (TREE_CODE (len) != INTEGER_CST)
! 	return 0;
! 
!       /* If the len parameter is zero, return the dst parameter.  */
!       if (integer_zerop (len))
! 	{
! 	  /* Evaluate and ignore the src argument in case it has
! 	     side-effects.  */
! 	  expand_expr (TREE_VALUE (TREE_CHAIN (arglist)), const0_rtx,
! 		       VOIDmode, EXPAND_NORMAL);
! 	  /* Return the dst parameter.  */
! 	  return expand_expr (TREE_VALUE (arglist), target, mode,
! 			      EXPAND_NORMAL);
! 	}
  
!       /* Now, we must be passed a constant src ptr parameter.  */
!       if (slen == 0 || TREE_CODE (slen) != INTEGER_CST)
  	return 0;
  
        slen = size_binop (PLUS_EXPR, slen, ssize_int (1));
--- 3010,3030 ----
     if we failed the caller should emit a normal call.  */
  
  static rtx
! expand_builtin_strncpy (tree exp, rtx target, enum machine_mode mode)
  {
!   tree arglist = TREE_OPERAND (exp, 1);
!   if (validate_arglist (arglist,
! 			POINTER_TYPE, POINTER_TYPE, INTEGER_TYPE, VOID_TYPE))
      {
        tree slen = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)), 1);
        tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
!       tree result = fold_builtin_strncpy (exp, slen);
!       
!       if (result)
! 	return expand_expr (result, target, mode, EXPAND_NORMAL);
  
!       /* We must be passed a constant len and src parameter.  */
!       if (!host_integerp (len, 1) || !slen || !host_integerp (slen, 1))
  	return 0;
  
        slen = size_binop (PLUS_EXPR, slen, ssize_int (1));
*************** expand_builtin_strncpy (tree arglist, rt
*** 3068,3081 ****
  	  dest_mem = convert_memory_address (ptr_mode, dest_mem);
  	  return dest_mem;
  	}
- 
-       /* OK transform into builtin memcpy.  */
-       fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
-       if (!fn)
- 	return 0;
-       return expand_expr (build_function_call_expr (fn, arglist),
- 			  target, mode, EXPAND_NORMAL);
      }
  }
  
  /* Callback routine for store_by_pieces.  Read GET_MODE_BITSIZE (MODE)
--- 3054,3061 ----
  	  dest_mem = convert_memory_address (ptr_mode, dest_mem);
  	  return dest_mem;
  	}
      }
+   return 0;
  }
  
  /* Callback routine for store_by_pieces.  Read GET_MODE_BITSIZE (MODE)
*************** expand_builtin (tree exp, rtx target, rt
*** 5391,5397 ****
        break;
  
      case BUILT_IN_STRNCPY:
!       target = expand_builtin_strncpy (arglist, target, mode);
        if (target)
  	return target;
        break;
--- 5371,5377 ----
        break;
  
      case BUILT_IN_STRNCPY:
!       target = expand_builtin_strncpy (exp, target, mode);
        if (target)
  	return target;
        break;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]