GCC Bugzilla – Bug 45632
const function pointer propagation issues with inlining
Last modified: 2011-10-21 14:07:53 UTC
The attached test case is testing inlining of const function pointers
in a typical "OO code written in C" situation.
The code shows two optimization problems:
- a_foo is inlined into main, b_foo is not.
The only difference is that new_a() returns a const pointer
and new_b() does not. I would have assumed that gcc detects that the pointer coming out of new_b() is const.
- p->ops->op2 is never inlined, not even for a, even though the compiler
should have enough information to do so (everything that is passed in is
const). I assume this is because cloning does not work through
Created attachment 21763 [details]
testcase, compiled with -O3
Is the second call to func() in main we pass the pointer p again, p2
being basically thrown away, I think that is a mistake because this
way, there isn't actually any call to b_foo in the testcase, just two
calls to a_foo.
BTW, currently (at -O3 and on i686) not even these calls to a_foo is
inlined. Just one of them is direct but the other one is not, presumably
because we don't believe in the constantness of *p over the first call
at this stage. When I change the testcase to pass p2 to the second
invocation of func, neither a_foo nor b_foo are inlined either.
So it seems to me that in order to inline both cases we'd need
aggregate return functions that we would be able to combine with
indirect cgraph edges at inlining time. Tough.