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

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 26 05:00:48 PST 2025


https://github.com/Meinersbur commented:

Effectively, with SeparateLoops=true, this will handle loops as if they are fused.

But it also means that the result is plain wrong for non-fused loops. E.g. the dependence distance `d` computed by e.g. `strongSIVtest` may result in `d > 0`, where in reality all the instances of write occur before the read because their loops are sequential, not nested.

Another concern is that the analysis makes the decision on how to loop fusion occurs. The FuseLoops pass may want to fust loops with non-equal trip count, then it has to make the decision which iterations are executed with which ones. Even in cases where the trip count matches such as
```
for (int i = 0; i < n; +=1)
  A[i+1] += 1;
for (int i = 0; i < n; +=1)
  A[i] += 2;
```
loop fusion would optimally be
```
for (int i = 0; i < n+1; +=1) {
  if (i > 0) A[i] += 1;
  if (i < n) A[i] += 2;
}
```
or after LoopBoundSplitPass etc.
```
A[0] += 2;
for (int i = 0; i < n+1; +=1) 
  A[i] += 3;
A[n] +=  1;
```
i.e. not as naive as DA would assume.

I think instead of a `SeparateLoops` parameter, DA should receive the info which loops are considered to be fused from FuseLoops -- otherwise they might be disagree. "SeparateLoops" isn't a good name anyway. It goes pack to the old problem that we want to analyze the result of a optimization without the optimization having been applied first. It would be great if we could leave pass-specific concerns out of DA itself.


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


More information about the llvm-commits mailing list