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] Rename tree_ssa_useless_type_conversion_1


This patch renames tree_ssa_useless_type_conversion_1 to
type_conversion_needed_p (thereby inverting its sense).

Bootstrapped and tested on x86_64-unknown-linux-gnu.

I'm inclined to put this in now instead of waiting to after the freeze
to minimize conflicts with other patches.  Though I'll wait for some
comments first.

Thanks,
Richard.

2007-06-22  Richard Guenther  <rguenther@suse.de>

	* tree-flow.h (tree_ssa_useless_type_conversion_1): Rename to ...
	(type_conversion_needed_p): ... this.
	* tree-ssa.c (tree_ssa_useless_type_conversion_1): Rename to ...
	(type_conversion_needed_p): ... this.
	* builtins.c (fold_builtin_memory_op): Rename
	tree_ssa_useless_type_conversion_1 to type_conversion_needed_p.
	* tree-cfg.c (verify_expr): Likewise.
	* tree-ssa-address.c (tree_ssa_useless_type_conversion_1): Likewise.
	* tree-ssa-ccp.c (ccp_fold): Likewise.
	* tree-ssa-copy.c (may_propagate_copy): Likewise.
	* tree-ssa-dom.c (eliminate_redundant_computations): Likewise.
	* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Likewise.
	* tree-ssa-loop-niter.c (refine_bounds_using_guard): Likewise.
	* tree-ssa-pre.c (eliminate): Likewise.
	* tree-ssa.c (delete_tree_ssa): Likewise.
	(tree_ssa_useless_type_conversion): Likewise.
	* tree.c (build2_stat): Likewise.

