]> git.ipfire.org Git - thirdparty/gcc.git/commit
loop-ch improvements, part 5
authorJan Hubicka <jh@suse.cz>
Fri, 21 Jul 2023 12:54:23 +0000 (14:54 +0200)
committerJan Hubicka <jh@suse.cz>
Fri, 21 Jul 2023 12:57:10 +0000 (14:57 +0200)
commit65ff4a45b11b5ab13ef849bd5721ab28ff316202
tree96314c3687f55ed6251db062b8b23a07504dcb75
parent8cbdb2e4d64461d8a19e033bd33b585187059d8a
loop-ch improvements, part 5

Currently loop-ch skips all do-while loops.  But when loop is not do-while
in addition to original goal of turining it to do-while it can do additional
things:
 1) move out loop invariant computations
 2) duplicate loop invariant conditionals and eliminate them in loop body.
 3) prove that some exits are always true in first iteration
    and can be skipped

Most of time 1 can be done by lim (exception is when the invariant computation
is conditional). For 2 we however don't really have other place doing it except
for loop unswitching that is more expensive (it will duplicate the loop and
then optimize out one path to non-loop).
3 can be done by loop peeling but it is also more expensive by duplicating full
loop body.

This patch improves heuristics by not giving up on do-while loops and trying
to find sequence of BBs to duplicate to obtain one of goals:
 - turn loop to do-while
 - eliminate invariant conditional in loop body
 - do partial "peeling" as long as code optimizes enough so this does not
   increase code size.

Bootstrapped/regtested x86_64-linux, OK?

gcc/ChangeLog:

* tree-ssa-loop-ch.cc (enum ch_decision): New enum.
(should_duplicate_loop_header_p): Return info on profitability.
(do_while_loop_p): Watch for constant conditionals.
(update_profile_after_ch): Do not sanity check that all
static exits are taken.
(ch_base::copy_headers): Run on all loops.
(pass_ch::process_loop_p): Improve heuristics by handling also
do_while loop and duplicating shortest sequence containing all
winning blocks.

gcc/testsuite/ChangeLog:

* gcc.dg/loop-unswitch-17.c: Disable ch.
* gcc.dg/pr103079.c: Disable ch.
* gcc.dg/tree-ssa/copy-headers-7.c: Update so ch behaves
as expected.
* gcc.dg/tree-ssa/copy-headers.c: Update template.
* gcc.dg/tree-ssa/copy-headers-9.c: New test.
gcc/testsuite/gcc.dg/loop-unswitch-17.c
gcc/testsuite/gcc.dg/pr103079.c
gcc/testsuite/gcc.dg/tree-ssa/copy-headers-7.c
gcc/testsuite/gcc.dg/tree-ssa/copy-headers-9.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/copy-headers.c
gcc/tree-ssa-loop-ch.cc