[PATCH] Do not recompute_tree_invariant_for_addr_expr

Richard Guenther rguenther@suse.de
Thu Mar 20 22:37:00 GMT 2008


As we switched is_gimple_min_invariant to re-check its property at
every call we no longer need to keep the cache (TREE_INVARIANT)
up-to-date.

Bootstrapped and tested on x86_64-unknown-linux-gnu, I'll apply this
later.

Richard.

2008-03-20  Richard Guenther  <rguenther@suse.de>

	* gimpify.c (gimplify_addr_expr): Clear TREE_SIDE_EFFECTS,
	do not call recompute_tree_invariant_for_addr_expr.
	* omp-low.c (lower_omp_2): Likewise.
	* tree-inline.c (copy_body_r): Likewise.
	* tree-nested.c (convert_nonlocal_reference): Likewise.
	(convert_local_reference): Likewise.
	* tree-cfg.c (replace_uses_by): Likewise.
	(verify_expr): Do not verify that
	recompute_tree_invariant_for_addr_expr is properly called.
	Recurse again for invariant addresses.  For PHI nodes
	verify the address is invariant.
	* tree-ssa-ccp.c (ccp_decl_initial_min_invariant): Remove.
	(get_symbol_constant_value): Use is_gimple_min_invariant.
	(maybe_fold_stmt_indirect): Likewise.
	(fold_stmt_r): Do not call recompute_tree_invariant_for_addr_expr.
	* tree-ssa-dom.c (optimize_stmt): Likewise.
	(propagate_rhs_into_lhs): Likewise.
	* tree-ssa-forwprop.c (tidy_after_forward_propagate_addr): Likewise.
	* tree-ssa-propagate.c (substitute_and_fold): Likewise.

Index: trunk/gcc/gimplify.c
===================================================================
*** trunk.orig/gcc/gimplify.c	2008-03-20 19:44:38.000000000 +0100
--- trunk/gcc/gimplify.c	2008-03-20 21:51:05.000000000 +0100
*************** gimplify_addr_expr (tree *expr_p, tree *
*** 4242,4256 ****
  	  if (TREE_CODE (op0) == INDIRECT_REF)
  	    goto do_indirect_ref;
  
- 	  /* Make sure TREE_INVARIANT, TREE_CONSTANT, and TREE_SIDE_EFFECTS
- 	     is set properly.  */
- 	  recompute_tree_invariant_for_addr_expr (expr);
- 
  	  mark_addressable (TREE_OPERAND (expr, 0));
  	}
        break;
      }
  
    return ret;
  }
  
--- 4242,4255 ----
  	  if (TREE_CODE (op0) == INDIRECT_REF)
  	    goto do_indirect_ref;
  
  	  mark_addressable (TREE_OPERAND (expr, 0));
  	}
        break;
      }
  
+   /* All side-effects have been resolved.  */
+   TREE_SIDE_EFFECTS (expr) = false;
+ 
    return ret;
  }
  
Index: trunk/gcc/omp-low.c
===================================================================
*** trunk.orig/gcc/omp-low.c	2008-03-20 19:44:21.000000000 +0100
--- trunk/gcc/omp-low.c	2008-03-20 19:44:35.000000000 +0100
*************** lower_omp_2 (tree *tp, int *walk_subtree
*** 4896,4906 ****
    if (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t))
      return t;
  
-   /* If a global variable has been privatized, TREE_CONSTANT on
-      ADDR_EXPR might be wrong.  */
-   if (TREE_CODE (t) == ADDR_EXPR)
-     recompute_tree_invariant_for_addr_expr (t);
- 
    *walk_subtrees = !TYPE_P (t) && !DECL_P (t);
    return NULL_TREE;
  }
