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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot 
gnu.org

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
So the issue lies with SCEV.  We get

(get_scalar_evolution
  (scalar = _4)
  (scalar_evolution = {-66, +, -97}<nw>_1))

for

  <bb 3> [local count: 955630224]:
  # n.0_44 = PHI <_24(5), 20158(2)>
  # _45 = PHI <_3(5), -66(2)>
  # ivtmp_67 = PHI <ivtmp_66(5), 2(2)
..
  _4 = (int) _45;
..
  n.22_22 = (unsigned short) n.0_44;
  _23 = n.22_22 + 6303;
  _24 = (short int) _23;
..
  _3 = (signed char) _23;
..
  ivtmp_66 = ivtmp_67 - 1;
  if (ivtmp_66 == 0)
    goto <bb 4>; [11.00%]
  else
    goto <bb 5>; [89.00%]

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

with the cycles analyzed to

(set_scalar_evolution 
  instantiated_below = 2 
  (scalar = n.0_44)
  (scalar_evolution = {20158, +, 6303}_1))

(instantiate_scev 
  (instantiate_below = 2 -> 3)
  (evolution_loop = 1)
  (chrec = {93, +, -97}_1)
  (res = {93, +, -97}_1))
Simplify PEELED_CHREC into POLYNOMIAL_CHREC.
  (evolution_function = {-66, +, -97}_1))
(set_scalar_evolution 
  instantiated_below = 2
  (scalar = _45)
  (scalar_evolution = {-66, +, -97}_1))
) 

simplify_peeled_chrec turns {93, +, -97}_1 into {-66, +, -97}_1 with

  left = CHREC_LEFT (ev);
  right = CHREC_RIGHT (ev);
  type = TREE_TYPE (left);
  step_val = chrec_fold_plus (type, init_cond, right);

  /* Transform (init, {left, right}_LOOP)_LOOP to {init, right}_LOOP
     if "left" equals to "init + right".  */
  if (operand_equal_p (left, step_val, 0))
    {
      if (dump_file && (dump_flags & TDF_SCEV))
        fprintf (dump_file, "Simplify PEELED_CHREC into POLYNOMIAL_CHREC.\n");

      return build_polynomial_chrec (loop->num, init_cond, right);
    }

but here init_cond + right overflows (-66 + -97), we get 93(OVF).  The
following "try harder" code does not seem to care about overflow either.

Reply via email to