[llvm] [FuncSpec] Consider literal constants of recursive functions (PR #111162)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 01:01:32 PDT 2024


david-arm wrote:

Hi @hazzlim, I do understand why you want to make this change, because it can lead to a significant gain in the bwaves benchmark (in combination with PR #111163). However, it feels like this patch is adding a fairly arbitrary heuristic, i.e. that only Fortran routines that are recursive are able to benefit from PR #111163. If I understand correctly, PR #111163 will promote references to constants to actual constant arguments, which unlocks optimisations later in the pipeline, in particular IPSCCP. I thought the fundamental reason why we are careful to specialise based on a constant literal is we want to avoid a potential explosion in specialisations, which not only increases compile time but also binary size? This patch could also lead to an explosion in compile times for certain benchmarks if there are lots of different calls to the recursive function where we pass in different literals. It just so happens for bwaves this isn't a problem, if I understand correctly?

So I suppose what this patch implies is that if a function is recursive there will be at least two callers passing in that literal value, i.e. the original call and the recursive call. That makes me wonder if there is a better heuristic we can use that would benefit non-recursive Fortran functions too? For example, what if we decided to specialise functions with literal constants only if we can prove there that it's worth it based on the number or percentage of callers using that same literal? Would such a heuristic also work for bwaves?

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


More information about the llvm-commits mailing list