> Missing test cases? Good point. The testcases I have needs rest of the patches from the series to hit the mainline. For now I have added the following to test the basic scenario
* g++.dg/ipa/devirt-15.C: New testcase. Index: g++.dg/ipa/devirt-15.C =================================================================== --- g++.dg/ipa/devirt-15.C (revision 0) +++ g++.dg/ipa/devirt-15.C (working copy) @@ -0,0 +1,40 @@ +/* Check that we speculatively devirutalize call to FOO to A::foo becuase + B is noreturn. */ +/* { dg-do run } */ +/* { dg-options "-O2 -fdump-ipa-devirt" } */ +class A { +public: + virtual int foo(void) + { + throw (1); + return 0; + } +}; + + +class B : public A { +public: + virtual int foo(void); +}; + +int +B::foo(void) +{ + return 1; +} +class A a, *b=&a; +void +m(void) +{ + b->foo(); +} +main() +{ + m(); +} + +/* { dg-final { scan-ipa-dump "Speculatively devirtualizing call" "devirt"} } */ +/* { dg-final { cleanup-ipa-dump "devirt" } } */ +/* Match if (PROF_6 == foo) to verify that the speculation survived. */ +/* { dg-final { scan-tree-dump "== foo" "optimized"} } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ > > Have you tested the optimization with SPEC2k and SPEC06? There are a > couple of benchmarks benefit greatly from devirtualization, such as > eon, povray etc. I believe astar will probably improve with this > optimization at O2 (it has hot virtual functions that are not > overridden at all). For eon, the assumption at O2 for speculative > devirt may not work well. I trusted Martin (Jambor) that only interesting testcase for devirtualization in SPEC in xalancbmk. We will definitely see tomorrow. Concerning eon, I think it includes all the classes for individual objects so it should not get devirtualized the wrong way. I will double check. Wrong guess in general should not be terribly expensive. Many speculative calls are eliminated by inlining and other will just end up with the extra conditinal+jump (to jump). For firefox the code growth for all those 30000 devirtualization is about 1.8%. Here about 70% of them survive till final executable since they use virtual functions for very cheap accessors that gets inlined well. There is an accounting bug in ipa-cp that makes us to mistakely remove references to some virutal functions as dead after devirtualization, so I disabled tracking of described references for virtual calls. Once this is fixed, the code size may get better. Honza