Bug 45632 - const function pointer propagation issues with inlining
const function pointer propagation issues with inlining
Status: UNCONFIRMED
Product: gcc
Classification: Unclassified
Component: middle-end
4.6.0
: P3 enhancement
: ---
Assigned To: Not yet assigned to anyone
: missed-optimization
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-09-10 08:50 UTC by Andi Kleen
Modified: 2011-10-21 14:07 UTC (History)
4 users (show)

See Also:
Host: x86_64-linux
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
testcase, compiled with -O3 (1.04 KB, text/plain)
2010-09-10 08:50 UTC, Andi Kleen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andi Kleen 2010-09-10 08:50:09 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
function pointers?
Comment 1 Andi Kleen 2010-09-10 08:50:49 UTC
Created attachment 21763 [details]
testcase, compiled with -O3
Comment 2 Martin Jambor 2011-10-21 14:07:53 UTC
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.