On Tue, Apr 19, 2016 at 12:09 PM, Jan Hubicka <hubi...@ucw.cz> wrote: >> > Index: tree-ssa-loop-ivopts.c >> > =================================================================== >> > --- tree-ssa-loop-ivopts.c (revision 235064) >> > +++ tree-ssa-loop-ivopts.c (working copy) >> > @@ -121,7 +121,11 @@ avg_loop_niter (struct loop *loop) >> > { >> > HOST_WIDE_INT niter = estimated_stmt_executions_int (loop); >> > if (niter == -1) >> > - return AVG_LOOP_NITER (loop); >> > + { >> > + niter = max_stmt_executions_int (loop); >> > + if (niter == -1 || niter > AVG_LOOP_NITER (loop)) >> > + return AVG_LOOP_NITER (loop); >> Any reason why AVG_LOOP_NITER is still used if niter gives larger number? > > if you have a loop like this > > int a[1000000]; > > for (i=0li<1000000;i++) > if (a[i]) > break > max_stmt_executions_int will be 1000000 but that is just upper bound, not > realistic > estimate and thus you can not assume that average number of iterations is > 1000000. > It is anywhere between 0 and 1000000 and I assume the constant of 5 which > AVG_LOOP_NITER > expands into was chosen to avoid ivopts to give resonable balance between > setup cost > and iteration cost. For example, string manipulation loops tends to get large > buffers > and terminate in very few iterations. > > (I do not recall the data precisely, it has been a decade. The average number > of iterations of random loop can be measured from profile feedback, it is > somewhere between 3 adn 10 for SPEC or GCC). > This is why: > /* Loopback edge is taken. */ > DEF_PREDICTOR (PRED_LOOP_BRANCH, "loop branch", HITRATE (86), > PRED_FLAG_FIRST_MATCH) > > /* Edge causing loop to terminate is probably not taken. */ > DEF_PREDICTOR (PRED_LOOP_EXIT, "loop exit", HITRATE (91), > PRED_FLAG_FIRST_MATCH) > > is set accordingly. Thanks for explanation.
Thanks, bin