[llvm] [Delinearization] Add function for fixed size array without relying on GEP (PR #145050)

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 8 07:31:18 PDT 2025


kasuga-fj wrote:

I replaced the call to `tryDelinearizeFixedSizeImpl` in DA with the new function and tried running regression tests for DA and LoopInterchange. As a result, all tests under `test/Transforms/LoopInterchange` passed, but about half of the tests under `test/Analysis/DependenceAnalysis` failed. I haven't checked all the cases yet, but here's a quick summary of the current findings:

- For example, triangular loops such as the one in [NonCanonicalizedSubscript.ll](https://github.com/llvm/llvm-project/blob/1693ac35aa294837cfddad065e426127b1c33fd0/llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll#L43-L102) were not handled properly. At the moment, I don't have a good idea for addressing these cases. However, since LoopInterchange also doesn't support triangular loops, I believe this limitation is acceptable in the context of enabling that pass.
    - On the other hand, I'm not sure if this is a problem for the other passes that depend on DA, such as LoopUnrollAndJam.
- Regarding DA, it calls the delinearization function twice, once for `Src` and once for `Dst`. In some cases, inferred array sizes differ between them, causing `DependenceInfo::tryDelinearizeFixedSize` to fail (e.g., [Invariant.ll](https://github.com/llvm/llvm-project/blob/d338d197e7ee6e6f8986e14b2aec9d4c368d8a9e/llvm/test/Analysis/DependenceAnalysis/Invariant.ll), where `rr[j][j]` doesn't depend on `i`). However, if those two results are "compatible", delinearization may still succeed. It would be nice to add such logic into DA to detect such cases. From a brief test, it seemed to work well.
    - IIUIC, this is conceptually similar to how NumPy handles tensor strides when reshaping.
- In some cases, the results seems to be improved. At first glance, dependencies like `[* * *]` often turns into ones like `[S S 0]`. I need to check if they are actually correct.

While investigating them, I noticed some minor glitches as well.

- `DependenceAnalysisPrinter` seems a bit flaky. If a loop only has dependencies within a single iteration (i.e., no loop-carried dependencies), it prints either `0` or `=`. It seemed that this caused several tests to fail.
- In addition to fixed-size array delinearization, we also need to incorporate logic to check whether the address is divisible by ElementSize in `DependenceInfo::tryDelinearizeParametricSize`. [The first corner case I posted](https://github.com/llvm/llvm-project/blob/d338d197e7ee6e6f8986e14b2aec9d4c368d8a9e/llvm/test/Analysis/DependenceAnalysis/DifferentOffsets.ll#L147-L201) was resolved by fixing only the fixed-size array delinearization, but [the second one](https://github.com/llvm/llvm-project/pull/144088#discussion_r2191831171) required changes to this function as well.

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


More information about the llvm-commits mailing list