[llvm] [AMDGPU][VOPD] Limit VOPDPairing from reaching over load dependencies (PR #201930)

Joe Nash via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 12 09:08:26 PDT 2026


================
@@ -264,6 +264,31 @@ static bool shouldScheduleVOPDAdjacent(const TargetInstrInfo &TII,
       .has_value();
 }
 
+/// Collect all load (dependents if \p Forward else dependencies) that connect
+/// to \p SU.
+static void collectLoads(SmallVector<SUnit *> &Loads, BitVector &Visited,
+                         const SUnit &SU, bool Forward) {
+  if (SU.isBoundaryNode() || Visited.test(SU.NodeNum))
+    return;
+
+  const SmallVector<SDep, 4> &Deps = Forward ? SU.Succs : SU.Preds;
+  for (const SDep &Edge : Deps) {
+    if (Edge.getKind() != SDep::Data)
+      continue;
+    SUnit *Dep = Edge.getSUnit();
+    if (Dep->isBoundaryNode())
+      continue;
+
+    if (Dep->isInstr() && Dep->getInstr()->mayLoad()) {
+      Loads.push_back(Dep);
+    } else {
+      collectLoads(Loads, Visited, *Dep, Forward);
----------------
Sisyph wrote:

I'm not finding a conclusive LLVM style answer on iteration vs recursion, but this could get quite deep. Worth using iteration instead of recursion, and/or a max depth guard?

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


More information about the llvm-commits mailing list