[llvm] [DependenceAnalysis] Extending SIV to handle fusable loops (PR #128782)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 26 13:51:58 PDT 2025
amehsan wrote:
> At the very least, `ScalarEvolution` uses loop-guards to prove something, and `SCEVAddRecExpr`s are constructed based on them. In other words, they may contain information inferred from loop-guards, which we might be implicitly leveraging through the `ScalarEvolution` APIs. Therefore, I believe we need to ensure that we're not depending on properties derived by `ScalarEvolution` from loop-guards that are present in only one of the loops of the fusable-loops.
>
> In addition, IIUIC, the following two codes are not considered equivalent by `ScalarEvolution`, even thought the condition in the if-statement is loop-invariant. In the first case, the if condition is a loop-guard and is taken into account when constructing `SCEVAddRecExpr`s for expressions inside Stmt. In contrast, this is not true for the second case.
>
> ```c
> if (i < 10)
> for (int j = 0; j < N; j++)
> Stmt;
>
> for (int j = 0; j < N; j++)
> if (i < 10)
> Stmt;
> ```
I appreciate your intention to ensure the utmost quality of the open source compiler. Let me clarify a couple of things.
DA gets two mem access instructions in one or two loops. The actual memory accessed may vary depending on the value of the induction variables of the loops. All that DA is responsible for is to check these two instructions may access the same memory for some of the possible values of the induction variables or not. Whether the loops have guards or not, control flow inside the loop, whether the instructions are actually executed for any or all values of the induction variable is irrelevant to DA.
There is another issue about fusability of the loops. None of conditions of fusability (loop guards, etc. ) is relevant here. The only thing relevant is that we have two loops with induction variables I and J that takes values `I_start` to `I_end` to `J_stat` to `J_end`. The implication of fusability for DA is that we assume these values change in a specific order. That is all. That is not going to cause any dependence to be reported as non-dependent. It only makes it possible to calculate a distance or directions on induction variables `I` and `J` (One that is useful for loop fusion). There won't be any impact on other components of the distance vector, and no impact on distinguishing dependence and non-dependence.
https://github.com/llvm/llvm-project/pull/128782
More information about the llvm-commits
mailing list