Index: gcc/builtins.c
===================================================================
*** gcc.orig/builtins.c	2007-06-21 16:54:03.000000000 +0200
--- gcc/builtins.c	2007-06-21 16:54:16.000000000 +0200
*************** fold_builtin_memory_op (tree dest, tree 
*** 8584,8590 ****
  
        if (srctype == desttype
  	  || (gimple_in_ssa_p (cfun)
! 	      && tree_ssa_useless_type_conversion_1 (desttype, srctype)))
  	expr = srcvar;
        else if ((INTEGRAL_TYPE_P (TREE_TYPE (srcvar))
  	   || POINTER_TYPE_P (TREE_TYPE (srcvar)))
--- 8584,8590 ----
  
        if (srctype == desttype
  	  || (gimple_in_ssa_p (cfun)
! 	      && !type_conversion_needed_p (desttype, srctype)))
  	expr = srcvar;
        else if ((INTEGRAL_TYPE_P (TREE_TYPE (srcvar))
  	   || POINTER_TYPE_P (TREE_TYPE (srcvar)))
Index: gcc/tree-cfg.c
===================================================================
*** gcc.orig/tree-cfg.c	2007-06-21 16:54:03.000000000 +0200
--- gcc/tree-cfg.c	2007-06-21 16:54:16.000000000 +0200
*************** verify_expr (tree *tp, int *walk_subtree
*** 3287,3294 ****
  	}
        /* Check to make sure the second operand is an integer with type of
  	 sizetype.  */
!       if (!tree_ssa_useless_type_conversion_1 (sizetype,
! 					       TREE_TYPE (TREE_OPERAND (t, 1))))
  	{
  	  error ("invalid operand to pointer plus, second operand is not an "
  		 "integer with type of sizetype.");
--- 3287,3294 ----
  	}
        /* Check to make sure the second operand is an integer with type of
  	 sizetype.  */
!       if (!!type_conversion_needed_p (sizetype,
! 				      TREE_TYPE (TREE_OPERAND (t, 1))))
  	{
  	  error ("invalid operand to pointer plus, second operand is not an "
  		 "integer with type of sizetype.");
Index: gcc/tree-flow.h
===================================================================
*** gcc.orig/tree-flow.h	2007-06-21 16:54:03.000000000 +0200
--- gcc/tree-flow.h	2007-06-21 16:54:16.000000000 +0200
*************** extern void init_tree_ssa (void);
*** 868,874 ****
  extern edge ssa_redirect_edge (edge, basic_block);
  extern void flush_pending_stmts (edge);
  extern bool tree_ssa_useless_type_conversion (tree);
! extern bool tree_ssa_useless_type_conversion_1 (tree, tree);
  extern void verify_ssa (bool);
  extern void delete_tree_ssa (void);
  extern void walk_use_def_chains (tree, walk_use_def_chains_fn, void *, bool);
--- 868,874 ----
  extern edge ssa_redirect_edge (edge, basic_block);
  extern void flush_pending_stmts (edge);
  extern bool tree_ssa_useless_type_conversion (tree);
! extern bool type_conversion_needed_p (tree, tree);
  extern void verify_ssa (bool);
  extern void delete_tree_ssa (void);
  extern void walk_use_def_chains (tree, walk_use_def_chains_fn, void *, bool);
Index: gcc/tree-predcom.c
===================================================================
*** gcc.orig/tree-predcom.c	2007-06-21 16:54:03.000000000 +0200
--- gcc/tree-predcom.c	2007-06-21 16:54:16.000000000 +0200
*************** determine_offset (struct data_reference 
*** 633,639 ****
    /* Check that both the references access the location in the same type.  */
    typea = TREE_TYPE (DR_REF (a));
    typeb = TREE_TYPE (DR_REF (b));
!   if (!tree_ssa_useless_type_conversion_1 (typeb, typea))
      return false;
  
    /* Check whether the base address and the step of both references is the
--- 633,639 ----
    /* Check that both the references access the location in the same type.  */
    typea = TREE_TYPE (DR_REF (a));
    typeb = TREE_TYPE (DR_REF (b));
!   if (type_conversion_needed_p (typeb, typea))
      return false;
  
    /* Check whether the base address and the step of both references is the
Index: gcc/tree-ssa-address.c
===================================================================
*** gcc.orig/tree-ssa-address.c	2007-06-21 16:54:03.000000000 +0200
--- gcc/tree-ssa-address.c	2007-06-21 16:54:16.000000000 +0200
*************** create_mem_ref (block_stmt_iterator *bsi
*** 604,610 ****
        /* Add the symbol to base, eventually forcing it to register.  */
        if (parts.base)
  	{
! 	  gcc_assert (tree_ssa_useless_type_conversion_1
  				(sizetype, TREE_TYPE (parts.base)));
  
  	  if (parts.index)
--- 604,610 ----
        /* Add the symbol to base, eventually forcing it to register.  */
        if (parts.base)
  	{
! 	  gcc_assert (!type_conversion_needed_p
  				(sizetype, TREE_TYPE (parts.base)));
  
  	  if (parts.index)
Index: gcc/tree-ssa-ccp.c
===================================================================
*** gcc.orig/tree-ssa-ccp.c	2007-06-21 16:54:03.000000000 +0200
--- gcc/tree-ssa-ccp.c	2007-06-21 17:10:16.000000000 +0200
*************** ccp_fold (tree stmt)
*** 899,906 ****
  	}
  
        if ((code == NOP_EXPR || code == CONVERT_EXPR)
! 	  && tree_ssa_useless_type_conversion_1 (TREE_TYPE (rhs),
! 		  				 TREE_TYPE (op0)))
  	return op0;
        return fold_unary (code, TREE_TYPE (rhs), op0);
      }
--- 899,905 ----
  	}
  
        if ((code == NOP_EXPR || code == CONVERT_EXPR)
! 	  && !type_conversion_needed_p (TREE_TYPE (rhs), TREE_TYPE (op0)))
  	return op0;
        return fold_unary (code, TREE_TYPE (rhs), op0);
      }
Index: gcc/tree-ssa-copy.c
===================================================================
*** gcc.orig/tree-ssa-copy.c	2007-06-21 16:54:03.000000000 +0200
--- gcc/tree-ssa-copy.c	2007-06-21 17:10:16.000000000 +0200
*************** may_propagate_copy (tree dest, tree orig
*** 82,88 ****
  	                         DECL_UID (SSA_NAME_VAR (dest)))));
    
    /* Do not copy between types for which we *do* need a conversion.  */
!   if (!tree_ssa_useless_type_conversion_1 (type_d, type_o))
      return false;
  
    /* FIXME.  GIMPLE is allowing pointer assignments and comparisons of
--- 82,88 ----
  	                         DECL_UID (SSA_NAME_VAR (dest)))));
    
    /* Do not copy between types for which we *do* need a conversion.  */
!   if (type_conversion_needed_p (type_d, type_o))
      return false;
  
    /* FIXME.  GIMPLE is allowing pointer assignments and comparisons of
Index: gcc/tree-ssa-dom.c
===================================================================
*** gcc.orig/tree-ssa-dom.c	2007-06-21 16:54:03.000000000 +0200
--- gcc/tree-ssa-dom.c	2007-06-21 17:10:16.000000000 +0200
*************** eliminate_redundant_computations (tree s
*** 1515,1522 ****
    if (cached_lhs
        && ((TREE_CODE (cached_lhs) != SSA_NAME
  	   && (modify_expr_p
! 	       || tree_ssa_useless_type_conversion_1 (TREE_TYPE (*expr_p),
! 						      TREE_TYPE (cached_lhs))))
  	  || may_propagate_copy (*expr_p, cached_lhs)))
      {
        if (dump_file && (dump_flags & TDF_DETAILS))
--- 1515,1522 ----
    if (cached_lhs
        && ((TREE_CODE (cached_lhs) != SSA_NAME
  	   && (modify_expr_p
! 	       || !type_conversion_needed_p (TREE_TYPE (*expr_p),
! 					     TREE_TYPE (cached_lhs))))
  	  || may_propagate_copy (*expr_p, cached_lhs)))
      {
        if (dump_file && (dump_flags & TDF_DETAILS))
*************** eliminate_redundant_computations (tree s
*** 1541,1548 ****
  	retval = true;
        
        if (modify_expr_p
! 	  && !tree_ssa_useless_type_conversion_1 (TREE_TYPE (*expr_p),
! 						  TREE_TYPE (cached_lhs)))
  	cached_lhs = fold_convert (TREE_TYPE (*expr_p), cached_lhs);
  
        propagate_tree_value (expr_p, cached_lhs);
--- 1541,1548 ----
  	retval = true;
        
        if (modify_expr_p
! 	  && type_conversion_needed_p (TREE_TYPE (*expr_p),
! 				       TREE_TYPE (cached_lhs)))
  	cached_lhs = fold_convert (TREE_TYPE (*expr_p), cached_lhs);
  
        propagate_tree_value (expr_p, cached_lhs);
Index: gcc/tree-ssa-forwprop.c
===================================================================
*** gcc.orig/tree-ssa-forwprop.c	2007-06-21 16:54:03.000000000 +0200
--- gcc/tree-ssa-forwprop.c	2007-06-21 17:10:16.000000000 +0200
*************** forward_propagate_addr_expr_1 (tree name
*** 601,608 ****
        	    && rhs == name)
  	   || ((TREE_CODE (rhs) == NOP_EXPR
  		|| TREE_CODE (rhs) == CONVERT_EXPR)
! 	       && tree_ssa_useless_type_conversion_1 (TREE_TYPE (rhs),
! 						      TREE_TYPE (def_rhs))))
      return forward_propagate_addr_expr (lhs, def_rhs);
  
    /* Strip away any outer COMPONENT_REF, ARRAY_REF or ADDR_EXPR
--- 601,608 ----
        	    && rhs == name)
  	   || ((TREE_CODE (rhs) == NOP_EXPR
  		|| TREE_CODE (rhs) == CONVERT_EXPR)
! 	       && !type_conversion_needed_p (TREE_TYPE (rhs),
! 					     TREE_TYPE (def_rhs))))
      return forward_propagate_addr_expr (lhs, def_rhs);
  
    /* Strip away any outer COMPONENT_REF, ARRAY_REF or ADDR_EXPR
Index: gcc/tree-ssa-loop-niter.c
===================================================================
*** gcc.orig/tree-ssa-loop-niter.c	2007-06-21 16:54:03.000000000 +0200
--- gcc/tree-ssa-loop-niter.c	2007-06-21 16:54:16.000000000 +0200
*************** refine_bounds_using_guard (tree type, tr
*** 213,219 ****
        STRIP_SIGN_NOPS (c0);
        STRIP_SIGN_NOPS (c1);
        ctype = TREE_TYPE (c0);
!       if (!tree_ssa_useless_type_conversion_1 (ctype, type))
  	return;
  
        break;
--- 213,219 ----
        STRIP_SIGN_NOPS (c0);
        STRIP_SIGN_NOPS (c1);
        ctype = TREE_TYPE (c0);
!       if (type_conversion_needed_p (ctype, type))
  	return;
  
        break;
Index: gcc/tree-ssa-pre.c
===================================================================
*** gcc.orig/tree-ssa-pre.c	2007-06-21 16:54:03.000000000 +0200
--- gcc/tree-ssa-pre.c	2007-06-21 16:54:16.000000000 +0200
*************** eliminate (void)
*** 3588,3595 ****
  		     which may require adding a simple cast, which fold_convert
  		     will do for us.  */
  		  if (TREE_CODE (*rhs_p) != SSA_NAME
! 		      && !tree_ssa_useless_type_conversion_1 (TREE_TYPE (*rhs_p),
! 							      TREE_TYPE (sprime)))
  		    sprime = fold_convert (TREE_TYPE (*rhs_p), sprime);
  
  		  pre_stats.eliminations++;
--- 3588,3595 ----
  		     which may require adding a simple cast, which fold_convert
  		     will do for us.  */
  		  if (TREE_CODE (*rhs_p) != SSA_NAME
! 		      && type_conversion_needed_p (TREE_TYPE (*rhs_p),
! 						   TREE_TYPE (sprime)))
  		    sprime = fold_convert (TREE_TYPE (*rhs_p), sprime);
  
  		  pre_stats.eliminations++;
Index: gcc/tree-ssa.c
===================================================================
*** gcc.orig/tree-ssa.c	2007-06-21 16:54:03.000000000 +0200
--- gcc/tree-ssa.c	2007-06-21 17:11:55.000000000 +0200
*************** delete_tree_ssa (void)
*** 887,910 ****
  }
  
  
