[PATCH] D158664: [PSI] Use zero function entry count info when getting profile count for calls

Shimin Cui via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 13:09:46 PDT 2023


scui created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
scui requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently the BFI basic block ProfileCount is used when trying to getProfileCount for callsites. There are situations this count information may be inaccurate, for example, when the callsite code region is a result of inlining of a function without profile information to the caller which is profiled. This is to use the function entry count information from the called function when it contains the profile information and its function entry count is zero.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158664

Files:
  llvm/lib/Analysis/ProfileSummaryInfo.cpp
  llvm/test/Transforms/Inline/inline-zero-count-call.ll


Index: llvm/test/Transforms/Inline/inline-zero-count-call.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/inline-zero-count-call.ll
@@ -0,0 +1,62 @@
+; RUN: opt < %s -passes='require<profile-summary>,cgscc(inline)' -S | FileCheck %s
+
+; This tests a call to a function with zero entry count while no profile data
+; is available for the basic block of the call site.
+
+define void  @noprofile_f(i32 %n) "function-inline-cost"="15" {
+; CHECK-LABEL: define void @noprofile_f
+; CHECK:       cond_false:
+; CHECK-NEXT:    call void @zero_count_f()
+; CHECK-NEXT:    ret void
+;
+  %cond = icmp sle i32 %n, 10
+  br i1 %cond, label %cond_true, label %cond_false
+cond_true:
+  call void @extern_f()
+  ret void
+cond_false:
+  call void @zero_count_f()
+  ret void
+}
+
+define void @pprofile_f(i32 %n) !prof !16 {
+; CHECK-LABEL: define void @pprofile_f
+; CHECK:       cond_false:
+; CHECK-NEXT:    call void @zero_count_f()
+; CHECK-NEXT:    ret void
+;
+  %cond = icmp sle i32 %n, 10
+  br i1 %cond, label %cond_true, label %cond_false
+cond_true:
+  call void @extern_f()
+  ret void
+cond_false:
+  call void @zero_count_f()
+  ret void
+}
+
+define void @zero_count_f() #0  "function-inline-cost"="75" !prof !15 {
+  ret void
+}
+
+declare void @extern_f()
+attributes #0 = { cold }
+
+!15 = !{!"function_entry_count", i64 0}
+!16 = !{!"function_entry_count", i64 1000000}
+
+!llvm.module.flags = !{!1}
+!1 = !{i32 1, !"ProfileSummary", !2}
+!2 = !{!3, !4, !5, !6, !7, !8, !9, !10}
+!3 = !{!"ProfileFormat", !"InstrProf"}
+!4 = !{!"TotalCount", i64 1000000}
+!5 = !{!"MaxCount", i64 1000000}
+!6 = !{!"MaxInternalCount", i64 1}
+!7 = !{!"MaxFunctionCount", i64 1000000}
+!8 = !{!"NumCounts", i64 100}
+!9 = !{!"NumFunctions", i64 100}
+!10 = !{!"DetailedSummary", !11}
+!11 = !{!12, !13, !14}
+!12 = !{i32 10000, i64 100, i32 1}
+!13 = !{i32 990000, i64 100, i32 1}
+!14 = !{i32 999999, i64 1, i32 2}
Index: llvm/lib/Analysis/ProfileSummaryInfo.cpp
===================================================================
--- llvm/lib/Analysis/ProfileSummaryInfo.cpp
+++ llvm/lib/Analysis/ProfileSummaryInfo.cpp
@@ -90,6 +90,11 @@
       return TotalCount;
     return std::nullopt;
   }
+  if (auto *Called = Call.getCalledFunction()) {
+    auto CalledCount = Called->getEntryCount();
+    if (CalledCount && !CalledCount->getCount())
+      return 0;
+  }
   if (BFI)
     return BFI->getBlockProfileCount(Call.getParent(), AllowSynthetic);
   return std::nullopt;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158664.552855.patch
Type: text/x-patch
Size: 2538 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230823/d5eb9be9/attachment.bin>


More information about the llvm-commits mailing list