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

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 15 15:02:08 PDT 2025


kasuga-fj wrote:

> May I ask what your specific objection is? Do you believe that my patch produces incorrect results?

Basically yes. For example, consider the following case:

```c
for (int i = 0; i < M; i++) {
  if (i < 10)
    for (int j = 0; j < N; j++)
      A[i+10][j] = 42;
  for (int j = 0; j < N; j++)
    A[i][j] = 43;
}
```

What does "assuming fusion" mean in this case? Doesn't it also imply that Stmt2 is executed only when `i < 10`? If so, `i < i + 10` is implied and DA may report no dependency, which is obviously incorrect if `M` is greater than 10. It seems that this kind of condition isn't considered by DA at the moment, and I'm worried that miscompilations could occur if we try to account for it in the future, or that similar accidents could happen unnoticed due to improvements in ScalaEvolution.
This example, as well as the one in my earlier comment, represents just some specific cases, and I’m not sure when the changed result is actually "correct." Unless we can state that clearly, it would be ideal that the result remains the same, regardless of whether the fusion assumption is applied. Or at the very least, I think it would be better to ensure that there are no individual loop-guards between fusable loops within `areLoopsSimilar`.

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


More information about the llvm-commits mailing list