[llvm] [FnSpecialization] Only accept codesize savings if strictly greater than the minimum amount (PR #164867)
Ryan Buchner via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 27 23:37:10 PDT 2025
bababuck wrote:
Sorry for the slow response, out on trip. Thanks for taking the time to respond.
> > When MinCodeSizeSavings is set by default to 20, so if FuncSize < 5 all allowed by the knob, then MinCodeSizeSavings * FuncSize / 100 evaluates to 0. As a result, a CodeSizeSavings of 0 will pass this check and be possibly considered profitable.
>
> 20% is the bare minimum threshold (see https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp#L72), you are now making it higher. With your change given MinCodeSizeSavings=25 and FuncSize=4 a specialization is not profitable, since MinCodeSizeSavings must be at least 50%.
Would something like the following be preferable? It would leave the behavior the same in the case you mention.
```
auto IsProfitable = [&]() -> bool {
...
- if (CodeSizeSavings < MinCodeSizeSavings * FuncSize / 100)
+ if ((CodeSizeSavings < MinCodeSizeSavings * FuncSize / 100) && CodeSizeSavings > 0)
return false;
...
};
```
> > Prior to this change, unprofitable_spec specializes (with --funcspec-min-function-size=0) despite not having any savings.
>
> Again I am not seeing the issue here. 20% of zero is zero, --funcspec-min-function-size=0 suggests the user wants everything to be considered profitable.
My understanding is that `--funcspec-min-function-size=0` would imply that the user would want all functions to be considered regardless of size, and that `--funcspec-min-codesize-savings=0` would imply that everything should be considered profitable with respect to code size.
https://github.com/llvm/llvm-project/pull/164867
More information about the llvm-commits
mailing list