In the absence of PGO data, some compilers nonetheless will speculate the target of a virtual function call and optimize as such.
It could be a link time optimization to check if a single implementation is used and then de-virtualize the calls.
True, I imagine that clang with ThinLTO might do it.
Unfortunately I am too late to edit, but actually I simply misunderstood that the member function pointer would do dynamic dispatch. Somehow after all of these years, I never used that feature. (Although it explains some of the extra bytes needed in a member to function pointer; prior to now I was only aware of the this pointer offset part.)
Re:Compiler Explorer
by brandmeyer on Thursday August 06, 2020 @11:51AM
(#24072072)
I've seen devirtualization happen with link-time optimization as well.
The problem is that most devs don't bother with PGO.