]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix profile update after vectorize loop versioning
authorJan Hubicka <jh@suse.cz>
Sat, 29 Jul 2023 06:18:18 +0000 (08:18 +0200)
committerJan Hubicka <jh@suse.cz>
Sat, 29 Jul 2023 06:18:18 +0000 (08:18 +0200)
Vectorizer while loop versioning produces a versioned loop
guarded with two conditionals of the form

  if (cond1)
    goto scalar_loop
  else
    goto next_bb
next_bb:
  if (cond2)
    godo scalar_loop
  else
    goto vector_loop

It wants the combined test to be prob (whch is set to likely)
and uses profile_probability::split to determine probability
of cond1 and cond2.

However spliting  is turning:

     if (cond)
       goto lab; // ORIG probability
 into
     if (cond1)
       goto lab; // FIRST = ORIG * CPROB probability
     if (cond2)
       goto lab; // SECOND probability

Which is or instead of and.  As a result we get pretty low probabiility
of entering vectorized loop.

The fixes this by introducing sqrt to profile probability (which is correct
way to split this) and also adding pow that is needed elsewhere.

While loop versioning I now produce code as if there was only one combined
conditional and then update probability of conditional produced (containig
cond1).  Later edge is split and new conditional is added. At that time
it is necessary to update probability of the BB containing second conditional
so everything matches.

gcc/ChangeLog:

* profile-count.cc (profile_probability::sqrt): New member function.
(profile_probability::pow): Likewise.
* profile-count.h: (profile_probability::sqrt): Declare
(profile_probability::pow): Likewise.
* tree-vect-loop-manip.cc (vect_loop_versioning): Fix profile update.


No differences found