https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113808

Tamar Christina <tnfchris at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |tnfchris at gcc dot 
gnu.org

--- Comment #9 from Tamar Christina <tnfchris at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #6)
> With the following I don't see things going wrong, but we end up with the
> loop
> having the STOP exit last instead and thus a PEELED case.

If it's not a PEELED case than the code is wrong indeed.

  _100 = BIT_FIELD_REF <vect_vec_iv_.27_99, 32, 0>;
  k.4_43 = _100;

is wrong since for a normal case the primary exit needs to do a last reduction
rather than a first.

  _109 = BIT_FIELD_REF <vect__19.29_108, 32, 96>;
  _48 = _109;
  _100 = BIT_FIELD_REF <vect_vec_iv_.27_99, 32, 0>;
  k.4_43 = _100;

these two reduction orders should never be different.

The bug seems to be in vectorizable_live_operations where we determine if the
index needs to be a first or last reduction.

There's a boolean there

restart_loop = restart_loop || !main_exit_edge;

and we initially set it to

bool restart_loop = LOOP_VINFO_EARLY_BREAKS_VECT_PEELED (loop_vinfo);

outside the USE/DEF loop.

The problem is this depends on seeing the uses for the LOOP_VINFO_IV_EXIT
before seeing that of the early exits.

The code goes wrong because we see the early exit first and then see the main
exit, but once true the boolean can't become false again.

it's a silly bug, the boolean shouldn't be cached between loop iters.

quick hack:

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 190df9ec774..109a7e16abb 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -10966,7 +10966,7 @@ vectorizable_live_operation (vec_info *vinfo,
stmt_vec_info stmt_info,
              /* For early exit where the exit is not in the BB that leads
                 to the latch then we're restarting the iteration in the
                 scalar loop.  So get the first live value.  */
-             restart_loop = restart_loop || !main_exit_edge;
+             restart_loop = !main_exit_edge;
              if (restart_loop
                  && STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def)
                {

works but will revisit this and fix properly now.

Thanks for the reduction.

Reply via email to