https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67886
Yuri Gribov <tetra2005 at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |hubicka at gcc dot gnu.org, | |tetra2005 at gmail dot com --- Comment #2 from Yuri Gribov <tetra2005 at gmail dot com> --- There is a more important optimization hiding here. Standard suggests (in 3.8.7, in n3690.pdf) that when the same source variable is used for the instance pointer, it's dynamic type should not change. This allows code like Base *p = new Derived; p->foo(); p->foo(); to be optimized to Derived::foo(p); Derived::foo(p); (which would also allow to optimize Simon's original case). Clang currently performs this sort of optimization (see old discussion in https://groups.google.com/forum/#!topic/llvm-dev/XPxvsEauirM and recent blog post in http://blog.llvm.org/2017/03/devirtualization-in-llvm-and-clang.html). This sort of optimization requires frontend knowledge so probly can't be done solely in GIMPLE? Summon Honza to comment.