[llvm] dc2f2d2 - [MemProf] Use stable_sort to avoid non-determinism

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 23 09:21:17 PDT 2023


Author: Teresa Johnson
Date: 2023-03-23T09:20:39-07:00
New Revision: dc2f2d2180f1d1a1835dc55478d3bcceea41a4b1

URL: https://github.com/llvm/llvm-project/commit/dc2f2d2180f1d1a1835dc55478d3bcceea41a4b1
DIFF: https://github.com/llvm/llvm-project/commit/dc2f2d2180f1d1a1835dc55478d3bcceea41a4b1.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index b2fcea1ec869..762e4ce0c3e7 100644
--- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
+++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
@@ -1032,13 +1032,13 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::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


        


More information about the llvm-commits mailing list