aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineBlockPlacement.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2020-02-18 17:13:21 -0800
committerBill Wendling <isanbard@gmail.com>2020-02-19 11:33:48 -0800
commit129c911efaa492790c251b3eb18e4db36b55cbc5 (patch)
tree7b998cec77842aaaef540d9080dcea769d68749c /llvm/lib/CodeGen/MachineBlockPlacement.cpp
parent076475713c236081a3247a53e9dbab9043c3eac2 (diff)
downloadllvm-129c911efaa492790c251b3eb18e4db36b55cbc5.zip
llvm-129c911efaa492790c251b3eb18e4db36b55cbc5.tar.gz
llvm-129c911efaa492790c251b3eb18e4db36b55cbc5.tar.bz2
Include static prof data when collecting loop BBs
Summary: If the programmer adds static profile data to a branch---i.e. uses "__builtin_expect()" or similar---then we should honor it. Otherwise, "__builtin_expect()" is ignored in crucial situations. So we trust that the programmer knows what they're doing until proven wrong. Subscribers: hiraditya, JDevlieghere, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D74809
Diffstat (limited to 'llvm/lib/CodeGen/MachineBlockPlacement.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineBlockPlacement.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index 3149151..5ce4390 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -2506,9 +2506,14 @@ MachineBlockPlacement::collectLoopBlockSet(const MachineLoop &L) {
// its frequency and the frequency of the loop block. When it is too small,
// don't add it to the loop chain. If there are outer loops, then this block
// will be merged into the first outer loop chain for which this block is not
- // cold anymore. This needs precise profile data and we only do this when
- // profile data is available.
- if (F->getFunction().hasProfileData() || ForceLoopColdBlock) {
+ // cold anymore.
+ //
+ // If a block uses static profiling data (e.g. from '__builtin_expect()'),
+ // then the programmer is explicitly telling us which paths are hot and cold.
+ // There's no reason for the compiler to believe otherwise, unless
+ // '-fprofile-use' is specified.
+ if (F->getFunction().hasProfileData() || ForceLoopColdBlock ||
+ L.hasStaticProfInfo()) {
BlockFrequency LoopFreq(0);
for (auto LoopPred : L.getHeader()->predecessors())
if (!L.contains(LoopPred))