Actually, this optimisation is illegal. I could line up memory such that it is illegal to read past the first location where the array is not sorted. The original code would be fine, the vectorised code would segfault.
Similar annoying problems arise when people try to be clever with C strings, and read past the null. You can write optimisations which work, but they require care.
Similar annoying problems arise when people try to be clever with C strings, and read past the null. You can write optimisations which work, but they require care.