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] Merge bugfixes from mem-ref2 branch


This merges stuff I fell over when developing on mem-ref2.  Mostly
trivial corrections and cleanups.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2010-04-07  Richard Guenther  <rguenther@suse.de>

	* ipa-reference.c (mark_load): Use get_base_address.
	(mark_store): Likewise.

	* tree-ssa-ccp.c (gimplify_and_update_call_from_tree): Avoid
	inserting GIMPLE_NOPs into the IL.
	* tree-ssa-structalias.c (get_constraint_for_component_ref):
	Explicitly strip handled components and indirect references.
  
	* fold-const.c (fold_unary_loc): Do not strip qualifiers when
	folding address expressions.
	* gimple.c (gimple_ior_addresses_taken_1): Use get_base_address.
	* tree-ssa-alias.c (decl_refs_may_alias_p): Do not use
	operand_equal_p to compare decls.
	(ptr_deref_may_alias_decl_p): Likewise.
	* tree-ssa-operands.c (get_asm_expr_operands): Simplify
	* tree-ssa-forwprop.c (forward_propagate_into_gimple_cond):
	Handle reversed comparison ops.
	* tree-sra.c (asm_visit_addr): Use get_base_address.
	* ipa-prop.c (visit_store_addr_for_mod_analysis): Use
	get_base_address.
	* ipa-reference.c (mark_address): Use get_base_address.

Index: trunk/gcc/fold-const.c
===================================================================
*** trunk.orig/gcc/fold-const.c	2010-04-07 15:53:14.000000000 +0200
--- trunk/gcc/fold-const.c	2010-04-07 16:20:59.000000000 +0200
*************** fold_unary_loc (location_t loc, enum tre
*** 8561,8570 ****
  				      &mode, &unsignedp, &volatilep, false);
  	  /* If the reference was to a (constant) zero offset, we can use
  	     the address of the base if it has the same base type
! 	     as the result type.  */
  	  if (! offset && bitpos == 0
! 	      && TYPE_MAIN_VARIANT (TREE_TYPE (type))
  		  == TYPE_MAIN_VARIANT (TREE_TYPE (base)))
  	    return fold_convert_loc (loc, type,
  				     build_fold_addr_expr_loc (loc, base));
          }
--- 8561,8571 ----
  				      &mode, &unsignedp, &volatilep, false);
  	  /* If the reference was to a (constant) zero offset, we can use
  	     the address of the base if it has the same base type
! 	     as the result type and the pointer type is unqualified.  */
  	  if (! offset && bitpos == 0
! 	      && (TYPE_MAIN_VARIANT (TREE_TYPE (type))
  		  == TYPE_MAIN_VARIANT (TREE_TYPE (base)))
+ 	      && TYPE_QUALS (type) == TYPE_UNQUALIFIED)
  	    return fold_convert_loc (loc, type,
  				     build_fold_addr_expr_loc (loc, base));
          }
