[llvm] [LoopInterchange] Ignore the cost-model, force interchange if legal (PR #148858)

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 18 02:18:54 PDT 2025


================
@@ -0,0 +1,43 @@
+; RUN: opt < %s -passes=loop-interchange -pass-remarks-output=%t -disable-output -loop-interchange-profitabilities=ignore -S
----------------
kasuga-fj wrote:

> 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.

Could you please add this? It's fine to do it in another PR.

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


More information about the llvm-commits mailing list