re PR tree-optimization/27603 (wrong code, apparently due to bad VRP (-O2))
authorRichard Guenther <rguenther@suse.de>
Mon, 15 May 2006 17:35:48 +0000 (17:35 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 15 May 2006 17:35:48 +0000 (17:35 +0000)
2006-05-15  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/27603
* tree-ssa-loop-niter.c (infer_loop_bounds_from_undefined):
Do computations in original type.

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

From-SVN: r113797

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr27603.c [new file with mode: 0644]
gcc/tree-ssa-loop-niter.c

index 89ab05e32c48ed66b188e6b1b6c45ebf9ea44dd1..7e559a4ce8a5e7f812320f1bc63016979e6441c0 100644 (file)
@@ -1,3 +1,9 @@
+2006-05-15  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/27603
+       * tree-ssa-loop-niter.c (infer_loop_bounds_from_undefined):
+       Do computations in original type.
+
 2006-05-15  Mircea Namolaru  <namolaru@il.ibm.com>
 
         * see.c: Code style changes such as redundant paranthesis,
index 1c3b1a85bf0b5ff726288ef882ff8985aab539ad..771256a464f2b620c50d5f1a7761002e0ea13a1a 100644 (file)
@@ -1,3 +1,8 @@
+2006-05-15  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/27603
+       * gcc.dg/torture/pr27603.c: New testcase.
+
 2006-05-15  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/25090
diff --git a/gcc/testsuite/gcc.dg/torture/pr27603.c b/gcc/testsuite/gcc.dg/torture/pr27603.c
new file mode 100644 (file)
index 0000000..8cb0235
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do run } */
+
+void exit (int);
+void abort (void);
+int a;
+int main()
+{
+  int j;
+  for (j = 0; j < 6; j++)
+  {
+    if ((unsigned)j - 3 <= 1)
+      exit (0);
+    a = 1000 * (6 - j);
+  }
+  abort ();
+}
index a3c5791208fe7ca1d08e4b5767a0a2fb333c6b2a..4dd05ea6d169728105cfa43da933401248c0d6fd 100644 (file)
@@ -1587,7 +1587,6 @@ infer_loop_bounds_from_undefined (struct loop *loop)
                    tree scev = instantiate_parameters 
                      (loop, analyze_scalar_evolution (loop, op0));
                    tree type = chrec_type (scev);
-                   tree utype;
 
                    if (chrec_contains_undetermined (scev)
                        || TYPE_UNSIGNED (type))
@@ -1604,20 +1603,23 @@ infer_loop_bounds_from_undefined (struct loop *loop)
                        || TYPE_MAX_VALUE (type) == NULL_TREE)
                      break;
 
-                   utype = unsigned_type_for (type);
-                   if (tree_int_cst_lt (step, integer_zero_node))
-                     diff = fold_build2 (MINUS_EXPR, utype, init,
-                                         TYPE_MIN_VALUE (type));
-                   else
-                     diff = fold_build2 (MINUS_EXPR, utype,
-                                         TYPE_MAX_VALUE (type), init);
-
-                   if (!integer_zerop (step))
+                   if (integer_nonzerop (step))
                      {
-                       estimation = fold_build2 (CEIL_DIV_EXPR, utype, diff,
+                       tree utype;
+
+                       if (tree_int_cst_lt (step, integer_zero_node))
+                         diff = fold_build2 (MINUS_EXPR, type, init,
+                                             TYPE_MIN_VALUE (type));
+                       else
+                         diff = fold_build2 (MINUS_EXPR, type,
+                                             TYPE_MAX_VALUE (type), init);
+
+                       utype = unsigned_type_for (type);
+                       estimation = fold_build2 (CEIL_DIV_EXPR, type, diff,
                                                  step);
-                       record_estimate (loop, estimation, boolean_true_node,
-                                        stmt);
+                       record_estimate (loop,
+                                        fold_convert (utype, estimation),
+                                        boolean_true_node, stmt);
                      }
                  }