re PR tree-optimization/30730 (-Wunsafe-loop-optimizations gives too many warnings)

PR tree-optimization/30730
	PR tree-optimization/26900
	* tree-ssa-loop-niter.c: Include gmp.h.
	(bounds): New type.
	(mpz_set_double_int, get_type_bounds, mpz_to_double_int,
	split_to_var_and_offset, determine_value_range,
	bound_difference_of_offsetted_base, refine_bounds_using_guard,
	bound_difference, bounds_add, bounds_negate,
	number_of_iterations_ne_max, dump_affine_iv): New functions.
	(number_of_iterations_ne, number_of_iterations_lt_to_ne,
	assert_loop_rolls_lt, assert_loop_rolls_le): Use bounds on the
	difference of initial and final value of control iv to validate
	results.
	(number_of_iterations_cond): Add loop parameter.  Determine bounds
	on the difference of the extremes of the control iv.  Add dumps.
	(expand_simple_operations): Handle phi nodes.
	(simplify_using_initial_conditions): Do not record used conditions.
	(number_of_iterations_exit): Pass loop to number_of_iterations_cond.
	Do not set additional_info.
	(implies_nonnegative_p, implies_ge_p): Removed.
	(derive_constant_upper_bound): Do not use parameter `additional'.
	(record_estimate): Parameter `additional' removed.  Parameter
	`i_bound' added.  Do not call derive_constant_upper_bound.
	(record_nonwrapping_iv): Use derive_constant_upper_bound to
	bound the number of iterations estimate.
	(estimate_numbers_of_iterations_loop): Pass the estimate from
	the number of iterations analysis to record_estimate.
	* tree.h (multiple_of_p): Declare.
	* tree-scalar-evolution.c (expression_expensive_p): Removed.
	(scev_const_prop): Do not check expression_expensive_p.
	* fold-const.c (multiple_of_p): Exported.
	* double-int.c (double_int_mask): Exported.
	* double-int.h (double_int_mask): Declare.
	* tree-flow.h (struct tree_niter_desc): Removed additional_info
	field.  Added max field.

	* gcc.dg/tree-ssa/loop-26.c: New test.

From-SVN: r122896
This commit is contained in:
Zdenek Dvorak 2007-03-14 00:38:34 +00:00
parent ec34c4e4c0
commit b3ce5b6ed7
9 changed files with 919 additions and 165 deletions

View File

@ -1,3 +1,41 @@
2007-03-13 Zdenek Dvorak <dvorakz@suse.cz>
PR tree-optimization/30730
PR tree-optimization/26900
* tree-ssa-loop-niter.c: Include gmp.h.
(bounds): New type.
(mpz_set_double_int, get_type_bounds, mpz_to_double_int,
split_to_var_and_offset, determine_value_range,
bound_difference_of_offsetted_base, refine_bounds_using_guard,
bound_difference, bounds_add, bounds_negate,
number_of_iterations_ne_max, dump_affine_iv): New functions.
(number_of_iterations_ne, number_of_iterations_lt_to_ne,
assert_loop_rolls_lt, assert_loop_rolls_le): Use bounds on the
difference of initial and final value of control iv to validate
results.
(number_of_iterations_cond): Add loop parameter. Determine bounds
on the difference of the extremes of the control iv. Add dumps.
(expand_simple_operations): Handle phi nodes.
(simplify_using_initial_conditions): Do not record used conditions.
(number_of_iterations_exit): Pass loop to number_of_iterations_cond.
Do not set additional_info.
(implies_nonnegative_p, implies_ge_p): Removed.
(derive_constant_upper_bound): Do not use parameter `additional'.
(record_estimate): Parameter `additional' removed. Parameter
`i_bound' added. Do not call derive_constant_upper_bound.
(record_nonwrapping_iv): Use derive_constant_upper_bound to
bound the number of iterations estimate.
(estimate_numbers_of_iterations_loop): Pass the estimate from
the number of iterations analysis to record_estimate.
* tree.h (multiple_of_p): Declare.
* tree-scalar-evolution.c (expression_expensive_p): Removed.
(scev_const_prop): Do not check expression_expensive_p.
* fold-const.c (multiple_of_p): Exported.
* double-int.c (double_int_mask): Exported.
* double-int.h (double_int_mask): Declare.
* tree-flow.h (struct tree_niter_desc): Removed additional_info
field. Added max field.
2007-03-13 David Taylor <taylor@candd.org>
PR driver/12448:

View File

