diff --git a/llvm/include/llvm/CodeGen/MachinePipeliner.h b/llvm/include/llvm/CodeGen/MachinePipeliner.h --- a/llvm/include/llvm/CodeGen/MachinePipeliner.h +++ b/llvm/include/llvm/CodeGen/MachinePipeliner.h @@ -334,20 +334,21 @@ NodeSet(iterator S, iterator E) : Nodes(S, E), HasRecurrence(true) { Latency = 0; for (unsigned i = 0, e = Nodes.size(); i < e; ++i) { - DenseMap SuccSUnitLatency; + // The next node is either the next node in the list, or the backedge to + // the first node + SUnit *NextSUnit = ((i + 1) == e) ? Nodes[0] : Nodes[i + 1]; + + // Calculate the maximum latency to NextSUnit from Nodes[i] + unsigned SuccLatency = 0; for (const SDep &Succ : Nodes[i]->Succs) { - auto SuccSUnit = Succ.getSUnit(); - if (!Nodes.count(SuccSUnit)) + SUnit *SuccSUnit = Succ.getSUnit(); + if (SuccSUnit->NodeNum != NextSUnit->NodeNum) continue; unsigned CurLatency = Succ.getLatency(); - unsigned MaxLatency = 0; - if (SuccSUnitLatency.count(SuccSUnit)) - MaxLatency = SuccSUnitLatency[SuccSUnit]; - if (CurLatency > MaxLatency) - SuccSUnitLatency[SuccSUnit] = CurLatency; + if (CurLatency > SuccLatency) + SuccLatency = CurLatency; } - for (auto SUnitLatency : SuccSUnitLatency) - Latency += SUnitLatency.second; + Latency += SuccLatency; } }