This is the mail archive of the
mailing list for the GCC project.
Re: [RFC] Use fold to do phi optimizations
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: Paolo Bonzini <bonzini at gnu dot org>
- Cc: gcc-patches at gcc dot gnu dot org, Andrew Pinski <pinskia at physics dot uc dot edu>, law at redhat dot com
- Date: Thu, 3 Jun 2004 12:01:29 -0400
- Subject: Re: [RFC] Use fold to do phi optimizations
- References: <40BEE5E7.firstname.lastname@example.org>
On Jun 3, 2004, at 04:48, Paolo Bonzini wrote:
While experimenting with phiopt and getting bored about the code
duplication it has, I tried this attempt at reorganizing substantially
the way it works. With this patch, phiopt will create GENERIC for the
condition block and the other_block, creates a COND_EXPR from these
and the PHI tries to fold it, and if the folding succeeds it replaces
the phi with the gimplified result.
The phi optimization succeeds if it can eat all of the statements in
the other_block (or if it is empty, of course). For now, the only
GENERIC constructs that are searched backwards are casts, but it
could be possible to look for more constructs.
This adds optimizations such as synthesizing MIN_EXPR/MAX_EXPR, so I'm
also removing from gimplify_expr the gimplification of MIN_EXPRs and
MAX_EXPRs; they become valid GIMPLE binary operations.
It could do more such as (A & 2 ? 2 : 0) ==> A & 2 with some tweaks to
fold: an example is in the fold-const.c hunk of the attached patch,
necessary to obtain the same replacements that were in
I've not bootstrapped nor regtested it (except for checking that it
passes the few phiopt tests in the tree-ssa test suite), it creates
too much garbage, etc. etc.; I just wanted to ask if the concept seems
I would say instead of using fold, can you instead pull out the
COND_EXPR folding from fold
and put it into a function called fold_cond_expr which returns NULL if
it cannot do the
folding and takes four arguments (type, condition, true_part,
false_part) and then just use that function in fold and in
tree-ssa-phiopt. This way you do not have create new trees at all
they are needed.
There is also a missed optimization (absolute value) in fold which
phiopt catches as fold does
not look at a>0?a:-a; unless you fixed that in your patch.
I think there is another missed optimization in fold too for nabs
(negative abs): a>0?-a:a;