From aca738b7424189e4937295de9f297124cc07b10f Mon Sep 17 00:00:00 2001 From: Easwaran Raman Date: Thu, 16 Aug 2018 00:26:59 +0000 Subject: [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 --- llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp') diff --git a/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp b/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp index 3d095068e7f..98209888f8a 100644 --- a/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp +++ b/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp @@ -573,7 +573,9 @@ BlockFrequencyInfoImplBase::getProfileCountFromFreq(const Function &F, 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(); } -- cgit v1.2.3