[llvm] [FuncSpec] Only compute Latency bonus when necessary (PR #113159)
Hari Limaye via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 22 09:16:26 PDT 2024
================
@@ -875,48 +909,67 @@ bool FunctionSpecializer::findSpecializations(Function *F, unsigned FuncSize,
AllSpecs[Index].CallSites.push_back(&CS);
} else {
// Calculate the specialisation gain.
- Bonus B;
+ Cost CodeSize;
unsigned Score = 0;
InstCostVisitor Visitor = getInstCostVisitorFor(F);
for (ArgInfo &A : S.Args) {
- B += Visitor.getSpecializationBonus(A.Formal, A.Actual);
+ CodeSize += Visitor.getCodeSizeSavingsForArg(A.Formal, A.Actual);
Score += getInliningBonus(A.Formal, A.Actual);
}
- B += Visitor.getBonusFromPendingPHIs();
-
+ CodeSize += Visitor.getCodeSizeSavingsFromPendingPHIs();
- LLVM_DEBUG(dbgs() << "FnSpecialization: Specialization bonus {CodeSize = "
- << B.CodeSize << ", Latency = " << B.Latency
- << ", Inlining = " << Score << "}\n");
-
- FunctionGrowth[F] += FuncSize - B.CodeSize;
-
- auto IsProfitable = [](Bonus &B, unsigned Score, unsigned FuncSize,
- unsigned FuncGrowth) -> bool {
+ auto IsProfitable = [&]() -> bool {
// No check required.
if (ForceSpecialization)
return true;
+
+ unsigned CodeSizeSavings = getCostValue(CodeSize);
+ // TODO: We should only accumulate codesize increase of specializations
+ // that are actually created.
+ FunctionGrowth[F] += FuncSize - CodeSizeSavings;
----------------
hazzlim wrote:
> Hmm, but we sometimes early exit due to inlining bonus. Bummer
Yeah, it's somewhat annoying - I've put it where it is for this reason.
>Perhaps we can move it here ...
I think that this would be the ideal place to do the accumulation to `FunctionGrowth[F]`.
Could you clarify what you mean by the following:
> (it is S.Score as long as we remove Score += std::max(CodeSizeSavings, LatencySavings)).
The Score is initially the Inlining Bonus, and then we add `std::max(CodeSizeSavings, LatencySavings))` - do you mean to just simply set `Score = CodeSizeSavings` in the case where we reach this point i.e. we are specializing due to CodeSizeSavings/LatencySavings rather than the Inlining Bonus?
https://github.com/llvm/llvm-project/pull/113159
More information about the llvm-commits
mailing list