Fix PR23410

Sebastian Pop sebastian.pop@cri.ensmp.fr
Thu Sep 1 15:09:00 GMT 2005


Hi,

This patch fixes PR23410.  Tested on i686 and amd64, committed.  I've
worked on more cleanups for fixing this PR, but I think that these
should wait till 4.2.

	PR tree-optimization/23410
	* tree-ssa-loop-niter.c (scev_probably_wraps_p): Check that the
	sequence is not wrapping during the first step.

Index: tree-ssa-loop-niter.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-niter.c,v
retrieving revision 2.40
diff -d -u -p -r2.40 tree-ssa-loop-niter.c
--- tree-ssa-loop-niter.c	23 Aug 2005 08:15:13 -0000	2.40
+++ tree-ssa-loop-niter.c	1 Sep 2005 09:00:07 -0000
@@ -1823,7 +1823,8 @@ scev_probably_wraps_p (tree type, tree b
   struct nb_iter_bound *bound;
   tree delta, step_abs;
   tree unsigned_type, valid_niter;
-  tree base_plus_step;
+  tree base_plus_step, bpsps;
+  int cps, cpsps;
 
   /* FIXME: The following code will not be used anymore once
      http://gcc.gnu.org/ml/gcc-patches/2005-06/msg02025.html is
@@ -1865,7 +1866,17 @@ scev_probably_wraps_p (tree type, tree b
 
   *unknown_max = false;
   base_plus_step = fold_build2 (PLUS_EXPR, type, base, step);
-  switch (compare_trees (base_plus_step, base))
+  bpsps = fold_build2 (PLUS_EXPR, type, base_plus_step, step);
+  cps = compare_trees (base_plus_step, base);
+  cpsps = compare_trees (bpsps, base_plus_step);
+
+  /* Check that the sequence is not wrapping in the first step: it
+     should have the same monotonicity for the first two steps.  See
+     PR23410.  */
+  if (cps != cpsps)
+    return true;
+
+  switch (cps)
     {
     case -1:
       {



More information about the Gcc-patches mailing list