[llvm] [FuncSpec] Improve accounting of specialization codesize growth (PR #113448)
Alexandros Lamprineas via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 24 03:05:46 PDT 2024
================
@@ -759,6 +771,14 @@ bool FunctionSpecializer::run() {
SmallVector<Function *> Clones;
for (unsigned I = 0; I < NSpecs; ++I) {
Spec &S = AllSpecs[BestSpecs[I]];
+
+ // Check that creating this specialization doesn't exceed the maximum
+ // codesize growth.
+ unsigned FuncSize = getCostValue(FunctionMetrics[S.F].NumInsts);
+ if ((FunctionGrowth[S.F] + S.CodeSizeCost) / FuncSize > MaxCodeSizeGrowth)
+ continue;
----------------
labrinea wrote:
I think I was wrong before suggesting you to move this here. At this point we have committed on creating `NSpecs` specializations, but now we are skipping some. The filtering needs to happen earlier, inside findSpecializations but after the lambda. At that point we know it is profitable.
The thing is we know we are creating NSpecs but we don't know which ones. They may correspond to different functions. However the FunctionGrowth is kept per function, not per module. Inside findSpecialziations we are only examining specializations for the same function.
It would make sense to apply the filtering here if we kept codesize growth across functions (per module), which isn't the case. Correct me if I am wrong, but that's my understanding. Apologies for the confusion.
https://github.com/llvm/llvm-project/pull/113448
More information about the llvm-commits
mailing list