Skip to content

Commit bc0e0f5

Browse files
snehasishAnthony Tran
authored andcommitted
Add minimum count threshold for indirect call promotion (llvm#145282)
Allow users to set the minimum absolute count for indirect call promotion. This is primarily meant to be control indirect call promotion for synthetic vp metadata introduced in llvm#141164 for use by MemProf.
1 parent 372af29 commit bc0e0f5

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

llvm/lib/Analysis/IndirectCallPromotionAnalysis.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ static cl::opt<unsigned> ICPRemainingPercentThreshold(
3131

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

40+
// Set the minimum absolute count threshold for indirect call promotion.
41+
// Candidates with counts below this threshold will not be promoted.
42+
static cl::opt<unsigned> ICPMinimumCountThreshold(
43+
"icp-minimum-count-threshold", cl::init(0), cl::Hidden,
44+
cl::desc("Minimum absolute count for promotion candidate"));
45+
4046
// Set the maximum number of targets to promote for a single indirect-call
4147
// callsite.
4248
static cl::opt<unsigned>
@@ -51,7 +57,8 @@ cl::opt<unsigned> MaxNumVTableAnnotations(
5157
bool ICallPromotionAnalysis::isPromotionProfitable(uint64_t Count,
5258
uint64_t TotalCount,
5359
uint64_t RemainingCount) {
54-
return Count * 100 >= ICPRemainingPercentThreshold * RemainingCount &&
60+
return Count >= ICPMinimumCountThreshold &&
61+
Count * 100 >= ICPRemainingPercentThreshold * RemainingCount &&
5562
Count * 100 >= ICPTotalPercentThreshold * TotalCount;
5663
}
5764

llvm/test/Transforms/PGOProfile/indirect_call_promotion.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
; RUN: opt < %s -passes=pgo-icall-prom -S -icp-total-percent-threshold=50 | FileCheck %s --check-prefix=ICALL-PROM
22
; 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
33
; 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
4+
; Test minimum count threshold - should prevent func1 promotion (count 10 < threshold 15)
5+
; 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
6+
; Test edge case - threshold exactly at count value
7+
; 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
48

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

19+
; MIN-COUNT-15: remark: <unknown>:0:0: Promote indirect call to func4 with count 1030 out of 1600
20+
; MIN-COUNT-15: remark: <unknown>:0:0: Promote indirect call to func2 with count 410 out of 570
21+
; MIN-COUNT-15: remark: <unknown>:0:0: Promote indirect call to func3 with count 150 out of 160
22+
; MIN-COUNT-15-NOT: remark: <unknown>:0:0: Promote indirect call to func1
23+
24+
; MIN-COUNT-10: remark: <unknown>:0:0: Promote indirect call to func4 with count 1030 out of 1600
25+
; MIN-COUNT-10: remark: <unknown>:0:0: Promote indirect call to func2 with count 410 out of 570
26+
; MIN-COUNT-10: remark: <unknown>:0:0: Promote indirect call to func3 with count 150 out of 160
27+
; MIN-COUNT-10: remark: <unknown>:0:0: Promote indirect call to func1 with count 10 out of 10
28+
1529
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
1630
target triple = "x86_64-unknown-linux-gnu"
1731

0 commit comments

Comments
 (0)