[PATCH] D93838: [SCCP] Add Function Specialization pass

Chuanqi Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 19 20:28:51 PDT 2021


ChuanqiXu added a comment.

In D93838#2770203 <https://reviews.llvm.org/D93838#2770203>, @davidxl wrote:

> When compiler analyzes the callsite to spec_qsort, it sees the constant function pointer passed to the callee. During the callee body analysis, when the indirect callsite is seen, it will be simplified/evaluated to be the callsite constant thus the compare call can be resolved. If compiler decides that the compare call can be further inlined, it will give the original callsite additional bonus for inlining.  Once spec_qsort is inlined, the compare function call will be inlined further.
>
> I can imagine a fix in the inliner cost analysis to give the call to spec_qsort a bigger bonus when it sees that the compare function is also locally hot (e.g used in a loop). Does it make sense?

It doesn't make sense to me. There are two  reasons:

- We can't inline every thing. Maybe it is possible to inline spec_qsort by give a bigger bonus. However, we could construct an example easily that a function with a function pointer as parameter too large to infeasible to inline.
- Consider the following example:

  spec_qsort(arc_compare);
  spec_qsort(arc_compare);
  spec_qsort(arc_compare);
  spec_qsort(arc_compare);
  spec_qsort(cost_compare);
  spec_qsort(cost_compare);
  spec_qsort(cost_compare);

Then we could construct two specialization for spec_qsort to solve the problem. And we need to inline seven times for sepc_qsort. When spec_qsort becomes bigger, the difference would be more clear.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93838/new/

https://reviews.llvm.org/D93838



More information about the llvm-commits mailing list