[llvm] r339835 - [BFI] Use rounding while computing profile counts.
Easwaran Raman via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 15 17:27:00 PDT 2018
Author: eraman
Date: Wed Aug 15 17:26:59 2018
New Revision: 339835
URL: http://llvm.org/viewvc/llvm-project?rev=339835&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp
llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible_pgo.ll
llvm/trunk/test/Instrumentation/cgprofile.ll
llvm/trunk/unittests/Analysis/BlockFrequencyInfoTest.cpp
Modified: llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp?rev=339835&r1=339834&r2=339835&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp (original)
+++ llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp Wed Aug 15 17:26:59 2018
@@ -573,7 +573,9 @@ BlockFrequencyInfoImplBase::getProfileCo
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();
}
Modified: llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible_pgo.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible_pgo.ll?rev=339835&r1=339834&r2=339835&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible_pgo.ll (original)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible_pgo.ll Wed Aug 15 17:26:59 2018
@@ -146,19 +146,19 @@ indirectgoto:
; CHECK-NEXT: block-frequency-info: _Z11irreduciblePh
; CHECK-NEXT: - entry: {{.*}} count = 1
; CHECK-NEXT: - for.cond1: {{.*}} count = 1
-; CHECK-NEXT: - dispatch_op: {{.*}} count = 201
-; CHECK-NEXT: - dispatch_op.sw.bb6_crit_edge: {{.*}} count = 200
-; CHECK-NEXT: - sw.bb: {{.*}} count = 0
-; CHECK-NEXT: - TARGET_1: {{.*}} count = 299
-; CHECK-NEXT: - sw.bb6: {{.*}} count = 500, irr_loop_header_weight = 501
-; CHECK-NEXT: - if.then: {{.*}} count = 299
-; CHECK-NEXT: - TARGET_2: {{.*}} count = 98
-; CHECK-NEXT: - sw.bb15: {{.*}} count = 99, irr_loop_header_weight = 100
-; CHECK-NEXT: - if.then18: {{.*}} count = 99
+; CHECK-NEXT: - dispatch_op: {{.*}} count = 202
+; CHECK-NEXT: - dispatch_op.sw.bb6_crit_edge: {{.*}} count = 201
+; CHECK-NEXT: - sw.bb: {{.*}} count = 1
+; CHECK-NEXT: - TARGET_1: {{.*}} count = 300
+; CHECK-NEXT: - sw.bb6: {{.*}} count = 501, irr_loop_header_weight = 501
+; CHECK-NEXT: - if.then: {{.*}} count = 300
+; CHECK-NEXT: - TARGET_2: {{.*}} count = 99
+; CHECK-NEXT: - sw.bb15: {{.*}} count = 100, irr_loop_header_weight = 100
+; CHECK-NEXT: - if.then18: {{.*}} count = 100
; CHECK-NEXT: - unknown_op: {{.*}} count = 0
; CHECK-NEXT: - sw.default: {{.*}} count = 0
; CHECK-NEXT: - exit: {{.*}} count = 1
-; CHECK-NEXT: - indirectgoto: {{.*}} count = 399, irr_loop_header_weight = 400
+; CHECK-NEXT: - indirectgoto: {{.*}} count = 400, irr_loop_header_weight = 400
; Missing some irr loop annotations.
; Function Attrs: noinline norecurse nounwind uwtable
Modified: llvm/trunk/test/Instrumentation/cgprofile.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/cgprofile.ll?rev=339835&r1=339834&r2=339835&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/cgprofile.ll (original)
+++ llvm/trunk/test/Instrumentation/cgprofile.ll Wed Aug 15 17:26:59 2018
@@ -38,4 +38,4 @@ B:
; CHECK: ![[e3]] = !{void (i1)* @freq, i32 ()* @func3, i64 150}
; CHECK: ![[e4]] = !{void (i1)* @freq, i32 ()* @func1, i64 10}
; CHECK: ![[e5]] = !{void (i1)* @freq, void ()* @a, i64 11}
-; CHECK: ![[e6]] = !{void (i1)* @freq, void ()* @b, i64 20}
+; CHECK: ![[e6]] = !{void (i1)* @freq, void ()* @b, i64 21}
Modified: llvm/trunk/unittests/Analysis/BlockFrequencyInfoTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/BlockFrequencyInfoTest.cpp?rev=339835&r1=339834&r2=339835&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/BlockFrequencyInfoTest.cpp (original)
+++ llvm/trunk/unittests/Analysis/BlockFrequencyInfoTest.cpp Wed Aug 15 17:26:59 2018
@@ -77,8 +77,10 @@ TEST_F(BlockFrequencyInfoTest, Basic) {
EXPECT_EQ(BFI.getBlockProfileCount(&BB0).getValue(), UINT64_C(100));
EXPECT_EQ(BFI.getBlockProfileCount(BB3).getValue(), UINT64_C(100));
- EXPECT_EQ(BFI.getBlockProfileCount(BB1).getValue(), 100 * BB1Freq / BB0Freq);
- EXPECT_EQ(BFI.getBlockProfileCount(BB2).getValue(), 100 * BB2Freq / BB0Freq);
+ EXPECT_EQ(BFI.getBlockProfileCount(BB1).getValue(),
+ (100 * BB1Freq + BB0Freq / 2) / BB0Freq);
+ EXPECT_EQ(BFI.getBlockProfileCount(BB2).getValue(),
+ (100 * BB2Freq + BB0Freq / 2) / BB0Freq);
// Scale the frequencies of BB0, BB1 and BB2 by a factor of two.
SmallPtrSet<BasicBlock *, 4> BlocksToScale({BB1, BB2});
More information about the llvm-commits
mailing list