! /* Return true if the conversion from INNER_TYPE to OUTER_TYPE is a
!    useless type conversion, otherwise return false.  */
  
  bool
! tree_ssa_useless_type_conversion_1 (tree outer_type, tree inner_type)
  {
    if (inner_type == outer_type)
!     return true;
  
    /* Changes in machine mode are never useless conversions.  */
    if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type))
!     return false;
  
    /* If the inner and outer types are effectively the same, then
       strip the type conversion and enter the equivalence into
       the table.  */
    if (lang_hooks.types_compatible_p (inner_type, outer_type))
!     return true;
  
    /* If both types are pointers and the outer type is a (void *), then
       the conversion is not necessary.  The opposite is not true since
--- 887,910 ----
  }
  
  
! /* Return true if the conversion from INNER_TYPE to OUTER_TYPE is
!    explicitly required, otherwise return false.  */
  
  bool
! type_conversion_needed_p (tree outer_type, tree inner_type)
  {
    if (inner_type == outer_type)
!     return false;
  
    /* Changes in machine mode are never useless conversions.  */
    if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type))
!     return true;
  
    /* If the inner and outer types are effectively the same, then
       strip the type conversion and enter the equivalence into
       the table.  */
    if (lang_hooks.types_compatible_p (inner_type, outer_type))
