[llvm] [LoopInterchange] Fix depends() check parameters (PR #77719)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 24 23:26:04 PST 2024


ShivaChen wrote:


> > Index SCEV of aa[j] is {1,+,1}, Index SCEV of aa[j-1] is {0,+,1}. The depends(aa[j][i], aa[j-1][i]) call site in LoopCacheAnalysis return the correct distance 1. The call site in LoopInterchange has depends(aa[j-1][i], aa[j][i]) and return distance as -1. Should LoopInterchange follow the parameters as LoopCacheAnalysis?
> >> It seems LoopCacheAnalysis only consider |distance| to fit in cache line instead of direction. 
> 
> LoopCacheAnalysis does not care about the order of access, but whether the values are close enough to fit into the cache or cache line. E.g. if it is in the same cache line, then the second access will already have been established in the L1 cache, and therefore can be accessed with lower latency. Which of the accesses is first/second does not matter, accessing one of them will establish the other in the cache line[1](#user-content-fn-1-e1f02a32cb7511a1ac56645b1134c78e).
> 
> ## Footnotes
> 1. LoopCacheAnalysis does not consider cache line boundaries and data alignment, but if two neighboring addresses do not fall into the same cache line, the processor may have prefetched the neighboring cache line. Hence, it should be a good enough heuristic. [↩](#user-content-fnref-1-e1f02a32cb7511a1ac56645b1134c78e)

Agree, LoopCacheAnalysis only need to consider the aboslute value of |distance|. So might not a good analogue of LoopInterchange which the direction matter.
And LoopCacheAnalysis should able to catch the correct direction if the normalize occur as expected.

https://github.com/llvm/llvm-project/pull/77719


More information about the llvm-commits mailing list