https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
--- Comment #9 from Alexander Monakov <amonakov at gcc dot gnu.org> --- I think this is tree-ldist placing memset(sameZ, 0, zPlaneCount) after the loop, overwriting conditional 'sameZ[i] = true' assignments that happen in the loop. For the smaller testcase from comment #6, -O2 -ftree-loop-distribution is enough, namely: works: gcc-12 -O2 -ftree-loop-distribution -fno-tree-vectorize -fno-tree-loop-distribute-patterns breaks: gcc-12 -O2 -ftree-loop-distribution -fno-tree-vectorize