[llvm] [LoopInterchange] Ignore the cost-model, force interchange if legal (PR #148858)
Ryotaro Kasuga via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 17 08:06:35 PDT 2025
https://github.com/kasuga-fj commented:
orce interchange can occur odd behavior in some cases. Can you add a test to show it? Here is an example:
```c
int A[4][4][4];
for (int i = 0; i < 4; i++)
for (int j = 1; j < 4; j++)
for (int k = 0; k < 4; k++)
A[3-i][j-1][k] = A[i][j][k];
```
IIUIC, the following scenario happens due to the bubble-sort based heuristic:
1. Try to interchange the 2nd loop (j-loop) and 3rd loop (k-loop). It is legal, so they are interchanged.
2. Try to interchange the 1st loop (i-loop) and 2nd loop (k-loop, because the j-loop and k-loop were interchanged). It is illegal, so they are NOT interchanged.
3. Try to interchange the 2nd loop (k-loop) and 3rd loop (j-loop). It is legal indeed, so they are interchanged again.
Consequently, the first interchange is reverted, and the final loop order remains the same as the original. I believe this is acceptable, considering that the force interchange option is intended for testing purposes. However, it is worth clarifying this behavior with an example.
https://github.com/llvm/llvm-project/pull/148858
More information about the llvm-commits
mailing list