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

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #5)
> int foo (int *p, unsigned long sz)
> {
>   int sum = 0;
>   for (unsigned i = 0; i < sz; ++i)
>     sum += p[i];
>   return sum;
> }
> 
> is a simpler variant.  What works is that we set up to version the loop
> with sz_7(D) + 18446744073709551615 <= 4294967294 and do
> loop_constraint_set (loop, LOOP_C_FINITE), but that is not enough to make
> SCEV analysis succeed for the DR (so we get a gather) or analyze the
> index PHI in the induction defining the supposed gather index:
> 
> t.c:4:26: note:   Analyze phi: _15 = PHI <_4(6), 0(5)>
> t.c:4:26: missed:   reduction used in loop.
> t.c:4:26: missed:   Unknown def-use cycle pattern.
> ...
> t.c:4:26: note:   worklist: examine stmt: _1 = _15 * 4;
> t.c:4:26: note:   vect_is_simple_use: operand _15 = PHI <_4(6), 0(5)>, type
> of def: unknown
> t.c:4:26: missed:   Unsupported pattern.
> t.c:5:13: missed:   not vectorized: unsupported use in stmt.
> t.c:4:26: missed:  unexpected pattern.
> 
> I will see to fix this on the SCEV side.

So for this particular case where we have

  <bb 3> [local count: 955630224]:
  # _15 = PHI <_4(6), 0(5)>
  # sum_16 = PHI <sum_10(6), 0(5)>
  # i_18 = PHI <i_11(6), 0(5)>
  _1 = _15 * 4;
  _2 = p_9(D) + _1;
  _3 = *_2;
  sum_10 = _3 + sum_16;
  i_11 = i_18 + 1;
  _4 = (long unsigned int) i_11;
  if (_4 < sz_7(D))

_15 is a recurrence that fails to analyze in SCEV DFS because of the
widening conversion.  Eliding this IV as

  <bb 3> [local count: 955630224]:
  # sum_16 = PHI <sum_10(6), 0(5)>
  # i_18 = PHI <i_11(6), 0(5)>
  _15 = (long unsigned int) i_18;
  _1 = _15 * 4;
  _2 = p_9(D) + _1;
  _3 = *_2;
  sum_10 = _3 + sum_16;
  i_11 = i_18 + 1;
  _4 = (long unsigned int) i_11;
  if (_4 < sz_7(D))
    goto <bb 6>; [89.00%]

would avoid this particular issue.

But it's possible to enhance simplify_peeled_chrec to handle this situation.
This helps up to epilogue peeling which needs to handle "derived IVs" as well.

Reply via email to