Index: lib/Analysis/IteratedDominanceFrontier.cpp =================================================================== --- lib/Analysis/IteratedDominanceFrontier.cpp +++ lib/Analysis/IteratedDominanceFrontier.cpp @@ -21,15 +21,20 @@ void IDFCalculator::calculate( SmallVectorImpl &PHIBlocks) { // Use a priority queue keyed on dominator tree level so that inserted nodes - // are handled from the bottom of the dominator tree upwards. - typedef std::pair DomTreeNodePair; + // are handled from the bottom of the dominator tree upwards. We also augment + // the level with a DFS number to ensure that the blocks are ordered in a + // deterministic way. + typedef std::pair> + DomTreeNodePair; typedef std::priority_queue, less_second> IDFPriorityQueue; IDFPriorityQueue PQ; + DT.updateDFSNumbers(); + for (BasicBlock *BB : *DefBlocks) { if (DomTreeNode *Node = DT.getNode(BB)) - PQ.push({Node, Node->getLevel()}); + PQ.push({Node, std::make_pair(Node->getLevel(), Node->getDFSNumIn())}); } SmallVector Worklist; @@ -40,7 +45,7 @@ DomTreeNodePair RootPair = PQ.top(); PQ.pop(); DomTreeNode *Root = RootPair.first; - unsigned RootLevel = RootPair.second; + unsigned RootLevel = RootPair.second.first; // Walk all dominator tree children of Root, inspecting their CFG edges with // targets elsewhere on the dominator tree. Only targets whose level is at @@ -77,7 +82,8 @@ PHIBlocks.emplace_back(SuccBB); if (!DefBlocks->count(SuccBB)) - PQ.push(std::make_pair(SuccNode, SuccLevel)); + PQ.push(std::make_pair( + SuccNode, std::make_pair(SuccLevel, SuccNode->getDFSNumIn()))); } for (auto DomChild : *Node) {