Skip to content

Add minimum count threshold for indirect call promotion #145282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions llvm/lib/Analysis/IndirectCallPromotionAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ static cl::opt<unsigned> ICPRemainingPercentThreshold(

// The percent threshold for the direct-call target (this call site vs the
// total call count) for it to be considered as the promotion target.
static cl::opt<unsigned>
static cl::opt<uint64_t>
ICPTotalPercentThreshold("icp-total-percent-threshold", cl::init(5),
cl::Hidden,
cl::desc("The percentage threshold against total "
"count for the promotion"));

// Set the minimum absolute count threshold for indirect call promotion.
// Candidates with counts below this threshold will not be promoted.
static cl::opt<unsigned> ICPMinimumCountThreshold(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be uint64_t to match the type of the Count it is being compared against?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"icp-minimum-count-threshold", cl::init(0), cl::Hidden,
cl::desc("Minimum absolute count for promotion candidate"));

// Set the maximum number of targets to promote for a single indirect-call
// callsite.
static cl::opt<unsigned>
Expand All @@ -51,7 +57,8 @@ cl::opt<unsigned> MaxNumVTableAnnotations(
bool ICallPromotionAnalysis::isPromotionProfitable(uint64_t Count,
uint64_t TotalCount,
uint64_t RemainingCount) {
return Count * 100 >= ICPRemainingPercentThreshold * RemainingCount &&
return Count >= ICPMinimumCountThreshold &&
Count * 100 >= ICPRemainingPercentThreshold * RemainingCount &&
Count * 100 >= ICPTotalPercentThreshold * TotalCount;
}

Expand Down
14 changes: 14 additions & 0 deletions llvm/test/Transforms/PGOProfile/indirect_call_promotion.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
; RUN: opt < %s -passes=pgo-icall-prom -S -icp-total-percent-threshold=50 | FileCheck %s --check-prefix=ICALL-PROM
; RUN: opt < %s -passes=pgo-icall-prom -S -pass-remarks=pgo-icall-prom -icp-remaining-percent-threshold=0 -icp-total-percent-threshold=0 -icp-max-prom=4 2>&1 | FileCheck %s --check-prefix=PASS-REMARK
; RUN: opt < %s -passes=pgo-icall-prom -S -pass-remarks=pgo-icall-prom -icp-remaining-percent-threshold=0 -icp-total-percent-threshold=20 -icp-max-prom=4 2>&1 | FileCheck %s --check-prefix=PASS2-REMARK
; Test minimum count threshold - should prevent func1 promotion (count 10 < threshold 15)
; RUN: opt < %s -passes=pgo-icall-prom -S -pass-remarks=pgo-icall-prom -icp-minimum-count-threshold=15 -icp-remaining-percent-threshold=0 -icp-total-percent-threshold=0 -icp-max-prom=4 2>&1 | FileCheck %s --check-prefix=MIN-COUNT-15
; Test edge case - threshold exactly at count value
; RUN: opt < %s -passes=pgo-icall-prom -S -pass-remarks=pgo-icall-prom -icp-minimum-count-threshold=10 -icp-remaining-percent-threshold=0 -icp-total-percent-threshold=0 -icp-max-prom=4 2>&1 | FileCheck %s --check-prefix=MIN-COUNT-10

; PASS-REMARK: remark: <unknown>:0:0: Promote indirect call to func4 with count 1030 out of 1600
; PASS-REMARK: remark: <unknown>:0:0: Promote indirect call to func2 with count 410 out of 570
Expand All @@ -12,6 +16,16 @@
; PASS2-REMARK-NOT: remark: <unknown>:0:0: Promote indirect call to func3
; PASS2-REMARK-NOT: remark: <unknown>:0:0: Promote indirect call to func1

; MIN-COUNT-15: remark: <unknown>:0:0: Promote indirect call to func4 with count 1030 out of 1600
; MIN-COUNT-15: remark: <unknown>:0:0: Promote indirect call to func2 with count 410 out of 570
; MIN-COUNT-15: remark: <unknown>:0:0: Promote indirect call to func3 with count 150 out of 160
; MIN-COUNT-15-NOT: remark: <unknown>:0:0: Promote indirect call to func1

; MIN-COUNT-10: remark: <unknown>:0:0: Promote indirect call to func4 with count 1030 out of 1600
; MIN-COUNT-10: remark: <unknown>:0:0: Promote indirect call to func2 with count 410 out of 570
; MIN-COUNT-10: remark: <unknown>:0:0: Promote indirect call to func3 with count 150 out of 160
; MIN-COUNT-10: remark: <unknown>:0:0: Promote indirect call to func1 with count 10 out of 10

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

Expand Down
Loading