diff options
author | Easwaran Raman <eraman@google.com> | 2017-02-14 22:49:28 +0000 |
---|---|---|
committer | Easwaran Raman <eraman@google.com> | 2017-02-14 22:49:28 +0000 |
commit | 5a12f236c655b266966cb97727739d493df3d6c4 (patch) | |
tree | d6082d8ed38d7a7d60823ff9d61f93e293bbcf3f /llvm/lib/Transforms/Utils/InlineFunction.cpp | |
parent | 52d0aaac139ae8804f31970fa96f5debbe94deee (diff) | |
download | bcm5719-llvm-5a12f236c655b266966cb97727739d493df3d6c4.tar.gz bcm5719-llvm-5a12f236c655b266966cb97727739d493df3d6c4.zip |
Fix a bug in caller's BFI update code after inlining.
Multiple blocks in the callee can be mapped to a single cloned block
since we prune the callee as we clone it. The existing code
iterates over the value map and clones the block frequency (and
eventually scales the frequencies of the cloned blocks). Value map's
iteration is not deterministic and so the cloned block might get the
frequency of any of the original blocks. The fix is to set the max of
the original frequencies to the cloned block. The first block in the
sequence must have this max frequency and, in the call context,
subsequent blocks must have its frequency.
Differential Revision: https://reviews.llvm.org/D29696
llvm-svn: 295115
Diffstat (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/InlineFunction.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index 86f40c32dc0..0cf5145035f 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1411,9 +1411,16 @@ static void updateCallerBFI(BasicBlock *CallSiteBlock, continue; auto *OrigBB = cast<BasicBlock>(Entry.first); auto *ClonedBB = cast<BasicBlock>(Entry.second); - ClonedBBs.insert(ClonedBB); - CallerBFI->setBlockFreq(ClonedBB, - CalleeBFI->getBlockFreq(OrigBB).getFrequency()); + uint64_t Freq = CalleeBFI->getBlockFreq(OrigBB).getFrequency(); + if (!ClonedBBs.insert(ClonedBB).second) { + // Multiple blocks in the callee might get mapped to one cloned block in + // the caller since we prune the callee as we clone it. When that happens, + // we want to use the maximum among the original blocks' frequencies. + uint64_t NewFreq = CallerBFI->getBlockFreq(ClonedBB).getFrequency(); + if (NewFreq > Freq) + Freq = NewFreq; + } + CallerBFI->setBlockFreq(ClonedBB, Freq); } BasicBlock *EntryClone = cast<BasicBlock>(VMap.lookup(&CalleeEntryBlock)); CallerBFI->setBlockFreqAndScale( |