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

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 02:47:05 PST 2024


ShivaChen wrote:

> 1. `populateDependencyMatrix` MUST check for self-dependencies, i.e. StoreInsts that overwrite memory of previous iterations. These must be kept in-order so the last overwrite is the value in memory when the loop nest finishes.
> 2. The order of I/J does not matter because of `D->normalize(SE)`.

Hi Meinersbur,

Thanks for providing the example in https://godbolt.org/z/Tacx7M7M7, it make it easier to follow the reason of store self checking. :-)

1. It seems the interchange in the case is invalid due to the store type is wider than the array element type. Could we detect the type size to prevent the interchange instead of output dependency to itself? The loop in s231() didn't has cross multiple iteration store and bail out by the store self checking. There is a https://github.com/llvm/llvm-project/pull/77885 PR to address the issue.
2. According to `isDirectionNegative()`, it will normalize if find ">". However, s231 has 3 level loop. There is no dependency in Level 1 loop and Direction is initialized as "*" which prevent the normalize.

 ```
   for (int nl = 0; nl < 10000000/256; nl++) // Level 1
     for (int i = 0; i < 256; ++i)           // Level 2
       for (int j = 1; j < 256; j++)         // Level 3
         aa[j][i] = aa[j-1][i] + bb[j][i];

```
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?

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


More information about the llvm-commits mailing list