]> git.ipfire.org Git - thirdparty/gcc.git/commit
phiopt: do factor_out_conditional_operation for all phis [PR112418]
authorAndrew Pinski <quic_apinski@quicinc.com>
Wed, 4 Sep 2024 19:11:43 +0000 (12:11 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Sat, 19 Oct 2024 15:43:02 +0000 (08:43 -0700)
commit8d6d6d537fdc754a429b08091422c307188f3c82
treee2a42e65be13f3e92d0519d11e20fa756a937dc2
parentf2989316139c3e7a99b1babe2606833c05b8a12f
phiopt: do factor_out_conditional_operation for all phis [PR112418]

Sometimes factor_out_conditional_operation can factor out
an operation that causes a phi node to become the same element.
Other times, we want to factor out a binary operator because
it can improve code generation, an example is PR 110015 (openjpeg).

Note this includes a heuristic to decide if factoring out the operation
is profitable or not. It can be expanded to include a better live range
extend detector. Right now it has a simple one where if it is live on a
dominating path, it is considered a live or if there are a small # of
assign statements (defaults to 5), then it does not extend the live range
too much.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/112418

gcc/ChangeLog:

* tree-ssa-phiopt.cc (is_factor_profitable): New function.
(factor_out_conditional_operation): Add merge argument. Remove
arg0/arg1 arguments. Return bool instead of the new phi.
Early return for virtual ops. Call is_factor_profitable to
check if the factoring would be profitable.
(pass_phiopt::execute): Call factor_out_conditional_operation
on all phis instead of just singleton phi.
* doc/invoke.texi (--param phiopt-factor-max-stmts-live=): Document.
* params.opt (--param=phiopt-factor-max-stmts-live=): New opt.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/factor_op_phi-1.c: New test.
* gcc.dg/tree-ssa/factor_op_phi-2.c: New test.
* gcc.dg/tree-ssa/factor_op_phi-3.c: New test.
* gcc.dg/tree-ssa/factor_op_phi-4.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/doc/invoke.texi
gcc/params.opt
gcc/testsuite/gcc.dg/tree-ssa/factor_op_phi-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/factor_op_phi-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/factor_op_phi-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/factor_op_phi-4.c [new file with mode: 0644]
gcc/tree-ssa-phiopt.cc