[PATCH] D73064: [LoopCacheAnalysis]: Add support for negative stride

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 4 22:34:41 PST 2020


jdoerfert added a comment.

In D73064#1857187 <https://reviews.llvm.org/D73064#1857187>, @rcraik wrote:

> In D73064#1844826 <https://reviews.llvm.org/D73064#1844826>, @jdoerfert wrote:
>
> > Correct me if I'm wrong but it seems you pretend negative steps are positive ones. While this is just a best-effort analysis, it seems wrong.
> > Take
> >
> >   for (i = N; i > 0; i--)
> >     A[i] = A[N - i];
> >
> >
> > which should have a different cost than
> >
> >   for (i = N; i > 0; i--)
> >     A[i] = A[i];
> >
> >
> > which is the same as
> >
> >   for (i = 0; i < N; i++)
> >     A[i] = A[i];
> >
> >
> > Can you add these examples to the tests please?
>
>
> Could you explain why you believe the first test should have a different cost than the second two? The first and last testcase both iterate over the array in a forwards direction (at least in terms of loads) while the middle one is the only one which goes backwards.


Going backwards is no different from going forward (assuming we ignore prefetchers). So I argue 2 and 3 are the same when it comes to cache behavior. In both we access the same memory twice in each iteration, but since it is the same memory there is actually only a single cache miss per iteration (assuming one array element per cache line for simplicity, otherwise we just get a factor everywhere). Now in version 1 we access two different elements in all but potentially one iteration (the middle) so we get two cache misses in each iteration.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73064/new/

https://reviews.llvm.org/D73064





More information about the llvm-commits mailing list