diff --git a/llvm/include/llvm/CodeGen/MachinePipeliner.h b/llvm/include/llvm/CodeGen/MachinePipeliner.h index 24e85a953d47..49276fb1a94d 100644 --- a/llvm/include/llvm/CodeGen/MachinePipeliner.h +++ b/llvm/include/llvm/CodeGen/MachinePipeliner.h @@ -330,10 +330,22 @@ public: NodeSet() = default; NodeSet(iterator S, iterator E) : Nodes(S, E), HasRecurrence(true) { Latency = 0; - for (unsigned i = 0, e = Nodes.size(); i < e; ++i) - for (const SDep &Succ : Nodes[i]->Succs) - if (Nodes.count(Succ.getSUnit())) - Latency += Succ.getLatency(); + for (unsigned i = 0, e = Nodes.size(); i < e; ++i) { + DenseMap SuccSUnitLatency; + for (const SDep &Succ : Nodes[i]->Succs) { + auto SuccSUnit = Succ.getSUnit(); + if (!Nodes.count(SuccSUnit)) + continue; + unsigned CurLatency = Succ.getLatency(); + unsigned MaxLatency = 0; + if (SuccSUnitLatency.count(SuccSUnit)) + MaxLatency = SuccSUnitLatency[SuccSUnit]; + if (CurLatency > MaxLatency) + SuccSUnitLatency[SuccSUnit] = CurLatency; + } + for (auto SUnitLatency : SuccSUnitLatency) + Latency += SUnitLatency.second; + } } bool insert(SUnit *SU) { return Nodes.insert(SU); }