https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67886
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Note in this example the reason why GCC able to optimize this way (even without something like -fstrict-vtable-pointers) is because GCC is able to speculatively devirtualize the inner function call (that means adding an if statement) and inline that. And then FRE can come along and optimize it all the way away as GCC knows that branch will not touch memory and the value does not change otherwise through the loop.