[llvm] [FnSpecialization] Enable function specialization of call chains (PR #163891)

Ryan Buchner via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 28 00:13:16 PDT 2025


bababuck wrote:

Sorry for the slow response, and thanks for taking the time to engage.

> Perhaps it's best to handle non constant foldable calls in the instruction cost visitor separately, similarly to branches and switches which are not folded to a constant.

I think that is a competitive approach, here were my pro's/con's between the two approaches:
Pro's of approach in patch:
- Able to handle indirect function calls that are constants. Since currently we visit each instruction one argument as a time, the second approach would require additional caching logic to handle this.
- Can handle chained specialization in a single `run()` loop, doesn't run the risk of specializing the first layer and not the second (in the case where max iterations is hit, or maximum code-size is reached.) At least if my understanding is correct, the cost metric would allow the outer function to specialize due to the savings of the inner function. Then in the next iteration, the inner function would specialize.

Pro's of the approach you suggested:
- Much cleaner implementation, only need to extend a single area of the code

> But then all this adds compile time complexity which I am not sure it is worth it.

We were looking into this for a particular case in `x264` which we wanted to optimize, but I can collect data on how this code behaves on other workloads.

https://github.com/llvm/llvm-project/pull/163891


More information about the llvm-commits mailing list