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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think the issue is latent on trunk.  The fix should be

diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index b767056aeb0..21e25cabbd2 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -1171,7 +1171,17 @@ number_of_iterations_lt_to_ne (tree type, affine_iv
*iv0, affine_iv *iv1,
                               bool exit_must_be_taken, bounds *bnds)
 {
   tree niter_type = TREE_TYPE (step);
-  tree mod = fold_build2 (FLOOR_MOD_EXPR, niter_type, *delta, step);
+  tree mod;
+  if (POINTER_TYPE_P (type))
+    {
+      /* For pointers both step and delta have to be interpreted signed.  */
+      mod = fold_build2 (FLOOR_MOD_EXPR, ssizetype,
+                        fold_convert (ssizetype, *delta),
+                        fold_convert (ssizetype, step));
+      mod = fold_convert (niter_type, mod);
+    }
+  else
+    mod = fold_build2 (FLOOR_MOD_EXPR, niter_type, *delta, step);
   tree tmod;
   mpz_t mmod;
   tree assumption = boolean_true_node, bound, noloop;

Reply via email to