https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102511
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- So the difference between -O2 and -O3 that matters here is -ftree-vectorize but it is not the vectorizer that is making the difference but rather ch_vect. But I can't figure out what is going wrong. Also adding -fwrapv fixes it too.