[BFI] Use rounding while computing profile counts.
Summary:
Profile count of a block is computed by multiplying its block frequency
by entry count and dividing the result by entry block frequency. Do
rounded division in the last step and update test cases appropriately.
Reviewers: davidxl
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D50822
llvm-svn: 339835
diff --git a/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp b/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
index 3d09506..9820988 100644
--- a/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
+++ b/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
@@ -573,7 +573,9 @@
APInt BlockFreq(128, Freq);
APInt EntryFreq(128, getEntryFreq());
BlockCount *= BlockFreq;
- BlockCount = BlockCount.udiv(EntryFreq);
+ // Rounded division of BlockCount by EntryFreq. Since EntryFreq is unsigned
+ // lshr by 1 gives EntryFreq/2.
+ BlockCount = (BlockCount + EntryFreq.lshr(1)).udiv(EntryFreq);
return BlockCount.getLimitedValue();
}