https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Couldn't it be optimized as: short func(short *a, int y) { short ret = 0; unsigned int tmp = 0; int i; for(i = 0; i < y; i++) tmp += (unsigned int)(int)a[i]; return (short)tmp; } Such that the addition happens in unsigned (so there is only wrapping and is well defined) and only one truncatation happens at the end of the loop.