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]

Re: [tree-ssa] tree-ssa vs. fold


On Sat, 28 Jun 2003, Jason Merrill wrote:
> How about checking TREE_SIDE_EFFECTS instead of looking for SSA_NAME?

If we can be confident that TREE_SIDE_EFFECTS == TREE_THIS_VOLATILE for
GIMPLE binop nodes, this patch should be equivalent to the last, except
for eliminating some unnecessary SAVE_EXPRs when folding non-GIMPLE trees.

I've verified this patch still optimizes the test case correctly, and
fixes the last Java regression on tree-ssa.  Full bootstrap in progress.

Jeff

2003-06-28  Jeff Sturm   <jsturm@one-point.com>

	* fold-const.c (fold): Don't save_expr unless TREE_SIDE_EFFECTS.
	* tree-ssa.c (rewrite_and_optimize_stmt): Check has_volatile_ops
	before folding.

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.213.2.32
diff -c -p -r1.213.2.32 fold-const.c
*** fold-const.c	12 Jun 2003 16:44:01 -0000	1.213.2.32
--- fold-const.c	29 Jun 2003 00:28:10 -0000
*************** fold (expr)
*** 6609,6615 ****
  	      && (*lang_hooks.decls.global_bindings_p) () == 0
  	      && ! contains_placeholder_p (arg0))
  	    {
! 	      tree arg = save_expr (arg0);
  	      return fold (build (PLUS_EXPR, type, arg, arg));
  	    }

--- 6609,6623 ----
  	      && (*lang_hooks.decls.global_bindings_p) () == 0
  	      && ! contains_placeholder_p (arg0))
  	    {
! 	      tree arg;
!
! 	      /* If we got here by way of rewrite_into_ssa,
! 		 we must not save_expr arg, which cannot have
! 		 side effects anyhow.  */
! 	      if (TREE_SIDE_EFFECTS (arg0))
! 		 arg = save_expr (arg0);
! 	      else
! 		 arg = arg0;
  	      return fold (build (PLUS_EXPR, type, arg, arg));
  	    }

Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.98
diff -c -p -r1.1.4.98 tree-ssa.c
*** tree-ssa.c	26 Jun 2003 01:07:05 -0000	1.1.4.98
--- tree-ssa.c	29 Jun 2003 00:28:10 -0000
*************** rewrite_and_optimize_stmt (block_stmt_it
*** 2142,2150 ****
    for (i = 0; vuses && i < VARRAY_ACTIVE_SIZE (vuses); i++)
      rewrite_operand (&(VARRAY_TREE (vuses, i)));

!   /* If the statement has been modified with constant replacements,
!       fold its RHS before checking for redundant computations.  */
!   if (ann->modified)
      fold_stmt (stmt);

    /* Step 2.  Check for redundant computations.  Do this optimization only
--- 2142,2152 ----
    for (i = 0; vuses && i < VARRAY_ACTIVE_SIZE (vuses); i++)
      rewrite_operand (&(VARRAY_TREE (vuses, i)));

!   /* If the statement has been modified with constant replacements
!      and contains no volatile references, fold its RHS before checking
!      for redundant computations.  */
!   /* FIXME.  fold needs to know when it must maintain GIMPLE trees.  */
!   if (ann->modified && !ann->has_volatile_ops)
      fold_stmt (stmt);

    /* Step 2.  Check for redundant computations.  Do this optimization only


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