[llvm] [DependenceAnalysis] Extending SIV to handle fusable loops (PR #128782)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 14 07:35:25 PDT 2025


amehsan wrote:


> 
> I don't think so. For example, regarding LoopInterchange, the following case isn't currently supported, but I believe it could be extended relatively easily
> 
> ```c
> for (int i = 0; i < N; i++)
>   for (int j = 0; j < M; j++) {
>     for (int k = 0; k < O; k++)
>       Stmt1;
>     for (int l = 0; l < O; l++)
>       Stmt2;
>   }
> ```
> 

Your example is not a perfect loop nest (the j-loop has two  inner loops) and the legality check for loop interchange assumes a perfect loop nest (see the code snippet below taken from loop interchange source code). I am not sure extension of loop interchange to cover this case will be easy. But anyways, let's use that flag to address this concern.

```
// After interchanging, check if the direction vector is valid.
// [Theorem] A permutation of the loops in a perfect nest is legal if and only
// if the direction matrix, after the same permutation is applied to its
// columns, has no ">" direction as the leftmost non-"=" direction in any row.
static bool isLexicographicallyPositive(std::vector<char> &DV) {
  for (unsigned char Direction : DV) {
    if (Direction == '<')
      return true;
    if (Direction == '>' || Direction == '*')
      return false;
  }
  return true;
}

```

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


More information about the llvm-commits mailing list