[llvm] [MachinePipeliner] Fix store-store dependences (#72508) (PR #72575)

Yuta Mukai via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 24 00:25:05 PST 2023


ytmukai wrote:

> The original case already has an order dependence, so we need to make sure that the second store isn't scheduled too far way from the first.

I believe that a dependence recognized by `ScheduleDAGInstrs::buildSchedGraph()` is loop independent, and it tells nothing about loop carried dependence.

There should be cases where there are loop independent dependencies but no loop carried ones. In those cases, this modification would be excessive.

Here's an example of each case.

* only loop independent dependence (between stores)

```c
for (int i=0; i<n; i++) {
  /* S0 */ a[i] = 1;
  /* S1 */ int tmp = a[x];  // To prevent optimization
  /* S2 */ a[i] = tmp;
}
```

There is a dependence from S0 to S2 but not from S2 to S0. Therefore, S2 can be scheduled after S0 at the next iteration. This modification may prevent it.

* only loop carried dependence (between stores)

```c
for (int i=0; i<n; i++) {
  /* S0 */ a[i] = 1;
  /* S1 */ int tmp = a[x];  // To prevent optimization
  /* S2 */ a[i+1] = tmp;
}
```

There is a dependence from S2 to S0 but not from S0 to S2. Therefore, S2 must be scheduled before S0 at the next iteration. The dependence is not recognized by `SwingSchedulerDAG::addLoopCarriedDependences()` currently.

* both loop independent and loop carried dependence (between stores)

```c
for (int i=0; i<n; i++) {
  // a and idx0/idx1 are disjoint
  /* S0 */ a[idx0[i]] = 1;
  /* S1 */ a[idx1[i]] = 2;
}
```

There is a loop independent dependence from S0 to S1 and a loop carried dependence from S1 to S0. (The loop carried dependence from S0 to S1 need not be considered since there is an loop independent one.) The former is recognized by `ScheduleDAGInstrs::buildSchedGraph()`. This modification would consider that when there is such a dependence, there is a loop carried dependence in the opposite direction. In this case, that would seem to be correct.

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


More information about the llvm-commits mailing list