IVOPT improvement patch

Zdenek Dvorak rakdver@kam.mff.cuni.cz
Tue May 25 18:25:00 GMT 2010


Hi,

> >> @@ -3811,6 +3841,9 @@ get_computation_cost_at (struct ivopts_d
> >>                                        &offset, depends_on));
> >>      }
> >>
> >> +  /* Loop invariant computation.  */
> >> +  cost.cost /= avg_loop_niter (data->current_loop);
> >> +
> >
> > This is wrong, at least some parts of the computation here are not loop invariant.
> 
> Which part is not loop invariant?

it depends on the actual form of the use.  But in the most general case, the
computation whose cost is determined here is ubase + ratio * (var - cbase), and
no part of this is loop invariant (except for the force_var_costs of ubase and cbase).

> >> @@ -4056,20 +4090,16 @@ may_eliminate_iv (struct ivopts_data *da
> >>    /* If not, and if this is the only possible exit of the loop, see whether
> >>       we can get a conservative estimate on the number of iterations of the
> >>       entire loop and compare against that instead.  */
> >> -  else if (loop_only_exit_p (loop, exit))
> >> +  else
> >
> > This change is wrong, the test is necessary.  See
> > http://gcc.gnu.org/ml/gcc-patches/2008-07/msg00146.html
> > and the following discussion.
> >
> 
> The original fix to the problem is too conservative -- if there is
> only one exit has the test to be replaced, it should be ok to do it,
> right?

Yes.  But I do not see your point -- your patch removes the loop_only_exit_p
test, which is necessary.

> >>      {
> >>        double_int period_value, max_niter;
> >>        if (!estimated_loop_iterations (loop, true, &max_niter))
> >>       return false;
> >>        period_value = tree_to_double_int (period);
> >> -      if (double_int_ucmp (max_niter, period_value) >= 0)
> >> +      if (double_int_ucmp (max_niter, period_value) > 0)
> >>       return false;
> >>      }
> >
> > This also seems wrong (or at least inconsistent with that is done for
> > the constant number of iterations).
> 
> This looks correct to me. 

I think you are right; but, then the preceding test for tree_int_cst_lt
should be changed as well (so that both conditions are the same).
It would also be nice to add testcases for the boundary values to the
testsuite, to make sure we are not making an off-by-one error.

Zdenek



More information about the Gcc-patches mailing list