Hi,

since peeling and version for alignment for VLA modes was introduced
(r16-3065-geee51f9a4b6) we have been seeing a lot of test suite failures
like

 internal compiler error: in apply_scale, at profile-count.h:1187

This is because vect_gen_prolog_loop_niters sets the prolog bound to -1
in case align_in_elems is a non-constant poly_int.
bound - 1 is later used to scale the loop profile in scale_loop_profile
so we try to calculate with an assumed -2 iterations.

This patch sets bound to 0 instead so scale_loop_profile gets passed -1
and won't do anything then.

Regtested on rv64gcv_zvl512b and aarch64 via qemu.

Regards
Robin


gcc/ChangeLog:

        * tree-vect-loop-manip.cc (PROLOG_BOUND_UNKNOWN): Define.
        (vect_gen_prolog_loop_niters): Use.
        (vect_do_peeling): Use.
---
gcc/tree-vect-loop-manip.cc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index 566308f4fe5..578ee82571f 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -2505,6 +2505,8 @@ get_misalign_in_elems (gimple **seq, loop_vec_info 
loop_vinfo)
   the number of elements that fit in the vector.  Therefore, instead of VF we
   use TYPE_VECTOR_SUBPARTS.  */

+#define PROLOG_BOUND_UNKNOWN (0)
+
static tree
vect_gen_prolog_loop_niters (loop_vec_info loop_vinfo,
                             basic_block bb, int *bound)
@@ -2559,7 +2561,7 @@ vect_gen_prolog_loop_niters (loop_vec_info loop_vinfo,
      if (align_in_elems.is_constant (&align_in_elems_c))
        *bound = align_in_elems_c - 1;
      else
-       *bound = -1;
+       *bound = PROLOG_BOUND_UNKNOWN;
    }

  if (dump_enabled_p ())
@@ -3257,7 +3259,7 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, 
tree nitersm1,
  /* Generate the number of iterations for the prolog loop.  We do this here
     so that we can also get the upper bound on the number of iterations.  */
  tree niters_prolog;
-  int bound_prolog = 0;
+  int bound_prolog = PROLOG_BOUND_UNKNOWN;
  if (prolog_peeling)
    {
      niters_prolog = vect_gen_prolog_loop_niters (loop_vinfo, anchor,
--
2.50.0

Reply via email to