this is called devirtualization and it is a thing.https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html , look for "devirtualize"