[PATCH] D155077: [MachinePipeliner] Fix a bug in write-after-read scheduling

Alon Kom via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 12 05:52:35 PDT 2023


alonkom created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
alonkom requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When computing the early/late start/end cycle only the case of loop-carried-dependence where the read comes before the write is handled.
This code guarantees they will be scheduled at the same stage, no more than II cycles apart.
This didn't work properly when the write occurs before the read, even though they may be loop-carried dependent.
For example:

  a[idx] = 1;
  b[idx] = long_compute_chain(a[idx + 1]);

In this case, where the write a[idx], comes before the read a[idx+1], the read cannot be scheduled more than II cycles from the write, as the write may store new data that should have been read already in previous iteration.

Unfortunately, I'm working on an out-of-tree target, and couldn't create a lit test of this case.


https://reviews.llvm.org/D155077

Files:
  llvm/lib/CodeGen/MachinePipeliner.cpp


Index: llvm/lib/CodeGen/MachinePipeliner.cpp
===================================================================
--- llvm/lib/CodeGen/MachinePipeliner.cpp
+++ llvm/lib/CodeGen/MachinePipeliner.cpp
@@ -2439,7 +2439,8 @@
             int EarlyStart = cycle + Dep.getLatency() -
                              DAG->getDistance(Dep.getSUnit(), SU, Dep) * II;
             *MaxEarlyStart = std::max(*MaxEarlyStart, EarlyStart);
-            if (DAG->isLoopCarriedDep(SU, Dep, false)) {
+            if (DAG->isLoopCarriedDep(SU, Dep, false) ||
+                DAG->isLoopCarriedDep(SU, Dep)) {
               int End = earliestCycleInChain(Dep) + (II - 1);
               *MinEnd = std::min(*MinEnd, End);
             }
@@ -2463,7 +2464,8 @@
             int LateStart = cycle - Dep.getLatency() +
                             DAG->getDistance(SU, Dep.getSUnit(), Dep) * II;
             *MinLateStart = std::min(*MinLateStart, LateStart);
-            if (DAG->isLoopCarriedDep(SU, Dep)) {
+            if (DAG->isLoopCarriedDep(SU, Dep) ||
+                DAG->isLoopCarriedDep(SU, Dep, false)) {
               int Start = latestCycleInChain(Dep) + 1 - II;
               *MaxStart = std::max(*MaxStart, Start);
             }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155077.539511.patch
Type: text/x-patch
Size: 1227 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230712/1331a627/attachment.bin>


More information about the llvm-commits mailing list