https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69708
Bug ID: 69708 Summary: ipa inline not working for function reference in static const struct Product: gcc Version: 5.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: carlosjosepita at gmail dot com Target Milestone: --- Please see full discussion at https://gcc.gnu.org/ml/gcc/2016-02/msg00042.html. Here is a summary of the above: ``` typedef struct F { int (*call)(int); } F; static int g(F f, int x) { x = f.call(x); x = f.call(x); x = f.call(x); x = f.call(x); x = f.call(x); x = f.call(x); x = f.call(x); x = f.call(x); return x; } static int sq(int x) { return x * x; } static const F f = {sq}; void dosomething(int); int h(int x) { dosomething(g(f, x)); dosomething(g((F){sq}, x)); } ``` I've reported this: . Just to summarize: 1) If early inlining is forced then fre replaces the many references to sq and ipa inlining is able to do its job. 2) If early inlining is disabled then ipa inlining only works for the compound literal case. The cp pass (happening immediately before the ipa inline one) results in: ``` h (int x) { ... _4 = g (f, x_2(D)); dosomething (_4); D.1847.call = sq; _8 = g (D.1847, x_2(D)); dosomething (_8); .... } ``` Nevertheless ipa inline seems clever enough to expand the second call to g. 3) The proper solution seems to be that cp were able to propagate sq to both call sites in order to make things easy to ipa inline.