This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] tree-ssa-ccp.c: Propagate ADDR_EXPRs further.
- From: Jeffrey A Law <law at redhat dot com>
- To: Kazu Hirata <kazu at cs dot umass dot edu>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 26 May 2005 22:40:39 -0600
- Subject: Re: [patch] tree-ssa-ccp.c: Propagate ADDR_EXPRs further.
- References: <20050527.001713.98419647.kazu@cs.umass.edu>
- Reply-to: law at redhat dot com
On Fri, 2005-05-27 at 00:17 -0400, Kazu Hirata wrote:
> Hi,
>
> Attached is a patch to propagate ADDR_EXPRs further.
>
> Consider
>
> void
> f (void)
> {
> int a[10];
> int *p = &a[5];
> int *q = p - 1;
> if (q != &a[4])
> link_error ();
> }
>
> Note that "p - 1" can be folded to &a[4] because p is known to be
> &a[4]. However, CCP doesn't do so despite Richard Guenther's recent
> improvement to try_move_mult_to_index in fold-const.c. To be precise,
> the propagator does not do the folding in question. fold_stmt does
> fold "p - 1", so we end up with
>
> q = &a[4];
> if (q != &a[4])
>
> Notice that we leave the "if" statement there.
>
> The problem is that fold_binary_to_constant is a bit too restrictive.
> Recall that fold_binary_to_constant calls fold_binary as a subroutine.
> fold_binary does fold "&a[5] - 1" to &a[4] as desired, but
> fold_binary_to_constant rejects the result because TREE_CONSTANT isn't
> set. I guess TREE_CONSTANT is for compile-time and maybe link-time
> constants, but regardless, that's not exactly what
> is_gimple_min_invariant accepts. AFAIK, is_gimple_min_invariant also
> accepts ADDR_EXPRs like &a[4], where 'a' is some array.
>
> The patch fixes the problem by simply changing fold_binary_to_constant
> to fold_binary in ccp_fold. Note that ccp_fold calls
> is_gimple_min_invariant like so
>
> if (retval && ! is_gimple_min_invariant (retval))
> return NULL;
>
> so we won't propagate something that does not satisfy
> is_gimple_min_invariant.
>
> Since ccp_fold calls fold_unary_to_constant, I changed that to
> fold_unary as well. We call is_gimple_min_invariant there, too, so we
> don't have to worry about propagating something that does not satisfy
> is_gimple_min_invariant.
>
> Tested on i686-pc-linux-gnu. OK to apply?
>
> Kazu Hirata
>
> 2005-05-27 Kazu Hirata <kazu@cs.umass.edu>
>
> PR tree-optimization/21658
> * tree-ssa-ccp.c (ccp_fold): Call fold_binary instead of
> fold_binary_to_constant. Likewise, call fold_unary instead of
> fold_unary_to_constant.
>
> 2005-05-27 Kazu Hirata <kazu@cs.umass.edu>
>
> PR tree-optimization/21658
> * gcc.dg/tree-ssa/pr21658.c: New.
I'd like to see at least some measurement of compile-time impacts.
There were two reasons for the introduction of fold_XXX_to_constant
routines. One was to avoid the destructive nature of fold. That
problem has been fixed and is thus no longer an issue. The other
was compile-time. We were spending a measurable amount of time
with a lot of useless attempts at folding (CCP doesn't need anywhere
near the full set of simplifications done by fold).
An alternate approach would be to loosen the check in
fold_XXX_to_constant and let them fold to invariants instead of
just constants.
jeff