On Mon, Jul 17, 2017 at 11:56:50AM +0200, Richard Biener wrote:
> On Thu, Jul 13, 2017 at 2:18 AM, Kugan Vivekanandarajah
> <kugan.vivekanandara...@linaro.org> wrote:
> > I am looking into reversing loop to increased efficiency. There is
> > already a PR22041 for this and an old patch
> > https://gcc.gnu.org/ml/gcc-patches/2006-01/msg01851.html by Zdenek
> > which never made it to mainline.
> >
> > For constant loop count, ivcanon pass is adding reverse iv but this
> > not selected by ivopt.
> 
> ivopt will never do loop reversal, if it would select this IV it would need to
> keep the original one as well or compute the old i based on the new.
> 
> loop reversal needs dependence analysis and it's not clear if for the copy
> case you quote would be profitable (HW prefetchers like that?).  For your
> case it's also invalid as a and c may overlap.

If the goal is to make the induction variable end at 0, you can transform
[0..N) into [-N..0).  I have some old patches to do that; it probably
is better to start from scratch if you want it though.

Two issues that had to be solved for this:

1) ivopts didn't cost the cheaper loop ending condition correctly;
2) where you had say a[i] in the loop it will be (a+N)[i] afterwards,
and the calculation of a+N wasn't properly hoisted out of the loop.


Segher

Reply via email to