From 8c60365d74acff80046c6981f6379368bc9826e8 Mon Sep 17 00:00:00 2001 From: Mandeep Singh Grang Date: Thu, 9 Nov 2017 18:05:17 +0000 Subject: [PATCH] [GlobalMerge] Stable sort GlobalSets to fix non-deterministic sort order 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp index 52a5737..3254531 100644 --- a/llvm/lib/CodeGen/GlobalMerge.cpp +++ b/llvm/lib/CodeGen/GlobalMerge.cpp @@ -386,7 +386,7 @@ bool GlobalMerge::doMerge(SmallVectorImpl &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; -- 2.7.4