Index: trunk/gcc/gimple.c
===================================================================
*** trunk.orig/gcc/gimple.c	2010-04-07 16:07:13.000000000 +0200
--- trunk/gcc/gimple.c	2010-04-07 16:20:59.000000000 +0200
*************** gimple_ior_addresses_taken_1 (gimple stm
*** 4532,4540 ****
  			      tree addr, void *data)
  {
    bitmap addresses_taken = (bitmap)data;
!   while (handled_component_p (addr))
!     addr = TREE_OPERAND (addr, 0);
!   if (DECL_P (addr))
      {
        bitmap_set_bit (addresses_taken, DECL_UID (addr));
        return true;
--- 4532,4540 ----
  			      tree addr, void *data)
  {
    bitmap addresses_taken = (bitmap)data;
!   addr = get_base_address (addr);
!   if (addr
!       && DECL_P (addr))
      {
        bitmap_set_bit (addresses_taken, DECL_UID (addr));
        return true;
Index: trunk/gcc/tree-ssa-alias.c
===================================================================
*** trunk.orig/gcc/tree-ssa-alias.c	2010-04-07 16:07:13.000000000 +0200
--- trunk/gcc/tree-ssa-alias.c	2010-04-07 16:20:59.000000000 +0200
*************** ptr_deref_may_alias_decl_p (tree ptr, tr
*** 189,195 ****
  	ptr = TREE_OPERAND (base, 0);
        else if (base
  	       && SSA_VAR_P (base))
! 	return operand_equal_p (base, decl, 0);
        else if (base
  	       && CONSTANT_CLASS_P (base))
  	return false;
--- 189,195 ----
  	ptr = TREE_OPERAND (base, 0);
        else if (base
  	       && SSA_VAR_P (base))
! 	return base == decl;
        else if (base
  	       && CONSTANT_CLASS_P (base))
  	return false;
*************** decl_refs_may_alias_p (tree base1,
*** 629,635 ****
    gcc_assert (SSA_VAR_P (base1) && SSA_VAR_P (base2));
  
    /* If both references are based on different variables, they cannot alias.  */
!   if (!operand_equal_p (base1, base2, 0))
      return false;
  
    /* If both references are based on the same variable, they cannot alias if
--- 629,635 ----
    gcc_assert (SSA_VAR_P (base1) && SSA_VAR_P (base2));
  
    /* If both references are based on different variables, they cannot alias.  */
!   if (base1 != base2)
      return false;
  
    /* If both references are based on the same variable, they cannot alias if
Index: trunk/gcc/tree-ssa-operands.c
===================================================================
*** trunk.orig/gcc/tree-ssa-operands.c	2010-04-07 15:53:14.000000000 +0200
--- trunk/gcc/tree-ssa-operands.c	2010-04-07 16:21:44.000000000 +0200
*************** get_asm_expr_operands (gimple stmt)
*** 798,808 ****
        /* Memory operands are addressable.  Note that STMT needs the
  	 address of this operand.  */
        if (!allows_reg && allows_mem)
! 	{
! 	  tree t = get_base_address (TREE_VALUE (link));
! 	  if (t && DECL_P (t))
! 	    mark_address_taken (t);
! 	}
  
        get_expr_operands (stmt, &TREE_VALUE (link), opf_def);
      }
--- 798,804 ----
        /* Memory operands are addressable.  Note that STMT needs the
  	 address of this operand.  */
        if (!allows_reg && allows_mem)
! 	mark_address_taken (TREE_VALUE (link));
  
        get_expr_operands (stmt, &TREE_VALUE (link), opf_def);
      }
*************** get_asm_expr_operands (gimple stmt)
*** 818,828 ****
        /* Memory operands are addressable.  Note that STMT needs the
  	 address of this operand.  */
        if (!allows_reg && allows_mem)
! 	{
! 	  tree t = get_base_address (TREE_VALUE (link));
! 	  if (t && DECL_P (t))
! 	    mark_address_taken (t);
! 	}
  
        get_expr_operands (stmt, &TREE_VALUE (link), 0);
      }
--- 814,820 ----
        /* Memory operands are addressable.  Note that STMT needs the
  	 address of this operand.  */
        if (!allows_reg && allows_mem)
! 	mark_address_taken (TREE_VALUE (link));
  
        get_expr_operands (stmt, &TREE_VALUE (link), 0);
      }
Index: trunk/gcc/tree-ssa-forwprop.c
===================================================================
*** trunk.orig/gcc/tree-ssa-forwprop.c	2010-04-07 15:53:14.000000000 +0200
--- trunk/gcc/tree-ssa-forwprop.c	2010-04-07 16:20:59.000000000 +0200
*************** forward_propagate_into_gimple_cond (gimp
*** 398,422 ****
  
    do {
      tree tmp = NULL_TREE;
!     tree name, rhs0 = NULL_TREE, rhs1 = NULL_TREE;
      gimple def_stmt;
      bool single_use0_p = false, single_use1_p = false;
      enum tree_code code = gimple_cond_code (stmt);
  
      /* We can do tree combining on SSA_NAME and comparison expressions.  */
!     if (TREE_CODE_CLASS (gimple_cond_code (stmt)) == tcc_comparison
!         && TREE_CODE (gimple_cond_lhs (stmt)) == SSA_NAME)
        {
  	/* For comparisons use the first operand, that is likely to
  	   simplify comparisons against constants.  */
! 	name = gimple_cond_lhs (stmt);
! 	def_stmt = get_prop_source_stmt (name, false, &single_use0_p);
! 	if (def_stmt && can_propagate_from (def_stmt))
  	  {
! 	    tree op1 = gimple_cond_rhs (stmt);
! 	    rhs0 = rhs_to_tree (TREE_TYPE (op1), def_stmt);
! 	    tmp = combine_cond_expr_cond (loc, code, boolean_type_node, rhs0,
! 					  op1, !single_use0_p);
  	  }
  	/* If that wasn't successful, try the second operand.  */
  	if (tmp == NULL_TREE
--- 398,424 ----
  
    do {
      tree tmp = NULL_TREE;
!     tree name = NULL_TREE, rhs0 = NULL_TREE, rhs1 = NULL_TREE;
      gimple def_stmt;
      bool single_use0_p = false, single_use1_p = false;
      enum tree_code code = gimple_cond_code (stmt);
  
      /* We can do tree combining on SSA_NAME and comparison expressions.  */
!     if (TREE_CODE_CLASS (gimple_cond_code (stmt)) == tcc_comparison)
        {
  	/* For comparisons use the first operand, that is likely to
  	   simplify comparisons against constants.  */
! 	if (TREE_CODE (gimple_cond_lhs (stmt)) == SSA_NAME)
  	  {
! 	    name = gimple_cond_lhs (stmt);
! 	    def_stmt = get_prop_source_stmt (name, false, &single_use0_p);
! 	    if (def_stmt && can_propagate_from (def_stmt))
! 	      {
! 		tree op1 = gimple_cond_rhs (stmt);
! 		rhs0 = rhs_to_tree (TREE_TYPE (op1), def_stmt);
! 		tmp = combine_cond_expr_cond (loc, code, boolean_type_node,
! 					      rhs0, op1, !single_use0_p);
! 	      }
  	  }
  	/* If that wasn't successful, try the second operand.  */
  	if (tmp == NULL_TREE
Index: trunk/gcc/tree-sra.c
===================================================================
*** trunk.orig/gcc/tree-sra.c	2010-04-07 15:53:14.000000000 +0200
--- trunk/gcc/tree-sra.c	2010-04-07 16:20:59.000000000 +0200
*************** static bool
*** 1066,1072 ****
  asm_visit_addr (gimple stmt ATTRIBUTE_UNUSED, tree op,
  		void *data ATTRIBUTE_UNUSED)
  {
!   if (DECL_P (op))
      disqualify_candidate (op, "Non-scalarizable GIMPLE_ASM operand.");
  
    return false;
--- 1066,1074 ----
  asm_visit_addr (gimple stmt ATTRIBUTE_UNUSED, tree op,
  		void *data ATTRIBUTE_UNUSED)
  {
!   op = get_base_address (op);
!   if (op
!       && DECL_P (op))
      disqualify_candidate (op, "Non-scalarizable GIMPLE_ASM operand.");
  
    return false;
Index: trunk/gcc/ipa-prop.c
===================================================================
*** trunk.orig/gcc/ipa-prop.c	2010-04-07 15:53:14.000000000 +0200
--- trunk/gcc/ipa-prop.c	2010-04-07 16:20:59.000000000 +0200
*************** visit_store_addr_for_mod_analysis (gimpl
*** 199,205 ****
  {
    struct ipa_node_params *info = (struct ipa_node_params *) data;
  
!   if (TREE_CODE (op) == PARM_DECL)
      {
        int index = ipa_get_param_decl_index (info, op);
        gcc_assert (index >= 0);
--- 199,207 ----
  {
    struct ipa_node_params *info = (struct ipa_node_params *) data;
  
!   op = get_base_address (op);
!   if (op
!       && TREE_CODE (op) == PARM_DECL)
      {
        int index = ipa_get_param_decl_index (info, op);
        gcc_assert (index >= 0);
Index: trunk/gcc/ipa-reference.c
===================================================================
*** trunk.orig/gcc/ipa-reference.c	2010-04-07 15:53:14.000000000 +0200
--- trunk/gcc/ipa-reference.c	2010-04-07 16:20:59.000000000 +0200
*************** static bool
*** 352,360 ****
  mark_address (gimple stmt ATTRIBUTE_UNUSED, tree addr,
  	      void *data ATTRIBUTE_UNUSED)
  {
!   while (handled_component_p (addr))
!     addr = TREE_OPERAND (addr, 0);
!   mark_address_taken (addr);
    return false;
  }
  
--- 352,360 ----
  mark_address (gimple stmt ATTRIBUTE_UNUSED, tree addr,
  	      void *data ATTRIBUTE_UNUSED)
  {
!   addr = get_base_address (addr);
!   if (addr)
!     mark_address_taken (addr);
    return false;
  }
  
*************** static bool
*** 364,370 ****
  mark_load (gimple stmt ATTRIBUTE_UNUSED, tree t, void *data)
  {
    ipa_reference_local_vars_info_t local = (ipa_reference_local_vars_info_t)data;
!   if (TREE_CODE (t) == VAR_DECL
        && has_proper_scope_for_analysis (t))
      bitmap_set_bit (local->statics_read, DECL_UID (t));
    return false;
--- 364,371 ----
  mark_load (gimple stmt ATTRIBUTE_UNUSED, tree t, void *data)
  {
    ipa_reference_local_vars_info_t local = (ipa_reference_local_vars_info_t)data;
!   t = get_base_address (t);
!   if (t && TREE_CODE (t) == VAR_DECL
        && has_proper_scope_for_analysis (t))
      bitmap_set_bit (local->statics_read, DECL_UID (t));
    return false;
*************** static bool
*** 376,382 ****
  mark_store (gimple stmt ATTRIBUTE_UNUSED, tree t, void *data)
  {
    ipa_reference_local_vars_info_t local = (ipa_reference_local_vars_info_t)data;
!   if (TREE_CODE (t) == VAR_DECL
        && has_proper_scope_for_analysis (t))
      {
        if (local)
--- 377,384 ----
  mark_store (gimple stmt ATTRIBUTE_UNUSED, tree t, void *data)
  {
    ipa_reference_local_vars_info_t local = (ipa_reference_local_vars_info_t)data;
!   t = get_base_address (t);
!   if (t && TREE_CODE (t) == VAR_DECL
        && has_proper_scope_for_analysis (t))
      {
        if (local)
Index: trunk/gcc/tree-ssa-ccp.c
===================================================================
*** trunk.orig/gcc/tree-ssa-ccp.c	2010-04-07 15:53:14.000000000 +0200
--- trunk/gcc/tree-ssa-ccp.c	2010-04-07 16:20:59.000000000 +0200
*************** gimplify_and_update_call_from_tree (gimp
*** 3354,3359 ****
--- 3354,3360 ----
    gimple_stmt_iterator i;
    gimple_seq stmts = gimple_seq_alloc();
    struct gimplify_ctx gctx;
+   gimple last = NULL;
  
    stmt = gsi_stmt (*si_p);
  
*************** gimplify_and_update_call_from_tree (gimp
*** 3375,3396 ****
  
    /* The replacement can expose previously unreferenced variables.  */
    for (i = gsi_start (stmts); !gsi_end_p (i); gsi_next (&i))
!   {
!     new_stmt = gsi_stmt (i);
!     find_new_referenced_vars (new_stmt);
!     gsi_insert_before (si_p, new_stmt, GSI_NEW_STMT);
!     mark_symbols_for_renaming (new_stmt);
!     gsi_next (si_p);
!   }
  
    if (lhs == NULL_TREE)
      {
-       new_stmt = gimple_build_nop ();
        unlink_stmt_vdef (stmt);
        release_defs (stmt);
      }
    else
      {
        new_stmt = gimple_build_assign (lhs, tmp);
        gimple_set_vuse (new_stmt, gimple_vuse (stmt));
        gimple_set_vdef (new_stmt, gimple_vdef (stmt));
--- 3376,3406 ----
  
    /* The replacement can expose previously unreferenced variables.  */
    for (i = gsi_start (stmts); !gsi_end_p (i); gsi_next (&i))
!     {
!       if (last)
! 	{
! 	  gsi_insert_before (si_p, last, GSI_NEW_STMT);
! 	  gsi_next (si_p);
! 	}
!       new_stmt = gsi_stmt (i);
!       find_new_referenced_vars (new_stmt);
!       mark_symbols_for_renaming (new_stmt);
!       last = new_stmt;
!     }
  
    if (lhs == NULL_TREE)
      {
        unlink_stmt_vdef (stmt);
        release_defs (stmt);
+       new_stmt = last;
      }
    else
      {
+       if (last)
+ 	{
+ 	  gsi_insert_before (si_p, last, GSI_NEW_STMT);
+ 	  gsi_next (si_p);
+ 	}
        new_stmt = gimple_build_assign (lhs, tmp);
        gimple_set_vuse (new_stmt, gimple_vuse (stmt));
        gimple_set_vdef (new_stmt, gimple_vdef (stmt));
Index: trunk/gcc/tree-ssa-structalias.c
===================================================================
*** trunk.orig/gcc/tree-ssa-structalias.c	2010-04-07 16:07:13.000000000 +0200
--- trunk/gcc/tree-ssa-structalias.c	2010-04-07 16:22:26.000000000 +0200
*************** get_constraint_for_component_ref (tree t
*** 2951,2957 ****
    /* Some people like to do cute things like take the address of
       &0->a.b */
    forzero = t;
!   while (!SSA_VAR_P (forzero) && !CONSTANT_CLASS_P (forzero))
      forzero = TREE_OPERAND (forzero, 0);
  
    if (CONSTANT_CLASS_P (forzero) && integer_zerop (forzero))
--- 2951,2958 ----
    /* Some people like to do cute things like take the address of
       &0->a.b */
    forzero = t;
!   while (handled_component_p (forzero)
! 	 || INDIRECT_REF_P (forzero))
      forzero = TREE_OPERAND (forzero, 0);
  
    if (CONSTANT_CLASS_P (forzero) && integer_zerop (forzero))


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