Skip to content

Commit 511500e

Browse files
[TypeProf][ICP]Allow vtable-comparison as long as vtable count is comparable with function count for each candidate (#106260)
The current cost-benefit analysis between vtable comparison and function comparison require the indirect fallback branch to be cold. This is too conservative. This change allows vtable-comparison as long as vtable count is comparable with function count for each function candidate and removes the cold indirect fallback requirement. Tested: 1. Testing this on benchmarks uplifts the measurable performance wins. Counting the (possibly-duplicated) remarks (because of linkonce_odr functions, cross-module import of functions) show the number of vtable remarks increases from ~30k-ish to 50k-ish. 2. https://gcc.godbolt.org/z/sbGK7Pacn shows vtable-comparison doesn't happen today (using the same IR input)
1 parent a6edcea commit 511500e

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static cl::opt<bool>
117117
// Indirect call promotion pass will fall back to function-based comparison if
118118
// vtable-count / function-count is smaller than this threshold.
119119
static cl::opt<float> ICPVTablePercentageThreshold(
120-
"icp-vtable-percentage-threshold", cl::init(0.99), cl::Hidden,
120+
"icp-vtable-percentage-threshold", cl::init(0.995), cl::Hidden,
121121
cl::desc("The percentage threshold of vtable-count / function-count for "
122122
"cost-benefit analysis."));
123123

@@ -888,14 +888,6 @@ bool IndirectCallPromoter::isProfitableToCompareVTables(
888888
}
889889
}
890890

891-
// If the indirect fallback is not cold, don't compare vtables.
892-
if (PSI && PSI->hasProfileSummary() &&
893-
!PSI->isColdCount(RemainingVTableCount)) {
894-
LLVM_DEBUG(dbgs() << " Indirect fallback basic block is not cold. Bail "
895-
"out for vtable comparison.\n");
896-
return false;
897-
}
898-
899891
return true;
900892
}
901893

llvm/test/Transforms/PGOProfile/icp_vtable_cmp.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ declare i32 @Base2_foo(ptr)
120120
declare i32 @Base1_foo(ptr)
121121
declare void @Base3_foo(ptr)
122122

123+
!llvm.module.flags = !{!11}
123124
!0 = !{i64 16, !"Base1"}
124125
!1 = !{i64 40, !"Base1"}
125126
!2 = !{i64 16, !"Base2"}
@@ -131,6 +132,23 @@ declare void @Base3_foo(ptr)
131132
!8 = !{i64 16, !"Derived3"}
132133
!9 = !{!"VP", i32 2, i64 1600, i64 -4123858694673519054, i64 600, i64 -7211198353767973908, i64 500, i64 -3574436251470806727, i64 200, i64 6288809125658696740, i64 200, i64 12345678, i64 100}
133134
!10 = !{!"VP", i32 0, i64 1600, i64 3827408714133779784, i64 600, i64 5837445539218476403, i64 500, i64 -9064955852395570538, i64 400, i64 56781234, i64 100}
135+
136+
!11 = !{i32 1, !"ProfileSummary", !12}
137+
!12 = !{!13, !14, !15, !16, !17, !18, !19, !20}
138+
!13 = !{!"ProfileFormat", !"InstrProf"}
139+
!14 = !{!"TotalCount", i64 10000}
140+
!15 = !{!"MaxCount", i64 10}
141+
!16 = !{!"MaxInternalCount", i64 1}
142+
!17 = !{!"MaxFunctionCount", i64 1000}
143+
!18 = !{!"NumCounts", i64 3}
144+
!19 = !{!"NumFunctions", i64 3}
145+
!20 = !{!"DetailedSummary", !21}
146+
!21 = !{!22, !23, !24}
147+
!22 = !{i32 10000, i64 101, i32 1}
148+
!23 = !{i32 990000, i64 101, i32 1}
149+
!24 = !{i32 999999, i64 1, i32 2}
150+
151+
134152
;.
135153
; VTABLE-COMMON: [[PROF9]] = !{!"VP", i32 2, i64 100, i64 12345678, i64 100}
136154
; VTABLE-COMMON: [[PROF10]] = !{!"branch_weights", i32 600, i32 1000}

0 commit comments

Comments
 (0)