On Thu, 11 Jun 2020, Zhanghaijian (A) wrote:

> Hi,
> 
> This is a experimental fix for pr94274. For if/else structure, when the 
> expressions is binary operation and have a common subexpression, and the 
> opcode is the same, we can fold the merging phi node in 
> tree_ssa_phiopt_worker (ssa-phiopt). It can be optimized to do csel 
> first and then do binary operations. This can eliminate one or more 
> instructions. And this patch is effective for 500.perlbench_r in 
> spec2017. Bootstrap and tested on aarch64/x86_64 Linux platform. No new 
> regression witnessed.
> 
> Any suggestion?  

First of all I would not implement this as separate pass, we do
have precedence for this kind of transform in phiopt itself
(factor_out_conditional_conversion).  There's also abs_replacement
which eventually sinks a negation operation.

Note that the equivalency code matches roughly what we do in
the tail-merging optimization (tree-ssa-tail-merge.c).  I guess
if you'd cleverly re-order stmts and split blocks you could see
tail-merging doing the desired transform.

Your approach hard-codes binary operations but we have other classes
of operations that would benefit from the transform (including
calls for example).

Your approach is greedy, for a larger expression you rely on
intermediate transforms to be profitable, that is you won't
sink

 _1 = a_2(D) + b_3(D);
 _2 = a_2(D) - b_3(D);
 _3 = _1 * _2;

 .. = PHI <_3, ...>

because sinking _1 * _2 requires two PHIs but after sinking
a + b and a - b both are gone.  Note that the number of PHIs
does not directly translate to register pressure.  Note
other opportunities you leave on the plate are when the above
also has a second PHI like

 .. = PHI <_2, ...>

because then _2 does not have a single use but if we sink
the second PHI vanishes as well.

So I do not think the greedy approach is sound given you
talk about examples with more than one sunk statement.

There is already two copies of code comparing statements,
one in the above mentioned tail-merging pass and one in
ICF - ipa-icf-gimple.[ch] may even have a usable interface
to compare sequences of stmts for equality and if not
Martin may be of help here.

Thanks,
Richard.

Reply via email to