Bah, bounced due to html or something. My latest email client upgrade
must have lost the 'plain text only' attribute..
On 10/16/2013 08:02 AM, Andrew MacLeod wrote:
More or less the same patch that I put in bugzilla
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58697
I've bootstrapped it and run it through regressions. Jakubs test case
fails again like it did before my changes, so it no longer masks the
problem.
Loop unswitching was calling estimate_loop_iterations_int, which for
various annoying reasons ended up in cfgloop and called
get_estimate_loop_iterations, so it wasn't doing the calculations.
Hopefully its clearer now.
The end result now is that cfgloop.c has 4 accessor routines which
just retrieve info:
get_estimated_loop_iterations, get_estimated_loop_iterations_int,
get_max_loop_iterations, and get_max_loop_iterations_int.
tree-ssa-loop-niter.c has 4 routines which create the information
first, if they can, then retrieve the information.
estimated_loop_iterations, estimated_loop_iterations_int,
max_loop_iterations, and max_loop_iterations_int.
all the cfg* routines call the 'get_' variety, and all the tree-ssa
routines call the non 'get_' variety to calculate things if need be.
Bootstraps on x86_64-unknown-linux-gnu and no regressions. OK? I
presume Jakub's test case isn't in the testsuite anywhere then? I
presume it would go in along with a fix to the original problem
Andrew
* cfgloop.c (get_estimated_loop_iterations_int): Rename from
estimated_loop_iterations_int.
(max_stmt_executions_int): Call get_max_loop_iterations_int.
(get_max_loop_iterations_int): New. HWINT version of
get_max_loop_iterations.
* cfgloop.h: Add prototypes.
* loop-iv.c (find_simple_exit): call get_estimated_loop_iterations_int.
* loop-unroll.c (decide_peel_once_rolling): Call
get_estimated_loop_iterations_int.
* tree-ssa-loop-niter.c (estimated_loop_iterations_int): Add back.
* tree-ssa-loop-niter.h: Tweak prototypes.
Index: cfgloop.c
===================================================================
*** cfgloop.c (revision 203625)
--- cfgloop.c (working copy)
*************** record_niter_bound (struct loop *loop, d
*** 1815,1826 ****
loop->nb_iterations_estimate = loop->nb_iterations_upper_bound;
}
! /* Similar to estimated_loop_iterations, but returns the estimate only
if it fits to HOST_WIDE_INT. If this is not the case, or the estimate
on the number of iterations of LOOP could not be derived, returns -1. */
HOST_WIDE_INT
! estimated_loop_iterations_int (struct loop *loop)
{
double_int nit;
HOST_WIDE_INT hwi_nit;
--- 1815,1826 ----
loop->nb_iterations_estimate = loop->nb_iterations_upper_bound;
}
! /* Similar to get_estimated_loop_iterations, but returns the estimate only
if it fits to HOST_WIDE_INT. If this is not the case, or the estimate
on the number of iterations of LOOP could not be derived, returns -1. */
HOST_WIDE_INT
! get_estimated_loop_iterations_int (struct loop *loop)
{
double_int nit;
HOST_WIDE_INT hwi_nit;
*************** estimated_loop_iterations_int (struct lo
*** 1842,1848 ****
HOST_WIDE_INT
max_stmt_executions_int (struct loop *loop)
{
! HOST_WIDE_INT nit = max_loop_iterations_int (loop);
HOST_WIDE_INT snit;
if (nit == -1)
--- 1842,1848 ----
HOST_WIDE_INT
max_stmt_executions_int (struct loop *loop)
{
! HOST_WIDE_INT nit = get_max_loop_iterations_int (loop);
HOST_WIDE_INT snit;
if (nit == -1)
*************** get_max_loop_iterations (struct loop *lo
*** 1891,1893 ****
--- 1891,1915 ----
*nit = loop->nb_iterations_upper_bound;
return true;
}
+
+ /* Similar to get_max_loop_iterations, but returns the estimate only
+ if it fits to HOST_WIDE_INT. If this is not the case, or the estimate
+ on the number of iterations of LOOP could not be derived, returns -1. */
+
+ HOST_WIDE_INT
+ get_max_loop_iterations_int (struct loop *loop)
+ {
+ double_int nit;
+ HOST_WIDE_INT hwi_nit;
+
+ if (!get_max_loop_iterations (loop, &nit))
+ return -1;
+
+ if (!nit.fits_shwi ())
+ return -1;
+ hwi_nit = nit.to_shwi ();
+
+ return hwi_nit < 0 ? -1 : hwi_nit;
+ }
+
+
Index: cfgloop.h
===================================================================
*** cfgloop.h (revision 203625)
--- cfgloop.h (working copy)
*************** loop_outermost (struct loop *loop)
*** 740,747 ****
}
extern void record_niter_bound (struct loop *, double_int, bool, bool);
! extern HOST_WIDE_INT estimated_loop_iterations_int (struct loop *);
! extern HOST_WIDE_INT max_loop_iterations_int (struct loop *);
extern bool get_estimated_loop_iterations (struct loop *loop, double_int *nit);
extern bool get_max_loop_iterations (struct loop *loop, double_int *nit);
--- 740,747 ----
}
extern void record_niter_bound (struct loop *, double_int, bool, bool);
! extern HOST_WIDE_INT get_estimated_loop_iterations_int (struct loop *);
! extern HOST_WIDE_INT get_max_loop_iterations_int (struct loop *);
extern bool get_estimated_loop_iterations (struct loop *loop, double_int *nit);
extern bool get_max_loop_iterations (struct loop *loop, double_int *nit);
Index: loop-iv.c
===================================================================
*** loop-iv.c (revision 203625)
--- loop-iv.c (working copy)
*************** find_simple_exit (struct loop *loop, str
*** 3001,3009 ****
fprintf (dump_file, "\n");
fprintf (dump_file, " upper bound: %li\n",
! (long)max_loop_iterations_int (loop));
fprintf (dump_file, " realistic bound: %li\n",
! (long)estimated_loop_iterations_int (loop));
}
else
fprintf (dump_file, "Loop %d is not simple.\n", loop->num);
--- 3001,3009 ----
fprintf (dump_file, "\n");
fprintf (dump_file, " upper bound: %li\n",
! (long)get_max_loop_iterations_int (loop));
fprintf (dump_file, " realistic bound: %li\n",
! (long)get_estimated_loop_iterations_int (loop));
}
else
fprintf (dump_file, "Loop %d is not simple.\n", loop->num);
Index: loop-unroll.c
===================================================================
*** loop-unroll.c (revision 203625)
--- loop-unroll.c (working copy)
*************** decide_peel_once_rolling (struct loop *l
*** 469,475 ****
|| desc->infinite
|| !desc->const_iter
|| (desc->niter != 0
! && max_loop_iterations_int (loop) != 0))
{
if (dump_file)
fprintf (dump_file,
--- 469,475 ----
|| desc->infinite
|| !desc->const_iter
|| (desc->niter != 0
! && get_max_loop_iterations_int (loop) != 0))
{
if (dump_file)
fprintf (dump_file,
Index: loop-unswitch.c
===================================================================
*** loop-unswitch.c (revision 203625)
--- loop-unswitch.c (working copy)
*************** unswitch_single_loop (struct loop *loop,
*** 304,310 ****
}
/* Nor if the loop usually does not roll. */
! iterations = estimated_loop_iterations_int (loop);
if (iterations >= 0 && iterations <= 1)
{
if (dump_file)
--- 304,310 ----
}
/* Nor if the loop usually does not roll. */
! iterations = get_estimated_loop_iterations_int (loop);
if (iterations >= 0 && iterations <= 1)
{
if (dump_file)
Index: tree-ssa-loop-niter.c
===================================================================
*** tree-ssa-loop-niter.c (revision 203625)
--- tree-ssa-loop-niter.c (working copy)
*************** estimated_loop_iterations (struct loop *
*** 3388,3393 ****
--- 3388,3414 ----
return (get_estimated_loop_iterations (loop, nit));
}
+ /* Similar to estimated_loop_iterations, but returns the estimate only
+ if it fits to HOST_WIDE_INT. If this is not the case, or the estimate
+ on the number of iterations of LOOP could not be derived, returns -1. */
+
+ HOST_WIDE_INT
+ estimated_loop_iterations_int (struct loop *loop)
+ {
+ double_int nit;
+ HOST_WIDE_INT hwi_nit;
+
+ if (!estimated_loop_iterations (loop, &nit))
+ return -1;
+
+ if (!nit.fits_shwi ())
+ return -1;
+ hwi_nit = nit.to_shwi ();
+
+ return hwi_nit < 0 ? -1 : hwi_nit;
+ }
+
+
/* Sets NIT to an upper bound for the maximum number of executions of the
latch of the LOOP. If we have no reliable estimate, the function returns
false, otherwise returns true. */
Index: tree-ssa-loop-niter.h
===================================================================
*** tree-ssa-loop-niter.h (revision 203625)
--- tree-ssa-loop-niter.h (working copy)
*************** extern bool finite_loop_p (struct loop *
*** 30,36 ****
--- 30,38 ----
extern tree loop_niter_by_eval (struct loop *, edge);
extern tree find_loop_niter_by_eval (struct loop *, edge *);
extern bool estimated_loop_iterations (struct loop *, double_int *);
+ extern HOST_WIDE_INT estimated_loop_iterations_int (struct loop *);
extern bool max_loop_iterations (struct loop *, double_int *);
+ extern HOST_WIDE_INT max_loop_iterations_int (struct loop *);
extern HOST_WIDE_INT max_stmt_executions_int (struct loop *);
extern HOST_WIDE_INT estimated_stmt_executions_int (struct loop *);
extern bool max_stmt_executions (struct loop *, double_int *);