[PATCH] D122857: [LoopCacheAnalysis] Enable delinearization of fixed sized arrays

Bardia Mahjour via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 11 13:23:44 PDT 2022


bmahjour added a comment.

> You mention that the SCEV-based approach cannot handle fixed-sized arrays. Could you please explain in more detail why? It's not really obvious to me.

To add to the above explanations, the algorithm for recovering subscripts (delinearization) is described in this paper. <https://dl.acm.org/doi/pdf/10.1145/2751205.2751248> The implementation in LLVM is based on that paper. In section 3.1 they describe a generic example where they try to recover subscripts `A[i+o0][ j+o1][k+o2]` for an access function that's been linearized in the IR. The original (linearized) polynomial in that example is `(n2(n1o0 +o1)+o2)+n1n2i+n2 j +k`. They apply a heuristic to recover the size of each dimension of the array (in this case `A[][n1][n2]`). They then take the polynomial and divide it by the size of the inner most dimension `n2`. The remainder from that division (ie. `o2 + k`) forms the subscript for the inner most dimension and the quotient (ie `n1o0+o1+n1i+ j`) is further divided by `n1` to recover `o1 + j` for the middle dimension and so on.

If the sizes of each dimension of the array were compile-time constants, and some of the offsets (ie `o0`, `o1` or `o2`) were also constant, those constants would get folded together in away that would make them indistinguishable from each other and the algorithm wouldn't be able to correctly recover the original subscripts. (eg. if `n1=10, n2=10, o0=1, o1=2, o2=3`, then the original linearized expression would be `123 + 100i + 10j + k`. Even if the algorithm knew the sizes of each dimension of the array (ie 10x10), dividing this expression by 10 would yield a remainder of `123 + k` which would not be a valid subscript for the inner dimension!

Hopefully this example clarifies why the same algorithm cannot be used to delinearize subscripts in a fixed size array.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122857



More information about the llvm-commits mailing list