[llvm] [AMDGPU][VOPD] Cache load reachability checks in VOPDpairing (PR #204854)

Joe Nash via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 19 12:21:44 PDT 2026


================
@@ -266,60 +266,83 @@ static bool shouldScheduleVOPDAdjacent(const TargetInstrInfo &TII,
 
 /// Collect all load (dependents if \p Forward else dependencies) that connect
 /// to the \p Head SU.
-static void collectLoads(SmallVector<SUnit *> &Loads, BitVector &Visited,
-                         SUnit &Head, bool Forward) {
-  if (Head.isBoundaryNode() || Visited.test(Head.NodeNum))
+static void collectLoads(SmallPtrSet<SUnit *, 8> &Loads, BitVector &Visited,
+                         SUnit &Head, bool Forward, bool StopAtLoads) {
+  if (Head.isBoundaryNode())
     return;
 
+  Visited.reset();
+
   SmallVector<SUnit *> Stack;
   Stack.push_back(&Head);
   while (!Stack.empty()) {
     SUnit *SU = Stack.pop_back_val();
     const SmallVector<SDep, 4> &Deps = Forward ? SU->Succs : SU->Preds;
     for (const SDep &Edge : Deps) {
-      if (Edge.getKind() != SDep::Data)
+      if (StopAtLoads && Edge.getKind() != SDep::Data)
         continue;
       SUnit *Dep = Edge.getSUnit();
       if (Dep->isBoundaryNode() || Visited.test(Dep->NodeNum))
         continue;
-      if (Dep->isInstr() && Dep->getInstr()->mayLoad())
-        Loads.push_back(Dep);
-      else
-        Stack.push_back(Dep);
-
       Visited.set(Dep->NodeNum);
+
+      if (Dep->isInstr() && Dep->getInstr()->mayLoad()) {
+        Loads.insert(Dep);
+        if (StopAtLoads)
+          continue;
+      }
+      Stack.push_back(Dep);
     }
   }
 }
 
 /// Checks whether fusing SU \p I with SU \p J would force the loads preceding
 /// \p J to complete before loads depending on \p I.
-static bool loadsMayOverlap(ScheduleDAGInstrs *DAG, [[maybe_unused]] SUnit &I,
-                            const BitVector &IVisited,
-                            const SmallVector<SUnit *> &ILoadSuccs,
-                            [[maybe_unused]] SUnit &J,
-                            const BitVector &JVisited,
-                            const SmallVector<SUnit *> &JLoadPreds) {
+static bool
+loadsMayOverlap(SUnit &I, const SmallPtrSet<SUnit *, 8> &ILoadSuccs, SUnit &J,
----------------
Sisyph wrote:

Nit: It's a bit difficult to tell what is an input parameter vs just outside allocated storage. I'd suggest describe the pre-condition of the parameter ILoadSuccs

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


More information about the llvm-commits mailing list