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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
    # of iterations (a_lsm.5_10 * 52) / 52, bounded by 63

is obviously wrong with a_lsm.5_10 being a 'char', that boils down to zero
iterations when computed at runtime.  The loop body looks like

  <bb 3> [local count: 1073741824]:
  # a_3 = PHI <a_5(2), a_6(5)>
d:
  a_6 = a_3 + 255;
  c_7 = a_3 * 52;
  if (c_7 != 0)
    goto <bb 5>; [89.00%]
  else
    goto <bb 4>; [11.00%]

  <bb 5> [local count: 955630224]:
  goto <bb 3>; [100.00%]

and SCEV computes

  (scalar = c_7)
  (scalar_evolution = {a_5 * 52, +, 204}_1))

which looks correct.

niter compute does

static bool
number_of_iterations_ne (class loop *loop, tree type, affine_iv *iv,
                         tree final, class tree_niter_desc *niter,
                         bool exit_must_be_taken, bounds *bnds)
{                       
...
  /* Compute no-overflow information for the control iv.  This can be
     proven when below two conditions are satisfied: 

       1) IV evaluates toward FINAL at beginning, i.e:
            base <= FINAL ; step > 0
            base >= FINAL ; step < 0

       2) |FINAL - base| is an exact multiple of step.
...
  if (!niter->control.no_overflow
      && (integer_onep (s) || multiple_of_p (type, c, s)))
    {

and there we have the issue of multiple_of_p not handling overflow (there's
a duplicate bug, PR100499 about this issue).  The 1) condition ends up
as unsigned-val >= 0 which is trivially true.

Reply via email to