diff --git a/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h b/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h --- a/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h +++ b/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h @@ -66,6 +66,8 @@ bool isIrrLoopHeader(const MachineBasicBlock *MBB); + void setBlockFreq(const MachineBasicBlock *MBB, uint64_t Freq); + const MachineFunction *getFunction() const; const MachineBranchProbabilityInfo *getMBPI() const; void view(const Twine &Name, bool isSimple = true) const; diff --git a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp --- a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp +++ b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp @@ -247,6 +247,12 @@ return MBFI->isIrrLoopHeader(MBB); } +void MachineBlockFrequencyInfo::setBlockFreq(const MachineBasicBlock *MBB, + uint64_t Freq) { + assert(MBFI && "Expected analysis to be available"); + MBFI->setBlockFreq(MBB, Freq); +} + const MachineFunction *MachineBlockFrequencyInfo::getFunction() const { return MBFI ? MBFI->getFunction() : nullptr; } diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp --- a/llvm/lib/CodeGen/MachineSink.cpp +++ b/llvm/lib/CodeGen/MachineSink.cpp @@ -91,7 +91,7 @@ MachineDominatorTree *DT; // Machine dominator tree MachinePostDominatorTree *PDT; // Machine post dominator tree MachineLoopInfo *LI; - const MachineBlockFrequencyInfo *MBFI; + MachineBlockFrequencyInfo *MBFI; const MachineBranchProbabilityInfo *MBPI; AliasAnalysis *AA; @@ -351,6 +351,11 @@ << printMBBReference(*Pair.first) << " -- " << printMBBReference(*NewSucc) << " -- " << printMBBReference(*Pair.second) << '\n'); + if (MBFI) { + auto NewSuccFreq = MBFI->getBlockFreq(Pair.first) * + MBPI->getEdgeProbability(Pair.first, NewSucc); + MBFI->setBlockFreq(NewSucc, NewSuccFreq.getFrequency()); + } MadeChange = true; ++NumSplit; } else diff --git a/llvm/test/CodeGen/X86/machine-sink.ll b/llvm/test/CodeGen/X86/machine-sink.ll --- a/llvm/test/CodeGen/X86/machine-sink.ll +++ b/llvm/test/CodeGen/X86/machine-sink.ll @@ -1,4 +1,5 @@ ; RUN: llc < %s -mtriple=x86_64-pc-linux | FileCheck %s +; RUN: llc < %s -mtriple=x86_64-pc-linux -check-bfi-unknown-block-queries=true | FileCheck %s ; Checks if movl $1 is sinked to critical edge. ; CHECK-NOT: movl $1