!     return false;
  
    /* If both types are pointers and the outer type is a (void *), then
       the conversion is not necessary.  The opposite is not true since
*************** tree_ssa_useless_type_conversion_1 (tree
*** 917,923 ****
  	   && TYPE_REF_CAN_ALIAS_ALL (inner_type)
  	      == TYPE_REF_CAN_ALIAS_ALL (outer_type)
  	   && TREE_CODE (TREE_TYPE (outer_type)) == VOID_TYPE)
!     return true;
  
    /* Don't lose casts between pointers to volatile and non-volatile
       qualified types.  Doing so would result in changing the semantics
--- 917,923 ----
  	   && TYPE_REF_CAN_ALIAS_ALL (inner_type)
  	      == TYPE_REF_CAN_ALIAS_ALL (outer_type)
  	   && TREE_CODE (TREE_TYPE (outer_type)) == VOID_TYPE)
!     return false;
  
    /* Don't lose casts between pointers to volatile and non-volatile
       qualified types.  Doing so would result in changing the semantics
*************** tree_ssa_useless_type_conversion_1 (tree
*** 926,932 ****
             && POINTER_TYPE_P (outer_type)
  	   && TYPE_VOLATILE (TREE_TYPE (outer_type))
  	      != TYPE_VOLATILE (TREE_TYPE (inner_type)))
!     return false;
  
    /* Pointers/references are equivalent if their pointed to types
       are effectively the same.  This allows to strip conversions between
--- 926,932 ----
             && POINTER_TYPE_P (outer_type)
  	   && TYPE_VOLATILE (TREE_TYPE (outer_type))
  	      != TYPE_VOLATILE (TREE_TYPE (inner_type)))
!     return true;
  
    /* Pointers/references are equivalent if their pointed to types
       are effectively the same.  This allows to strip conversions between
*************** tree_ssa_useless_type_conversion_1 (tree
*** 937,943 ****
  	      == TYPE_REF_CAN_ALIAS_ALL (outer_type)
             && lang_hooks.types_compatible_p (TREE_TYPE (inner_type),
  					     TREE_TYPE (outer_type)))
!     return true;
  
    /* If both the inner and outer types are integral types, then the
       conversion is not necessary if they have the same mode and
--- 937,943 ----
  	      == TYPE_REF_CAN_ALIAS_ALL (outer_type)
             && lang_hooks.types_compatible_p (TREE_TYPE (inner_type),
  					     TREE_TYPE (outer_type)))
!     return false;
  
    /* If both the inner and outer types are integral types, then the
       conversion is not necessary if they have the same mode and
*************** tree_ssa_useless_type_conversion_1 (tree
*** 958,974 ****
        if (simple_cst_equal (max_inner, TYPE_MAX_VALUE (outer_type))
  	  && simple_cst_equal (min_inner, TYPE_MIN_VALUE (outer_type))
  	  && first_boolean == second_boolean)
! 	return true;
      }
  
    /* Recurse for complex types.  */
    else if (TREE_CODE (inner_type) == COMPLEX_TYPE
  	   && TREE_CODE (outer_type) == COMPLEX_TYPE
! 	   && tree_ssa_useless_type_conversion_1 (TREE_TYPE (outer_type),
  						  TREE_TYPE (inner_type)))
