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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
But maybe the code relies on a positive 'delta' - after all the same issue must
exist for integer typed IVs.  Probably most interesting cases get folded early
in the correct way if they do not iterate.

Given niter_type is unsigned_type_for (type) the use of FLOOR_MOD_EXPR seems
pointless but would be required when doing a signed floor-mod as in the fix.

Note there's


  tree niter_type = TREE_TYPE (step);
  tree mod = fold_build2 (FLOOR_MOD_EXPR, niter_type, *delta, step);
..
  if (integer_nonzerop (mod))
    mod = fold_build2 (MINUS_EXPR, niter_type, step, mod);
..
  mpz_init (mmod);
  wi::to_mpz (wi::to_wide (mod), mmod, UNSIGNED);
  mpz_neg (mmod, mmod);

so there's evidence that 'mod' is assumed to be positive in the end but
'delta' can be effectively signed here.  Note 'step' is the absolute
value of step, it's always (made) positive.

The code has been this way since Zdenek wrote it.

The proposed patch has passed bootstrap & testing (but I believe it's
incomplete).

Reply via email to