https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111137
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-12 branch has been updated by Richard Biener <rgue...@gcc.gnu.org>: https://gcc.gnu.org/g:e35556c61bdeb9f41b4111fffb423a705232ab9c commit r12-10043-ge35556c61bdeb9f41b4111fffb423a705232ab9c Author: Richard Biener <rguent...@suse.de> Date: Fri Aug 25 13:37:30 2023 +0200 tree-optimization/111137 - dependence checking for SLP The following fixes a mistake with SLP dependence checking. When checking whether we can hoist loads to the first load place we special-case stores of the same instance considering them sunk to the last store place. But we fail to consider that stores from other SLP instances are sunk in a similar way. This leads us to miss the dependence between (A) and (B) in b[0][1] = 0; (A) ... _6 = b[_5 /* 0 */][0]; (B') _7 = _6 ^ 1; b[_5 /* 0 */][0] = _7; b[0][2] = 0; (A') _10 = b[_5 /* 0 */][1]; (B) _11 = _10 ^ 1; b[_5 /* 0 */][1] = _11; where the zeroing stores are sunk to (A') and the loads hoisted to (B'). The following fixes this, treating grouped stores from other instances similar to stores from our own instance. The difference is - and this is more conservative than necessary - that we don't know which stores of a group are in which SLP instance (though I believe either all of the grouped stores will be in a single SLP instance or in none at the moment), so we don't know which stores are sunk where. We simply assume they are all sunk to the last store we run into. Likewise we do not take into account that an SLP instance might be cancelled (or a grouped store not actually belong to any instance). PR tree-optimization/111137 * tree-vect-data-refs.cc (vect_slp_analyze_load_dependences): Properly handle grouped stores from other SLP instances. * gcc.dg/torture/pr111137.c: New testcase. (cherry picked from commit 845ee9c7107956845e487cb123fa581d9c70ea1b)