]> git.ipfire.org Git - thirdparty/gcc.git/commit
Improve profile update in loop-ch
authorJan Hubicka <jh@suse.cz>
Wed, 12 Jul 2023 15:22:03 +0000 (17:22 +0200)
committerJan Hubicka <jh@suse.cz>
Wed, 12 Jul 2023 15:22:03 +0000 (17:22 +0200)
commit14b10ff30ad58265c5acd495c3b0e56563571b0c
tree3939306bcc9c6d3d696ae54ef0e265a2f4aec8bb
parent5a13caf2666bdf586272cc24a08ab90499771c95
Improve profile update in loop-ch

Improve profile update in loop-ch to handle situation where duplicated header
has loop invariant test.  In this case we konw that all count of the exit edge belongs to
the duplicated loop header edge and can update probabilities accordingly.
Since we also do all the work to track this information from analysis to duplicaiton
I also added code to turn those conditionals to constants so we do not need later
jump threading pass to clean up.

This made me to work out that the propagation was buggy in few aspects
 1) it handled every PHI as PHI in header and incorrectly assigned some PHIs
    to be IV-like when they are not
 2) it did not check for novops calls that are not required to return same
    value on every invocation.
 3) I also added check for asm statement since those are not necessarily
    reproducible either.

I would like to do more changes, but tried to prevent this patch from
snowballing.  The analysis of what statements will remain after duplication can
be improved.  I think we should use ranger query for other than first basic
block, too and possibly drop the IV heuristics then.  Also it seems that a lot
of this logic is pretty much same to analysis in peeling pass, so unifying this
would be nice.

I also think I should move the profile update out of
gimple_duplicate_sese_region (it is now very specific to ch) and rename it,
since those regions are singe entry multiple exit.

Bootstrapped/regtsted x86_64-linux, OK?

Honza

gcc/ChangeLog:

* tree-cfg.cc (gimple_duplicate_sese_region): Add ORIG_ELIMINATED_EDGES
parameter and rewrite profile updating code to handle edges elimination.
* tree-cfg.h (gimple_duplicate_sese_region): Update prototpe.
* tree-ssa-loop-ch.cc (loop_invariant_op_p): New function.
(loop_iv_derived_p): New function.
(should_duplicate_loop_header_p): Track invariant exit edges; fix handling
of PHIs and propagation of IV derived variables.
(ch_base::copy_headers): Pass around the invariant edges hash set.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/loop-ch-profile-1.c: Remove xfail.
gcc/testsuite/gcc.dg/tree-ssa/loop-ch-profile-1.c
gcc/tree-cfg.cc
gcc/tree-cfg.h
gcc/tree-ssa-loop-ch.cc