The following fixes the new capability of analyzing a wrapping IV as
non-wrapping under a condition that ensures we do not wrap by
restricting it to the case where the exit test must be executed
when it reaches that bound.  Otherwise we may not analyze the
IV with the assumption that the exit test triggers exactly once.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2018-04-09  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/85284
        * tree-ssa-loop-niter.c (number_of_iterations_exit_assumptions):
        Only use the niter constraining form of simple_iv when the exit
        is always executed.

        * gcc.dg/torture/pr85284.c: New testcase.

Index: gcc/tree-ssa-loop-niter.c
===================================================================
--- gcc/tree-ssa-loop-niter.c   (revision 259227)
+++ gcc/tree-ssa-loop-niter.c   (working copy)
@@ -2356,11 +2356,11 @@ number_of_iterations_exit_assumptions (s
 
   tree iv0_niters = NULL_TREE;
   if (!simple_iv_with_niters (loop, loop_containing_stmt (stmt),
-                             op0, &iv0, &iv0_niters, false))
+                             op0, &iv0, safe ? &iv0_niters : NULL, false))
     return false;
   tree iv1_niters = NULL_TREE;
   if (!simple_iv_with_niters (loop, loop_containing_stmt (stmt),
-                             op1, &iv1, &iv1_niters, false))
+                             op1, &iv1, safe ? &iv1_niters : NULL, false))
     return false;
   /* Give up on complicated case.  */
   if (iv0_niters && iv1_niters)
Index: gcc/testsuite/gcc.dg/torture/pr85284.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr85284.c      (nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr85284.c      (working copy)
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+
+static int p[48], v;
+
+int
+main ()
+{
+  p[32] = 1;
+  for (int i = 48; i--;)
+    {
+      if (!p[i])
+       continue;
+      if ((i & 7) > 2)
+       break;
+      v = i & 1;
+    }
+  if (v != 0)
+    __builtin_abort ();
+  return 0;
+}

Reply via email to