@ -26,7 +26,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
/* Returns mask for PREC bits. */
static inline double_int
double_int
double_int_mask (unsigned prec)
{
unsigned HOST_WIDE_INT m;

View File

@ -134,6 +134,7 @@ void dump_double_int (FILE *, double_int, bool);
double_int double_int_ext (double_int, unsigned, bool);
double_int double_int_sext (double_int, unsigned);
double_int double_int_zext (double_int, unsigned);
double_int double_int_mask (unsigned);
#define ALL_ONES (~((unsigned HOST_WIDE_INT) 0))

View File

@ -1,3 +1,7 @@
2007-03-13 Zdenek Dvorak <dvorakz@suse.cz>
* gcc.dg/tree-ssa/loop-26.c: New test.
2007-03-13 Uros Bizjak <ubizjak@gmail.com>
* testsuite/gcc.target/i386/cmpxchg16b-1.c: New test.
@ -10,13 +14,13 @@
2007-03-12 Seongbae Park <seongbae.park@gmail.com>
* gcc.dg/wvla-1.c: New test
* gcc.dg/wvla-2.c: New test
* gcc.dg/wvla-3.c: New test
* gcc.dg/wvla-4.c: New test
* gcc.dg/wvla-5.c: New test
* gcc.dg/wvla-6.c: New test
* gcc.dg/wvla-7.c: New test
* gcc.dg/wvla-1.c: New test
* gcc.dg/wvla-2.c: New test
* gcc.dg/wvla-3.c: New test
* gcc.dg/wvla-4.c: New test
* gcc.dg/wvla-5.c: New test
* gcc.dg/wvla-6.c: New test
* gcc.dg/wvla-7.c: New test
* g++.dg/warn/Wvla-1.C: New test
* g++.dg/warn/Wvla-2.C: New test
* g++.dg/warn/Wvla-3.C: New test

View File

@ -0,0 +1,29 @@
/* PR 30730, PR 26900, number of iterations analysis should be able to
determine number of iterations of the following loops unconditionally. */
/* { dg-do compile } */
/* { dg-options "-O -fstrict-overflow -fdump-tree-empty" } */
unsigned foo(unsigned int n)
{
unsigned x = 0;;
while (n > 10)
{
n -= 2;
x++;
}
return x;
}
int foo0(int i0, int i1)
{
int i, j = 0;
for (i=i0; i<=i1+1; ++i)
++j;
return j;
}
/* { dg-final { scan-tree-dump-times "Removing empty loop" 2 "empty" } } */
/* { dg-final { cleanup-tree-dump "empty" } } */

View File

@ -822,18 +822,8 @@ struct tree_niter_desc
a loop (provided that assumptions == true and
may_be_zero == false), more precisely the number
of executions of the latch of the loop. */
tree additional_info; /* The boolean expression. Sometimes we use additional
knowledge to simplify the other expressions
contained in this structure (for example the
knowledge about value ranges of operands on entry to
the loop). If this is a case, conjunction of such
condition is stored in this field, so that we do not
lose the information: for example if may_be_zero
is (n <= 0) and niter is (unsigned) n, we know
that the number of iterations is at most
MAX_SIGNED_INT. However if the (n <= 0) assumption
is eliminated (by looking at the guard on entry of
the loop), then the information would be lost. */
double_int max; /* The upper bound on the number of iterations of
the loop. */
/* The simplified shape of the exit condition. The loop exits if
CONTROL CMP BOUND is false, where CMP is one of NE_EXPR,

View File

@ -2864,14 +2864,6 @@ scev_finalize (void)
BITMAP_FREE (already_instantiated);
}
/* Returns true if EXPR looks expensive. */
static bool
expression_expensive_p (tree expr)
{
return force_expr_to_var_cost (expr) >= target_spill_cost;
}
/* Replace ssa names for that scev can prove they are constant by the
appropriate constants. Also perform final value replacement in loops,
in case the replacement expressions are cheap.
@ -2958,10 +2950,13 @@ scev_const_prop (void)
continue;
niter = number_of_latch_executions (loop);
if (niter == chrec_dont_know
/* If computing the number of iterations is expensive, it may be
better not to introduce computations involving it. */
|| expression_expensive_p (niter))
/* We used to check here whether the computation of NITER is expensive,
and avoided final value elimination if that is the case. The problem
is that it is hard to evaluate whether the expression is too
expensive, as we do not know what optimization opportunities the
the elimination of the final value may reveal. Therefore, we now
eliminate the final values of induction variables unconditionally. */
if (niter == chrec_dont_know)
continue;
/* Ensure that it is possible to insert new statements somewhere. */

File diff suppressed because it is too large Load Diff

View File

@ -4481,6 +4481,7 @@ extern enum tree_code invert_tree_comparison (enum tree_code, bool);
extern bool tree_expr_nonzero_p (tree);
extern bool tree_expr_nonzero_warnv_p (tree, bool *);
extern int multiple_of_p (tree, tree, tree);
/* In builtins.c */
extern tree fold_call_expr (tree, bool);