[llvm] [DependenceAnalysis] Extending SIV to handle fusable loops (PR #128782)
Alireza Torabian via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 18 08:46:51 PDT 2025
1997alireza 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`.
I do not believe such checks are necessary within DA. If you run this code with the original DA, the result is [10], which represents the dependency distance with respect to loop i. With my patch applied, DA is able to capture the dependency for loop j as well, resulting in [10 0].
As you can see, DA does not report no dependency; rather, it now provides the dependency distance as well. The point you mentioned regarding loop-guards is not directly related to what DA is designed to provide. "assuming fusion" means what would be the dependency between two accesses if they were in the same loop like this:
```c
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++)
A[i+10][j] = 42;
A[i][j] = 43;
}
```
DA doesn't need to know about the loop-guards to provide such information. It is similar to the following case where DA generates [10, 0].
```c
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
if (i < 10)
A[i+10][j] = 42;
A[i][j] = 43;
}
}
```
https://github.com/llvm/llvm-project/pull/128782
More information about the llvm-commits
mailing list