[GlobalMerge] Stable sort GlobalSets to fix non-deterministic sort order
authorMandeep Singh Grang <mgrang@codeaurora.org>
Thu, 9 Nov 2017 18:05:17 +0000 (18:05 +0000)
committerMandeep Singh Grang <mgrang@codeaurora.org>
Thu, 9 Nov 2017 18:05:17 +0000 (18:05 +0000)
Summary: This fixes failure in CodeGen/AArch64/global-merge-group-by-use.ll uncovered by D39245.

Reviewers: ab, asl

Reviewed By: ab

Subscribers: aemerson, llvm-commits, kristof.beyls

Differential Revision: https://reviews.llvm.org/D39635

llvm-svn: 317817

llvm/lib/CodeGen/GlobalMerge.cpp

index 52a5737..3254531 100644 (file)
@@ -386,7 +386,7 @@ bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
   //
   // Multiply that by the size of the set to give us a crude profitability
   // metric.
-  std::sort(UsedGlobalSets.begin(), UsedGlobalSets.end(),
+  std::stable_sort(UsedGlobalSets.begin(), UsedGlobalSets.end(),
             [](const UsedGlobalSet &UGS1, const UsedGlobalSet &UGS2) {
               return UGS1.Globals.count() * UGS1.UsageCount <
                      UGS2.Globals.count() * UGS2.UsageCount;