Commit 9bdb685e by Zdenek Dvorak Committed by Zdenek Dvorak

tree-ssa-loop-niter.c (record_estimate): Add "upper" argument.

	* tree-ssa-loop-niter.c (record_estimate): Add "upper" argument.
	Update constant estimates of number of iterations.
	(record_nonwrapping_iv): Add "upper" argument.  "data_size_bounds_p"
	argument renamed to "realistic".
	(compute_estimated_nb_iterations): Removed.
	(record_niter_bound): New function.
	(idx_infer_loop_bounds): For possible but unlikely tail arrays,
	call record_nonwrapping_iv with upper = false.
	(infer_loop_bounds_from_signedness): Pass upper argument to
	record_nonwrapping_iv.
	(estimate_numbers_of_iterations_loop): Do not call
	compute_estimated_nb_iterations.  Record estimate based on profile
	information.  Initialize the constant estimates of number of
	iterations.
	* tree-data-ref.c (estimated_loop_iterations): Return the recorded
	estimates.
	* tree-ssa-loop-prefetch.c (loop_prefetch_arrays): Add dump when
	number of iterations is too small.
	* cfgloop.h (struct nb_iter_bound): Remove "realistic" field.
	(EST_NOT_AVAILABLE): Removed.
	(struct loop): Replace estimated_nb_iterations by any_upper_bound,
	nb_iterations_upper_bound, any_estimate and nb_iterations_estimate
	fields.

	* gcc.dg/tree-ssa/prefetch-5.c: New test.

