This is the mail archive of the 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: [RFC] Use fold to do phi optimizations

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 value_replacement.

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 sound.

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 unless
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;

Andrew Pinski

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