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]

[tree-ssa] PATCH to make &decl a val


With this patch, the address of a decl is now a gimple value--and, if it is
a non-weak static, a gimple constant.

The changes outside of tree-simple.c are to fix a bug exposed by this
change which broke gfortran.fortran-torture/execute/math.f90--we were
marking a statement like

  T.36 = __builtin_sqrt (two4);

with call clobber VDEFs (because the declaration of __builtin_sqrt in the
F90 front end doesn't have the pure attribute--Fortran folks, you want to
fix that).  After constant propagation and folding in dom, this became

  T.36 = <constant>;

A later call to get_expr_operands threw away the VDEFs, breaking the VDEF
chain, and causing dce to discard things that were needed.

The way get_expr_operands throws away the vops seems very dangerous to me;
it really ought to check to make sure that either all the old vops show up
again, or the caller has asserted that it's OK to lose some of them.

This patch fixes gfortran.fortran-torture/execute/st_function.f90 and
libmudflap.cth/pass39-frag.c.  I think both are fixed by the tree-simple.c
change, not by the vops fix.

Booted and tested athlon-pc-linux-gnu, applied to tree-ssa.

2003-09-15  Jason Merrill  <jason@redhat.com>

	* tree-simple.c (is_gimple_val): Allow addresses of all decls.
	(is_gimple_const): Allow addresses of all non-weak statics.
	* tree-ssa-ccp.c (fold_stmt): Return bool.
	* tree-flow.h: Adjust prototype.
	* tree-ssa-dom.c (optimize_stmt): If folding changed stuff, we
	need to recalculate the vops.

*** tree-flow.h.~1~	2003-09-11 11:14:22.000000000 -0400
--- tree-flow.h	2003-09-15 16:31:08.000000000 -0400
*************** extern void tree_perform_ssapre (tree);
*** 497,503 ****
  
  /* In tree-ssa-ccp.c  */
  void tree_ssa_ccp (tree);
! void fold_stmt (tree *);
  tree widen_bitfield (tree, tree, tree);
  
  /* In tree-ssa-dom.c  */
--- 497,503 ----
  
  /* In tree-ssa-ccp.c  */
  void tree_ssa_ccp (tree);
! bool fold_stmt (tree *);
  tree widen_bitfield (tree, tree, tree);
  
  /* In tree-ssa-dom.c  */
*** tree-simple.c.~1~	2003-09-10 17:40:06.000000000 -0400
--- tree-simple.c	2003-09-15 15:06:28.000000000 -0400
*************** is_gimple_const (tree t)
*** 285,298 ****
      return 1;
  
    if (TREE_CODE (t) == ADDR_EXPR
- #if 0
        && DECL_P (TREE_OPERAND (t, 0))
- #else
-       && TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
- #endif
        && (TREE_STATIC (TREE_OPERAND (t, 0))
! 	  || DECL_EXTERNAL (TREE_OPERAND (t, 0)))
!       && !DECL_WEAK (TREE_OPERAND (t, 0)))
      return 1;
  
    if (TREE_CODE (t) == PLUS_EXPR
--- 285,294 ----
      return 1;
  
    if (TREE_CODE (t) == ADDR_EXPR
        && DECL_P (TREE_OPERAND (t, 0))
        && (TREE_STATIC (TREE_OPERAND (t, 0))
! 	  || (DECL_EXTERNAL (TREE_OPERAND (t, 0))
! 	      && !DECL_WEAK (TREE_OPERAND (t, 0)))))
      return 1;
  
    if (TREE_CODE (t) == PLUS_EXPR
*************** is_gimple_val (tree t)
*** 450,461 ****
        TREE_CODE (t) == EXC_PTR_EXPR
        /* Allow the address of a decl.  */
        || (TREE_CODE (t) == ADDR_EXPR
! #if 0
! 	  && DECL_P (TREE_OPERAND (t, 0))
! #else
! 	  && TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
! #endif
! 	  ))
      return 1;
  
    /* Allow address of vla, so that we do not replace it in the call_expr of
--- 446,452 ----
        TREE_CODE (t) == EXC_PTR_EXPR
        /* Allow the address of a decl.  */
        || (TREE_CODE (t) == ADDR_EXPR
! 	  && DECL_P (TREE_OPERAND (t, 0))))
      return 1;
  
    /* Allow address of vla, so that we do not replace it in the call_expr of
*** tree-ssa-ccp.c.~1~	2003-09-11 11:14:22.000000000 -0400
--- tree-ssa-ccp.c	2003-09-15 22:54:32.000000000 -0400
*************** likely_value (tree stmt)
*** 1273,1284 ****
  
  
  /* Fold the statement pointed by STMT_P.  In some cases, this function may
!    replace the whole statement with a new one.  */
  
! void
  fold_stmt (tree *stmt_p)
  {
    tree rhs, result, stmt;
  
    stmt = *stmt_p;
    rhs = get_rhs (stmt);
--- 1273,1286 ----
  
  
  /* Fold the statement pointed by STMT_P.  In some cases, this function may
!    replace the whole statement with a new one.  Returns true iff folding
!    makes any changes.  */
  
! bool
  fold_stmt (tree *stmt_p)
  {
    tree rhs, result, stmt;
+   bool changed = false;
  
    stmt = *stmt_p;
    rhs = get_rhs (stmt);
*************** fold_stmt (tree *stmt_p)
*** 1324,1333 ****
  
        /* Strip away useless type conversions.  */
        if (result != rhs)
! 	STRIP_MAIN_TYPE_NOPS (result);
  
        set_rhs (stmt_p, result);
      }
  }
  
  
--- 1326,1340 ----
  
        /* Strip away useless type conversions.  */
        if (result != rhs)
! 	{
! 	  changed = true;
! 	  STRIP_MAIN_TYPE_NOPS (result);
! 	}
  
        set_rhs (stmt_p, result);
      }
+ 
+   return changed;
  }
  
  
*** tree-ssa-dom.c.~1~	2003-09-11 11:14:23.000000000 -0400
--- tree-ssa-dom.c	2003-09-15 16:34:30.000000000 -0400
*************** optimize_stmt (block_stmt_iterator si, v
*** 850,856 ****
    /* If the statement has been modified with constant replacements,
       fold its RHS before checking for redundant computations.  */
    if (ann->modified)
!     fold_stmt (bsi_stmt_ptr (si));
  
    /* Check for redundant computations.  Do this optimization only
       for assignments that make no calls and have no aliased stores
--- 850,864 ----
    /* If the statement has been modified with constant replacements,
       fold its RHS before checking for redundant computations.  */
    if (ann->modified)
!     {
!       if (fold_stmt (bsi_stmt_ptr (si)))
! 	{
! 	  stmt = bsi_stmt (si);
! 	  /* Folding may have removed the need for some vops/vdefs,
! 	     particularly if we folded away a call to a builtin.  */
! 	  may_have_exposed_new_symbols = true;
! 	}
!     }
  
    /* Check for redundant computations.  Do this optimization only
       for assignments that make no calls and have no aliased stores

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