From 5a654b01133fe5f5b2b4088495f829bb8c34e12d Mon Sep 17 00:00:00 2001 From: Amir Ayupov Date: Wed, 19 Jan 2022 20:20:55 -0800 Subject: [PATCH] [BOLT] Make ICP target selection (more) deterministic Summary: Break ties by selecting targets with lower addresses. Reviewers: maksfb FBD33677001 --- bolt/lib/Passes/IndirectCallPromotion.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bolt/lib/Passes/IndirectCallPromotion.cpp b/bolt/lib/Passes/IndirectCallPromotion.cpp index 4f16041..4104cc9 100644 --- a/bolt/lib/Passes/IndirectCallPromotion.cpp +++ b/bolt/lib/Passes/IndirectCallPromotion.cpp @@ -292,17 +292,18 @@ IndirectCallPromotion::getCallTargets(BinaryBasicBlock &BB, } } - // Sort by target count, number of indices in case of jump table, and - // mispredicts. We prioritize targets with high count, small number of - // indices and high mispredicts + // Sort by target count, number of indices in case of jump table, and + // mispredicts. We prioritize targets with high count, small number of indices + // and high mispredicts. Break ties by selecting targets with lower addresses. std::stable_sort(Targets.begin(), Targets.end(), [](const Callsite &A, const Callsite &B) { if (A.Branches != B.Branches) return A.Branches > B.Branches; - else if (A.JTIndices.size() != B.JTIndices.size()) + if (A.JTIndices.size() != B.JTIndices.size()) return A.JTIndices.size() < B.JTIndices.size(); - else + if (A.Mispreds != B.Mispreds) return A.Mispreds > B.Mispreds; + return A.To.Addr < B.To.Addr; }); // Remove non-symbol targets -- 2.7.4