]> git.ipfire.org Git - thirdparty/gcc.git/commit
Improve scale_loop_profile
authorJan Hubicka <jh@suse.cz>
Thu, 6 Jul 2023 16:51:02 +0000 (18:51 +0200)
committerJan Hubicka <jh@suse.cz>
Thu, 6 Jul 2023 16:51:02 +0000 (18:51 +0200)
commitd4c2e34deef8cbd81ba2ef3389fdbaf95c70e225
tree217bd3c15439fe3fff1a78d16dd31f8148404e8b
parent224fd59b2dc8a5fa78a309a09863afe9b3cf2111
Improve scale_loop_profile

Original scale_loop_profile was implemented to only handle very simple loops
produced by vectorizer at that time (basically loops with only one exit and no
subloops). It also has not been updated to new profile-count API very carefully.

The function does two thigs
 1) scales down the loop profile by a given probability.
    This is useful, for example, to scale down profile after peeling when loop
    body is executed less often than before
 2) update profile to cap iteration count by ITERATION_BOUND parameter.

I changed ITERATION_BOUND to be actual bound on number of iterations as
used elsewhere (i.e. number of executions of latch edge) rather then
number of iterations + 1 as it was before.

To do 2) one needs to do the following
  a) scale own loop profile so frquency o header is at most
     the sum of in-edge counts * (iteration_bound + 1)
  b) update loop exit probabilities so their count is the same
     as before scaling.
  c) reduce frequencies of basic blocks after loop exit

old code did b) by setting probability to 1 / iteration_bound which is
correctly only of the basic block containing exit executes precisely one per
iteration (it is not insie other conditional or inner loop).  This is fixed
now by using set_edge_probability_and_rescale_others

aldo c) was implemented only for special case when the exit was just before
latch bacis block.  I now use dominance info to get right some of addional
case.

I still did not try to do anything for multiple exit loops, though the
implementatoin could be generalized.

Bootstrapped/regtested x86_64-linux.  Plan to cmmit it tonight if there
are no complains.

gcc/ChangeLog:

* cfgloopmanip.cc (scale_loop_profile): Rewrite exit edge
probability update to be safe on loops with subloops.
Make bound parameter to be iteration bound.
* tree-ssa-loop-ivcanon.cc (try_peel_loop): Update call
of scale_loop_profile.
* tree-vect-loop-manip.cc (vect_do_peeling): Likewise.
gcc/cfgloopmanip.cc
gcc/tree-ssa-loop-ivcanon.cc
gcc/tree-vect-loop-manip.cc