Dear LLVM Community,
I’m working on improving the Dependency Analysis (DA)
pass in LLVM to better detect “Loop Carried Dependencies” in loop fusion. The current DA tests (SIV, MIV, RDIV) lack sufficient detail for this task, and I’d like to discuss extending the pass to address this.
Problem Context
The issue arises when fusing two exact similar loops and detecting the dependency between them along with its direction and distance. For example:
for (int i = 0; i < 10; i++)
A[i+1] = ...;
for (int j = 0; j < 10; j++)
... = A[j];
Here, there’s a backward loop-carried. The DA pass should ideally provide the dependency’s direction (<)
and distance (-1)
, which is essential for detecting loop carried dependencies in loop fusion. Currently, loop fusion attempts to gather the required information using SCEV, but in some cases, the SCEV is too complicated to handle, while DA could have been able to manage them.
Current DA Pass Behavior
Currently, the DA pass classifies this as RDIV, which identifies a dependency by detecting an intersection between the expressions but does not specify the direction or distance. This is because direction and distance do not make sense when we have different loops, but in our case, the loops are structurally the same, so we could leverage additional information to identify the dependency’s direction and distance.
SIV’s Potential for Our Use Case
SIV (Single Index Variable) works well for dependencies within the same loop, providing both direction and distance. However, it’s currently restricted to dependencies within the same loop. Given that the loops in our case are structurally similar, I propose relaxing the condition for SIV to allow it to work specifically for the following cases:
for (int i = 0; i < 10; i++)
A[i] = ...;
for (int j = 0; j < 10; j++)
... = A[j];
for (int i = 0; i < 10; i++)
A[i+1] = ...;
for (int j = 0; j < 10; j++)
... = A[j];
This would help the DA pass to provide direction and distance across different but similar loops.
Request for Feedback
We would like to post this extension to the opensource LLVM. I’d appreciate feedback on this proposal, especially regarding:
- Whether relaxing the SIV conditions is a reasonable approach for handling loop carried dependencies.
- Any potential implications this might have on the performance or correctness of the DA pass.
Thank you for your time. I look forward to your thoughts