Skip to content

Commit

Permalink
[BOLT] Make ICP target selection (more) deterministic
Browse files Browse the repository at this point in the history
Summary: Break ties by selecting targets with lower addresses.

Reviewers: maksfb

FBD33677001
  • Loading branch information
aaupov committed Jan 21, 2022
1 parent f18fcda commit 5a654b0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions bolt/lib/Passes/IndirectCallPromotion.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 5a654b0

Please sign in to comment.