[PATCH] D26370: Use max(BFI_Count, TotalProfCount) to get block's profile count.

Dehao Chen via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 7 13:30:04 PST 2016


danielcdh created this revision.
danielcdh added reviewers: davidxl, eraman.
danielcdh added a subscriber: llvm-commits.

For Sample PGO, BFI count may be inaccurate due to errors during propagation. In this patch, another mechanism is added to make sure the block's profile count is no less than the total prof count extracted from the metadata. A similar mechanism was introduced to inliner in r275073.


https://reviews.llvm.org/D26370

Files:
  lib/Analysis/BlockFrequencyInfo.cpp
  test/Transforms/LoopUnroll/loop-remarks-with-hotness.ll


Index: test/Transforms/LoopUnroll/loop-remarks-with-hotness.ll
===================================================================
--- test/Transforms/LoopUnroll/loop-remarks-with-hotness.ll
+++ test/Transforms/LoopUnroll/loop-remarks-with-hotness.ll
@@ -2,7 +2,9 @@
 ; RUN: opt < %s -S -loop-unroll -pass-remarks=loop-unroll -pass-remarks-with-hotness -unroll-count=4 2>&1 | FileCheck -check-prefix=PARTIAL-UNROLL %s
 
 ; COMPLETE-UNROLL: remark: {{.*}}: completely unrolled loop with 16 iterations (hotness: 300)
+; COMPLETE-UNROLL: remark: {{.*}}: completely unrolled loop with 16 iterations (hotness: 1000)
 ; PARTIAL-UNROLL: remark: {{.*}}: unrolled loop by a factor of 4 {{.*}} (hotness: 300)
+; PARTIAL-UNROLL: remark: {{.*}}: unrolled loop by a factor of 4 {{.*}} (hotness: 1000)
 
 define i32 @sum() !prof !0 {
 entry:
@@ -22,7 +24,26 @@
   ret i32 %add1
 }
 
+define i32 @sum2() !prof !0 {
+entry:
+  br label %for.body
+
+for.body:                                         ; preds = %for.body, %entry
+  %s.06 = phi i32 [ 0, %entry ], [ %add1, %for.body ]
+  %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+  %add = add nsw i32 %i.05, 4
+  %call = tail call i32 @baz(i32 %add) #2
+  %add1 = add nsw i32 %call, %s.06
+  %inc = add nsw i32 %i.05, 1
+  %exitcond = icmp eq i32 %inc, 16
+  br i1 %exitcond, label %for.end, label %for.body, !prof !2
+
+for.end:                                          ; preds = %for.body
+  ret i32 %add1
+}
+
 declare i32 @baz(i32)
 
 !0 = !{!"function_entry_count", i64 3}
 !1 = !{!"branch_weights", i32 1, i32 99}
+!2 = !{!"branch_weights", i32 10, i32 990}
Index: lib/Analysis/BlockFrequencyInfo.cpp
===================================================================
--- lib/Analysis/BlockFrequencyInfo.cpp
+++ lib/Analysis/BlockFrequencyInfo.cpp
@@ -156,7 +156,16 @@
   if (!BFI)
     return None;
 
-  return BFI->getBlockProfileCount(*getFunction(), BB);
+  auto BFICount = BFI->getBlockProfileCount(*getFunction(), BB);
+  if (!BFICount)
+    return None;
+
+  uint64_t SampleCount;
+  if (BB->getTerminator()->extractProfTotalWeight(SampleCount) &&
+      SampleCount > *BFICount)
+    return SampleCount;
+  else
+    return BFICount;
 }
 
 Optional<uint64_t>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26370.77091.patch
Type: text/x-patch
Size: 2215 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161107/7ff87d70/attachment.bin>


More information about the llvm-commits mailing list