--- 4896,4901 ----
Index: trunk/gcc/tree-cfg.c
===================================================================
*** trunk.orig/gcc/tree-cfg.c	2008-03-20 19:38:12.000000000 +0100
--- trunk/gcc/tree-cfg.c	2008-03-20 19:48:57.000000000 +0100
*************** replace_uses_by (tree name, tree val)
*** 1238,1254 ****
  
        if (TREE_CODE (stmt) != PHI_NODE)
  	{
- 	  tree rhs;
- 
  	  fold_stmt_inplace (stmt);
  	  if (cfgcleanup_altered_bbs)
  	    bitmap_set_bit (cfgcleanup_altered_bbs, bb_for_stmt (stmt)->index);
  
- 	  /* FIXME.  This should go in pop_stmt_changes.  */
- 	  rhs = get_rhs (stmt);
- 	  if (TREE_CODE (rhs) == ADDR_EXPR)
- 	    recompute_tree_invariant_for_addr_expr (rhs);
- 
  	  maybe_clean_or_replace_eh_stmt (stmt, stmt);
  
  	  pop_stmt_changes (&stmt);
--- 1238,1247 ----
*************** verify_expr (tree *tp, int *walk_subtree
*** 3157,3169 ****
  
      case ADDR_EXPR:
        {
- 	bool old_invariant;
- 	bool old_constant;
- 	bool old_side_effects;
- 	bool new_invariant;
- 	bool new_constant;
- 	bool new_side_effects;
- 
          /* ??? tree-ssa-alias.c may have overlooked dead PHI nodes, missing
  	   dead PHIs that take the address of something.  But if the PHI
  	   result is dead, the fact that it takes the address of anything
--- 3150,3155 ----
*************** verify_expr (tree *tp, int *walk_subtree
*** 3172,3203 ****
  	   we may be missing "valid" checks, but what can you do?
  	   This was PR19217.  */
          if (in_phi)
- 	  break;
- 
- 	old_invariant = TREE_INVARIANT (t);
- 	old_constant = TREE_CONSTANT (t);
- 	old_side_effects = TREE_SIDE_EFFECTS (t);
- 
- 	recompute_tree_invariant_for_addr_expr (t);
- 	new_invariant = TREE_INVARIANT (t);
- 	new_side_effects = TREE_SIDE_EFFECTS (t);
- 	new_constant = TREE_CONSTANT (t);
- 
- 	if (old_invariant != new_invariant)
  	  {
! 	    error ("invariant not recomputed when ADDR_EXPR changed");
! 	    return t;
! 	  }
! 
!         if (old_constant != new_constant)
! 	  {
! 	    error ("constant not recomputed when ADDR_EXPR changed");
! 	    return t;
! 	  }
! 	if (old_side_effects != new_side_effects)
! 	  {
! 	    error ("side effects not recomputed when ADDR_EXPR changed");
! 	    return t;
  	  }
  
  	/* Skip any references (they will be checked when we recurse down the
--- 3158,3170 ----
  	   we may be missing "valid" checks, but what can you do?
  	   This was PR19217.  */
          if (in_phi)
  	  {
! 	    if (!is_gimple_min_invariant (t))
! 	      {
! 		error ("non-invariant address expression in PHI argument");
! 		return t;
! 	      }
! 	    break;
  	  }
  
  	/* Skip any references (they will be checked when we recurse down the
*************** verify_expr (tree *tp, int *walk_subtree
*** 3216,3225 ****
  	    return x;
  	  }
  
- 	/* Stop recursing and verifying invariant ADDR_EXPRs, they tend
- 	   to become arbitrary complicated.  */
- 	if (is_gimple_min_invariant (t))
- 	  *walk_subtrees = 0;
  	break;
        }
  
--- 3183,3188 ----
Index: trunk/gcc/tree-inline.c
===================================================================
*** trunk.orig/gcc/tree-inline.c	2008-03-20 19:42:39.000000000 +0100
--- trunk/gcc/tree-inline.c	2008-03-20 19:42:58.000000000 +0100
*************** copy_body_r (tree *tp, int *walk_subtree
*** 779,786 ****
  	     into the operand of the ADDR_EXPR.  */
  	  if (TREE_CODE (TREE_OPERAND (*tp, 0)) == INDIRECT_REF)
  	    *tp = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0);
- 	  else
- 	    recompute_tree_invariant_for_addr_expr (*tp);
  	  /* If this used to be invariant, but is not any longer,
  	     then regimplification is probably needed.  */
  	  if (invariant && !is_gimple_min_invariant (*tp))
--- 779,784 ----
Index: trunk/gcc/tree-nested.c
===================================================================
*** trunk.orig/gcc/tree-nested.c	2008-03-20 19:41:29.000000000 +0100
--- trunk/gcc/tree-nested.c	2008-03-20 19:42:32.000000000 +0100
*************** convert_nonlocal_reference (tree *tp, in
*** 1035,1049 ****
  
  	if (wi->changed)
  	  {
- 	    tree save_context;
- 
- 	    /* If we changed anything, then TREE_INVARIANT is be wrong,
- 	       since we're no longer directly referencing a decl.  */
- 	    save_context = current_function_decl;
- 	    current_function_decl = info->context;
- 	    recompute_tree_invariant_for_addr_expr (t);
- 	    current_function_decl = save_context;
- 
  	    /* If the callback converted the address argument in a context
  	       where we only accept variables (and min_invariant, presumably),
  	       then compute the address into a temporary.  */
--- 1035,1040 ----
*************** convert_local_reference (tree *tp, int *
*** 1326,1340 ****
        /* If we converted anything ... */
        if (wi->changed)
  	{
- 	  tree save_context;
- 
  	  /* Then the frame decl is now addressable.  */
  	  TREE_ADDRESSABLE (info->frame_decl) = 1;
- 	    
- 	  save_context = current_function_decl;
- 	  current_function_decl = info->context;
- 	  recompute_tree_invariant_for_addr_expr (t);
- 	  current_function_decl = save_context;
  
  	  /* If we are in a context where we only accept values, then
  	     compute the address into a temporary.  */
--- 1317,1324 ----
Index: trunk/gcc/tree-ssa-ccp.c
===================================================================
*** trunk.orig/gcc/tree-ssa-ccp.c	2008-03-20 19:40:55.000000000 +0100
--- trunk/gcc/tree-ssa-ccp.c	2008-03-20 19:52:12.000000000 +0100
*************** debug_lattice_value (prop_value_t val)
*** 267,297 ****
  }
  
  
- /* The regular is_gimple_min_invariant does a shallow test of the object.
-    It assumes that full gimplification has happened, or will happen on the
-    object.  For a value coming from DECL_INITIAL, this is not true, so we
-    have to be more strict ourselves.  */
- 
- static bool
- ccp_decl_initial_min_invariant (tree t)
- {
-   if (!is_gimple_min_invariant (t))
-     return false;
-   if (TREE_CODE (t) == ADDR_EXPR)
-     {
-       /* Inline and unroll is_gimple_addressable.  */
-       while (1)
- 	{
- 	  t = TREE_OPERAND (t, 0);
- 	  if (is_gimple_id (t))
- 	    return true;
- 	  if (!handled_component_p (t))
- 	    return false;
- 	}
-     }
-   return true;
- }
- 
  /* If SYM is a constant variable with known value, return the value.
     NULL_TREE is returned otherwise.  */
  
--- 267,272 ----
*************** get_symbol_constant_value (tree sym)
*** 304,310 ****
      {
        tree val = DECL_INITIAL (sym);
        if (val
! 	  && ccp_decl_initial_min_invariant (val))
  	return val;
        /* Variables declared 'const' without an initializer
  	 have zero as the intializer if they may not be
--- 279,285 ----
      {
        tree val = DECL_INITIAL (sym);
        if (val
! 	  && is_gimple_min_invariant (val))
  	return val;
        /* Variables declared 'const' without an initializer
  	 have zero as the intializer if they may not be
*************** maybe_fold_stmt_indirect (tree expr, tre
*** 1983,1989 ****
  
        /* Fold away CONST_DECL to its value, if the type is scalar.  */
        if (TREE_CODE (base) == CONST_DECL
! 	  && ccp_decl_initial_min_invariant (DECL_INITIAL (base)))
  	return DECL_INITIAL (base);
  
        /* Try folding *(&B+O) to B.X.  */
--- 1958,1964 ----
  
        /* Fold away CONST_DECL to its value, if the type is scalar.  */
        if (TREE_CODE (base) == CONST_DECL
! 	  && is_gimple_min_invariant (DECL_INITIAL (base)))
  	return DECL_INITIAL (base);
  
        /* Try folding *(&B+O) to B.X.  */
*************** fold_stmt_r (tree *expr_p, int *walk_sub
*** 2202,2212 ****
        if (t)
  	return t;
        *walk_subtrees = 0;
- 
-       /* Set TREE_INVARIANT properly so that the value is properly
- 	 considered constant, and so gets propagated as expected.  */
-       if (*changed_p)
-         recompute_tree_invariant_for_addr_expr (expr);
        return NULL_TREE;
  
      case POINTER_PLUS_EXPR:
--- 2177,2182 ----
Index: trunk/gcc/tree-ssa-dom.c
===================================================================
*** trunk.orig/gcc/tree-ssa-dom.c	2008-03-20 19:40:07.000000000 +0100
--- trunk/gcc/tree-ssa-dom.c	2008-03-20 19:40:47.000000000 +0100
*************** optimize_stmt (struct dom_walk_data *wal
*** 1808,1815 ****
       fold its RHS before checking for redundant computations.  */
    if (ann->modified)
      {
-       tree rhs;
- 
        /* Try to fold the statement making sure that STMT is kept
  	 up to date.  */
        if (fold_stmt (bsi_stmt_ptr (si)))
--- 1808,1813 ----
*************** optimize_stmt (struct dom_walk_data *wal
*** 1824,1833 ****
  	    }
  	}
  
-       rhs = get_rhs (stmt);
-       if (rhs && TREE_CODE (rhs) == ADDR_EXPR)
- 	recompute_tree_invariant_for_addr_expr (rhs);
- 
        /* Constant/copy propagation above may change the set of 
  	 virtual operands associated with this statement.  Folding
  	 may remove the need for some virtual operands.
--- 1822,1827 ----
*************** propagate_rhs_into_lhs (tree stmt, tree 
*** 2256,2268 ****
  	      fprintf (dump_file, "\n");
  	    }
  
- 	  /* If we replaced a variable index with a constant, then
- 	     we would need to update the invariant flag for ADDR_EXPRs.  */
- 	  if (TREE_CODE (use_stmt) == GIMPLE_MODIFY_STMT
- 	      && TREE_CODE (GIMPLE_STMT_OPERAND (use_stmt, 1)) == ADDR_EXPR)
- 	    recompute_tree_invariant_for_addr_expr
- 	      (GIMPLE_STMT_OPERAND (use_stmt, 1));
- 
  	  /* If we cleaned up EH information from the statement,
  	     mark its containing block as needing EH cleanups.  */
  	  if (maybe_clean_or_replace_eh_stmt (use_stmt, use_stmt))
--- 2250,2255 ----
Index: trunk/gcc/tree-ssa-forwprop.c
===================================================================
*** trunk.orig/gcc/tree-ssa-forwprop.c	2008-03-20 19:39:14.000000000 +0100
--- trunk/gcc/tree-ssa-forwprop.c	2008-03-20 19:39:59.000000000 +0100
*************** tidy_after_forward_propagate_addr (tree 
*** 480,488 ****
        && tree_purge_dead_eh_edges (bb_for_stmt (stmt)))
      cfg_changed = true;
  
-   if (TREE_CODE (GIMPLE_STMT_OPERAND (stmt, 1)) == ADDR_EXPR)
-      recompute_tree_invariant_for_addr_expr (GIMPLE_STMT_OPERAND (stmt, 1));
- 
    mark_symbols_for_renaming (stmt);
  }
  
--- 480,485 ----
Index: trunk/gcc/tree-ssa-propagate.c
===================================================================
*** trunk.orig/gcc/tree-ssa-propagate.c	2008-03-20 19:38:33.000000000 +0100
--- trunk/gcc/tree-ssa-propagate.c	2008-03-20 20:37:37.000000000 +0100
*************** substitute_and_fold (prop_value_t *prop_
*** 1257,1263 ****
  	  if (did_replace)
  	    {
  	      tree old_stmt = stmt;
- 	      tree rhs;
  
  	      fold_stmt (bsi_stmt_ptr (i));
  	      stmt = bsi_stmt (i);
--- 1257,1262 ----
*************** substitute_and_fold (prop_value_t *prop_
*** 1267,1276 ****
  	      if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
  		tree_purge_dead_eh_edges (bb);
  
- 	      rhs = get_rhs (stmt);
- 	      if (TREE_CODE (rhs) == ADDR_EXPR)
- 		recompute_tree_invariant_for_addr_expr (rhs);
- 
  	      if (dump_file && (dump_flags & TDF_DETAILS))
  		{
  		  fprintf (dump_file, "Folded statement: ");
--- 1266,1271 ----



More information about the Gcc-patches mailing list