On 5/23/24 9:51 PM, Hanke Zhang via Gcc wrote:
Hi,
I got a question about optimizing function pointers for direct
function calls in C.
Consider the following scenario: one of the fields of a structure is a
function pointer, and all its assignments come from the same function.
Can all its uses be replaced by direct calls to this function? So the
later passes can do more optimizations.
Certainly. The RTL optimizers have been doing this for ~30 years. If
they can statically determine the target of an indirect call, they will
replace that indirect call with a simple direct call.
You're just extending that capability to apply more often, likely by
doing it at an earlier stage in the pipeline, presumably in one of the
IPA or gimple optimizers?
Note that by doing this transformation before the gimple->rtl conversion
step, you don't have to worry about quirky ABIs where direct and
indirect calls can have different calling conventions.
Jeff