[llvm] [LoopInterchange] Motivating example for interchange enablement. NFC. (PR #171631)

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 10 10:51:13 PST 2025


https://github.com/kasuga-fj commented:

There are at least two problems if we want to interchange this.

- Currently this is not even subject to LoopInterchange in the first place. This is because LoopInterchange doesn't support a loop that has multiple sub-loops (i.e., `L->getSubLoops().size() >= 2`). In this case, perhaps either `Stmt2`, `Stmt3` or `Stmt4` is a loop as well? We probably need to add a feature to limit the scope of what LoopInterchange handles, rather than applying it to the entire loop nest. I think implementing this itself would not be difficult, but the heuristic for choosing which loop nest to analyze may be non-trivial. Similar functionality will likely be necessary for DA as well.
- Probably DA cannot provide something useful without the information about the range of `NX` and `NY`. I think there are only two options here: 
    1. Use runtime checks
    1. Tell the knowledge of the semantics of the original language, e.g., out-of-bounds array access is UB in C/C++/Fortran. Note that this is different from emitting array size information from frontend. What we need here is `NX < 54` and `NY < 54`. More precisely, `%18 < 54` and `%20 < 54` in the LLVM IR. Metadata about array sizes won't guarantee them.

I don't know if there exists another approach and which one is the best...

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


More information about the llvm-commits mailing list