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

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> ---
static bool
idx_infer_loop_bounds (tree base, tree *idx, void *dta)
{
...
  /* If access is not executed on every iteration, we must ensure that overlow
may
     not make the access valid later.  */
  if (!dominated_by_p (CDI_DOMINATORS, loop->latch, gimple_bb (data->stmt))
      && scev_probably_wraps_p (initial_condition_in_loop_num (ev, loop->num),
                                step, data->stmt, loop, true))
    reliable = false;

  record_nonwrapping_iv (loop, init, step, data->stmt, low, high, reliable,
upper);
  return true;


I think we simply cannot make a bound from a not always executing array ref
reliable, even if the IV doesn't wrap.  And of course the above fails to reset
'upper'.

Testing

Index: gcc/tree-ssa-loop-niter.c
===================================================================
--- gcc/tree-ssa-loop-niter.c   (revision 233598)
+++ gcc/tree-ssa-loop-niter.c   (working copy)
@@ -3183,14 +3183,18 @@ idx_infer_loop_bounds (tree base, tree *
       && tree_int_cst_compare (next, high) <= 0)
     return true;

-  /* If access is not executed on every iteration, we must ensure that overlow
may
-     not make the access valid later.  */
-  if (!dominated_by_p (CDI_DOMINATORS, loop->latch, gimple_bb (data->stmt))
-      && scev_probably_wraps_p (initial_condition_in_loop_num (ev, loop->num),
-                               step, data->stmt, loop, true))
+  /* If access is not executed on every iteration we cannot derive any
+     upper bound.  */
+  if (!dominated_by_p (CDI_DOMINATORS, loop->latch, gimple_bb (data->stmt)))
+    upper = false;
+  /* If the IV of the access may wrap then the array size is not good for
+     an estimate either.  */
+  if (scev_probably_wraps_p (initial_condition_in_loop_num (ev, loop->num),
+                            step, data->stmt, loop, true))
     reliable = false;

-  record_nonwrapping_iv (loop, init, step, data->stmt, low, high, reliable,
upper);
+  record_nonwrapping_iv (loop, init, step, data->stmt, low, high,
+                        reliable, upper);
   return true;
 }

Reply via email to