Fix profile update in scale_profile_for_vect_loop
commit061f74c06735e1fa35b910ae0bcf01b61a74ec23
authorJan Hubicka <jh@suse.cz>
Sun, 16 Jul 2023 21:56:59 +0000 (16 23:56 +0200)
committerJan Hubicka <jh@suse.cz>
Sun, 16 Jul 2023 21:56:59 +0000 (16 23:56 +0200)
treec9431540893df6dc037aa5a14372d2235407c94c
parentc62791fa413a49fc6476ce186b324250f8ae6d40
Fix profile update in scale_profile_for_vect_loop

When vectorizing 4 times, we sometimes do
  for
    <4x vectorized body>
  for
    <2x vectorized body>
  for
    <1x vectorized body>

Here the second two fors handling epilogue never iterates.
Currently vecotrizer thinks that the middle for itrates twice.
This turns out to be scale_profile_for_vect_loop that uses
niter_for_unrolled_loop.

At that time we know epilogue will iterate at most 2 times
but niter_for_unrolled_loop does not know that the last iteration
will be taken by the epilogue-of-epilogue and thus it think
that the loop may iterate once and exit in middle of second
iteration.

We already do correct job updating niter bounds and this is
just ordering issue.  This patch makes us to first update
the bounds and then do updating of the loop.  I re-implemented
the function more correctly and precisely.

The loop reducing iteration factor for overly flat profiles is bit funny, but
only other method I can think of is to compute sreal scale that would have
similar overhead I think.

Bootstrapped/regtested x86_64-linux, will commit it shortly.

gcc/ChangeLog:

PR middle-end/110649
* tree-vect-loop.cc (scale_profile_for_vect_loop): Rewrite.
(vect_transform_loop): Move scale_profile_for_vect_loop after
upper bound updates.
gcc/tree-vect-loop.cc