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

--- Comment #12 from amker at gcc dot gnu.org ---
ICE is because prologue peeling changes code (to be specific, the initial
argument of reduction phi node in loop header), as a result, the statement to
be vectorized is not the statement that was previously analyzed.
One possible fix is be conservative and fall back to generic conditional
reduction if loop needs to be peeled for prologue.  Another (better) fix is we
don't update/inherit reduction value from prologue loop for vectorized loop,
and after vectorized loop, we combine the result manually.  Code would be like:

prolog_loop:
  c_1 = PHI<c_2, 0>
  c_2 = (cond) ? 1 : c_1;
  if (prolog_cond)  goto prolog_header
  else              goto prolog_exit

prolog_exit:
  c_3 = PHI<c_2>;

vector_loop:
  c_4 = PHI<c_5, 0>;
  c_5 = (cond) ? 1 : c_4
  if (vector_cond) goto vector_header
  else             goto vector_exit

vector_exit:
  c_6 = PHI<c_5>;
  c_7 = (c_3 == 1 || c_5 == 1) ? 1 : 0;

We need to change how loop peeling updates SSA(PHI) nodes.  Since I have other
patches rewriting loop peeling, better to check this method after loop peeling
patches.  For now, I think we'd better go with the first method which disables
the optimization in peeling cases.

Reply via email to