https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109205
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- So the IR looks like: _4 = MEM[(const struct vector *)v_3(D)].D.25711._M_impl.D.25018._M_finish; _6 = MEM[(const struct vector *)v_3(D)].D.25711._M_impl.D.25018._M_start; _7 = _4 - _6; _8 = (long unsigned int) _7; _1 = _8 + 100; GCC does not know this statement holds true: if (v.end() < v.begin()) __builtin_unreachable(); If you add that, then it will optimize away the comparison.