!     return true;
  
!   return false;
  }
  
  /* Return true if EXPR is a useless type conversion, otherwise return
--- 958,974 ----
        if (simple_cst_equal (max_inner, TYPE_MAX_VALUE (outer_type))
  	  && simple_cst_equal (min_inner, TYPE_MIN_VALUE (outer_type))
  	  && first_boolean == second_boolean)
! 	return false;
      }
  
    /* Recurse for complex types.  */
    else if (TREE_CODE (inner_type) == COMPLEX_TYPE
  	   && TREE_CODE (outer_type) == COMPLEX_TYPE
! 	   && !type_conversion_needed_p (TREE_TYPE (outer_type),
  						  TREE_TYPE (inner_type)))
!     return false;
  
!   return true;
  }
  
  /* Return true if EXPR is a useless type conversion, otherwise return
*************** tree_ssa_useless_type_conversion (tree e
*** 987,993 ****
      /* FIXME: Use of GENERIC_TREE_TYPE here is a temporary measure to work
         around known bugs with GIMPLE_MODIFY_STMTs appearing in places
         they shouldn't.  See PR 30391.  */
!     return tree_ssa_useless_type_conversion_1
        (TREE_TYPE (expr),
         GENERIC_TREE_TYPE (TREE_OPERAND (expr, 0)));
  
--- 987,993 ----
      /* FIXME: Use of GENERIC_TREE_TYPE here is a temporary measure to work
         around known bugs with GIMPLE_MODIFY_STMTs appearing in places
         they shouldn't.  See PR 30391.  */
!     return !type_conversion_needed_p
        (TREE_TYPE (expr),
         GENERIC_TREE_TYPE (TREE_OPERAND (expr, 0)));
  
Index: gcc/tree.c
===================================================================
*** gcc.orig/tree.c	2007-06-21 16:54:03.000000000 +0200
--- gcc/tree.c	2007-06-21 17:10:16.000000000 +0200
*************** build2_stat (enum tree_code code, tree t
*** 3076,3083 ****
    if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
      gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
  		&& TREE_CODE (TREE_TYPE (arg1)) == INTEGER_TYPE
! 		&& tree_ssa_useless_type_conversion_1 (sizetype,
! 						       TREE_TYPE (arg1)));
  
    t = make_node_stat (code PASS_MEM_STAT);
    TREE_TYPE (t) = tt;
--- 3076,3082 ----
    if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
      gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
  		&& TREE_CODE (TREE_TYPE (arg1)) == INTEGER_TYPE
! 		&& !type_conversion_needed_p (sizetype, TREE_TYPE (arg1)));
  
    t = make_node_stat (code PASS_MEM_STAT);
    TREE_TYPE (t) = tt;


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