https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107798
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #4) > When the program accesses (*m)[4]. You involved undefined behavior. Anything > can happen after that. Sorry (*m)[3] . So if the compiler thinks it is undefined behavior it can optimize it any way it wants. In this case it removes the i < 9 .