From-SVN: r122969
parent d4daf0d6
2007-03-15 Zdenek Dvorak <dvorakz@suse.cz> 2007-03-15 Zdenek Dvorak <dvorakz@suse.cz>
* tree-ssa-loop-niter.c (record_estimate): Add "upper" argument.
Update constant estimates of number of iterations.
(record_nonwrapping_iv): Add "upper" argument. "data_size_bounds_p"
argument renamed to "realistic".
(compute_estimated_nb_iterations): Removed.
(record_niter_bound): New function.
(idx_infer_loop_bounds): For possible but unlikely tail arrays,
call record_nonwrapping_iv with upper = false.
(infer_loop_bounds_from_signedness): Pass upper argument to
record_nonwrapping_iv.
(estimate_numbers_of_iterations_loop): Do not call
compute_estimated_nb_iterations. Record estimate based on profile
information. Initialize the constant estimates of number of
iterations.
* tree-data-ref.c (estimated_loop_iterations): Return the recorded
estimates.
* tree-ssa-loop-prefetch.c (loop_prefetch_arrays): Add dump when
number of iterations is too small.
* cfgloop.h (struct nb_iter_bound): Remove "realistic" field.
(EST_NOT_AVAILABLE): Removed.
(struct loop): Replace estimated_nb_iterations by any_upper_bound,
nb_iterations_upper_bound, any_estimate and nb_iterations_estimate
fields.
2007-03-15 Zdenek Dvorak <dvorakz@suse.cz>
* tree-ssa-loop-niter.c (refine_bounds_using_guard, bound_difference): * tree-ssa-loop-niter.c (refine_bounds_using_guard, bound_difference):
Handle NE_EXPR guards. Handle NE_EXPR guards.
......
...@@ -65,12 +65,6 @@ struct nb_iter_bound ...@@ -65,12 +65,6 @@ struct nb_iter_bound
are executed at most BOUND times. */ are executed at most BOUND times. */
bool is_exit; bool is_exit;
/* True if the bound is "realistic" -- i.e., most likely the loop really has
number of iterations close to the bound. Exact bounds (if the number of
iterations of a loop is a constant) and bounds derived from the size of
data accessed in the loop are considered realistic. */
bool realistic;
/* The next bound in the list. */ /* The next bound in the list. */
struct nb_iter_bound *next; struct nb_iter_bound *next;
}; };
...@@ -148,12 +142,18 @@ struct loop ...@@ -148,12 +142,18 @@ struct loop
{ {
/* Estimate was not computed yet. */ /* Estimate was not computed yet. */
EST_NOT_COMPUTED, EST_NOT_COMPUTED,
/* Estimate was computed, but we could derive no useful bound. */
EST_NOT_AVAILABLE,
/* Estimate is ready. */ /* Estimate is ready. */
EST_AVAILABLE EST_AVAILABLE
} estimate_state; } estimate_state;
double_int estimated_nb_iterations;
/* An integer guaranteed to bound the number of iterations of the loop
from above. */
bool any_upper_bound;
double_int nb_iterations_upper_bound;
/* An integer giving the expected number of iterations of the loop. */
bool any_estimate;
double_int nb_iterations_estimate;
/* Upper bound on number of iterations of a loop. */ /* Upper bound on number of iterations of a loop. */
struct nb_iter_bound *bounds; struct nb_iter_bound *bounds;
......
2007-03-15 Zdenek Dvorak <dvorakz@suse.cz>
* gcc.dg/tree-ssa/prefetch-5.c: New test.
2007-03-15 Manuel Lopez-Ibanez <manu@gcc.gnu.org> 2007-03-15 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/30891 PR c++/30891
/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
/* { dg-require-effective-target ilp32 } */
/* { dg-options "-O2 -fprefetch-loop-arrays -march=athlon -fdump-tree-aprefetch-details" } */
/* These are common idioms for writing variable-length arrays at the end
of structures. We should not deduce anything about the number of iterations
of the loops from them. */
struct tail0
{
int xxx;
int yyy[0];
};
int loop0 (int n, struct tail0 *x)
{
int i, s = 0;
for (i = 0; i < n; i++)
s += x->yyy[i];
return s;
}
struct tail1
{
int xxx;
int yyy[1];
};
int loop1 (int n, struct tail1 *x)
{
int i, s = 0;
for (i = 0; i < n; i++)
s += x->yyy[i];
return s;
}
/* It is unlikely that this should be a tail array. We may deduce that most
likely, the loop iterates about 5 times, and the array is not worth prefetching. */
struct tail5
{
int xxx;
int yyy[5];
};
int loop5 (int n, struct tail5 *x)
{
int i, s = 0;
for (i = 0; i < n; i++)
s += x->yyy[i];
return s;
}
/* { dg-final { scan-tree-dump-times "Issued prefetch" 2 "aprefetch" } } */
/* { dg-final { scan-tree-dump-times "Not prefetching" 1 "aprefetch" } } */
/* { dg-final { cleanup-tree-dump "aprefetch" } } */
...@@ -2556,33 +2556,23 @@ static bool ...@@ -2556,33 +2556,23 @@ static bool
estimated_loop_iterations (struct loop *loop, bool conservative, estimated_loop_iterations (struct loop *loop, bool conservative,
double_int *nit) double_int *nit)
{ {
tree numiter = number_of_exit_cond_executions (loop); estimate_numbers_of_iterations_loop (loop);
if (conservative)
/* If we have an exact value, use it. */
if (TREE_CODE (numiter) == INTEGER_CST)
{ {
*nit = tree_to_double_int (numiter); if (!loop->any_upper_bound)
return true; return false;
}
/* If we have a measured profile and we do not ask for a conservative bound, *nit = loop->nb_iterations_upper_bound;
use it. */
if (!conservative && loop->header->count != 0)
{
*nit = uhwi_to_double_int (expected_loop_iterations (loop) + 1);
return true;
} }
else
/* Finally, try using a reliable estimate on number of iterations according
to the size of the accessed data, if available. */
estimate_numbers_of_iterations_loop (loop);
if (loop->estimate_state == EST_AVAILABLE)
{ {
*nit = loop->estimated_nb_iterations; if (!loop->any_estimate)
return true; return false;
*nit = loop->nb_iterations_estimate;
} }
return false; return true;
} }
/* Similar to estimated_loop_iterations, but returns the estimate only /* Similar to estimated_loop_iterations, but returns the estimate only
......
...@@ -968,7 +968,13 @@ loop_prefetch_arrays (struct loop *loop) ...@@ -968,7 +968,13 @@ loop_prefetch_arrays (struct loop *loop)
the loop rolls at least AHEAD times, prefetching the references does not the loop rolls at least AHEAD times, prefetching the references does not
make sense. */ make sense. */
if (est_niter >= 0 && est_niter <= (HOST_WIDE_INT) ahead) if (est_niter >= 0 && est_niter <= (HOST_WIDE_INT) ahead)
goto fail; {
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file,
"Not prefetching -- loop estimated to roll only %d times\n",
(int) est_niter);
goto fail;
}
ninsns = tree_num_loop_insns (loop, &eni_size_weights); ninsns = tree_num_loop_insns (loop, &eni_size_weights);
unroll_factor = determine_unroll_factor (loop, refs, ninsns, &desc, unroll_factor = determine_unroll_factor (loop, refs, ninsns, &desc,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment