From dc2f2d2180f1d1a1835dc55478d3bcceea41a4b1 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Thu, 23 Mar 2023 09:15:57 -0700 Subject: [PATCH] [MemProf] Use stable_sort to avoid non-determinism Switch from std::sort to std::stable_sort when sorting callsites to avoid non-determinism when the comparisons are equal. This showed up in internal testing of fe27495be2040007c7b20844a9371b06156ab405. --- llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp index b2fcea1..762e4ce0 100644 --- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp +++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp @@ -1032,13 +1032,13 @@ void CallsiteContextGraph::updateStackNodes() { // latter is so that we can specially handle calls that have identical stack // id sequences (either due to cloning or artificially because of the MIB // context pruning). - std::sort(Calls.begin(), Calls.end(), - [](const CallContextInfo &A, const CallContextInfo &B) { - auto &IdsA = std::get<1>(A); - auto &IdsB = std::get<1>(B); - return IdsA.size() > IdsB.size() || - (IdsA.size() == IdsB.size() && IdsA < IdsB); - }); + std::stable_sort(Calls.begin(), Calls.end(), + [](const CallContextInfo &A, const CallContextInfo &B) { + auto &IdsA = std::get<1>(A); + auto &IdsB = std::get<1>(B); + return IdsA.size() > IdsB.size() || + (IdsA.size() == IdsB.size() && IdsA < IdsB); + }); // Find the node for the last stack id, which should be the same // across all calls recorded for this id, and is the id for this -- 2.7.4