This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] tree-ssa vs. fold
- From: Jeff Sturm <jsturm at one-point dot com>
- To: Diego Novillo <dnovillo at redhat dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 28 Jun 2003 01:46:04 -0400 (EDT)
- Subject: Re: [tree-ssa] tree-ssa vs. fold
On 7 Jun 2003, Diego Novillo wrote:
> On Fri, 2003-06-06 at 21:25, Roger Sayle wrote:
> > Does a save_expr hook seem a reasonable compromise/workable?
> >
> In the case of GIMPLE code I don't think it's really needed. I can't
> think of a case where we would be giving fold() an expression whose
> operands need to be SAVE_EXPR'd. Expression operands in GIMPLE never
> have side-effects.
How about a volatile DECL? Maybe the easiest thing in that case is to not
try to fold. Else we have no choice but to introduce a temporary.
A save_expr hook may help, but I won't yet guarantee there aren't other
ways fold() could return a non-GIMPLE tree.
Long-term maybe we want to extract the subset of fold() that would
only involve GIMPLE. I'm not quite ready to tackle it, though. Below is
the least intrusive patch I could put together. From encountering an
SSA_NAME node it realizes it need not (and must not) save_expr the node.
Jeff
2003-06-27 Jeff Sturm <jsturm@one-point.com>
* fold-const.c (fold): Don't SAVE_EXPR an SSA_NAME node.
* 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 28 Jun 2003 05:39:04 -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_CODE (arg0) == SSA_NAME)
! arg = arg0;
! else
! arg = save_expr (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 28 Jun 2003 05:39:04 -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