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

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 8 14:44:33 PDT 2025


kasuga-fj wrote:

> About (1) I think forcing `isConsistent` to be false is incorrect. It should be what the algorithm sets it to.

The comment of `isConsistent` says:

```
/// isConsistent - Returns true if this dependence is consistent
/// (occurs every time the source and destination are executed).
```

It means that this function returns true if we know the dependence is consistent. Returning false doesn't mean it is inconsistent. Always returning false is permitted.
Using the same value as the current algorithm computes looks risky to me. Consider the following case:

```c
for (int i = 0; i < 100; i++) {
  for (int j = 0; j < 100; j++)
    A[i][j] = 42;
  
  if (rand() % 2 == 0)
    for (int j = 0; j < 100; j++)
      A[i][j] = 43;
}
```

The dependence between `A[i][j] = 42` and `A[i][j] = 43` is not consistent. Then, what happens with this patch? I guess that the current algorithm set `Consistent` to true [^consistent].

> Let me rephrase my answer to question (2). If a pass asks a question about depdency of two statements from two different loops, then that pass needs to have good answers to the question that you raised. Right now, loop fusion can handle this. Any other pass that wants to do this in future needs to be clear about this as well.

If this patch adds new assumptions to the analysis results, we may need to update other existing uses. For example, if the improved results assume the conditions under which "LoopFuse works fine," then we need to replace code like:

```cpp
Dependence *Dep = DI->depends(Src, Dst);
```

with something like:

```cpp
Dependence *Dep = DI->depends(Src, Dst);
if (The same condition as in LoopFuse does not hold)
  return;
```


[^consistent]: Anyway, it's already broken... https://godbolt.org/z/sc3ds9WaM

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


More information about the llvm-commits mailing list