diff --git a/llvm/include/llvm/ADT/SCCIterator.h b/llvm/include/llvm/ADT/SCCIterator.h --- a/llvm/include/llvm/ADT/SCCIterator.h +++ b/llvm/include/llvm/ADT/SCCIterator.h @@ -348,9 +348,14 @@ NodeInfoMap[Edge->Target].Visited = false; std::queue Queue; - for (auto &Node : NodeInfoMap) - if (Node.second.Visited) - Queue.push(Node.first); + // Initialze the queue with MST roots. Note that walking through SortedEdges + // instead of NodeInfoMap ensures an ordered deterministic push. + for (auto *Edge : SortedEdges) { + if (NodeInfoMap[Edge->Source].Visited) { + Queue.push(Edge->Source); + NodeInfoMap[Edge->Source].Visited = false; + } + } while (!Queue.empty()) { auto *Node = Queue.front();