diff options
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/pr27603.c | 16 | ||||
-rw-r--r-- | gcc/tree-ssa-loop-niter.c | 28 |
4 files changed, 42 insertions, 13 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 89ab05e..7e559a4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1c3b1a8..771256a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..8cb0235 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr27603.c @@ -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 (); +} diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index a3c5791..4dd05ea 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -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); } } |