https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110381
--- Comment #22 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:8f6d889a8e609710ecfd555778fbff602b2c7d74 commit r12-10491-g8f6d889a8e609710ecfd555778fbff602b2c7d74 Author: Richard Biener <rguent...@suse.de> Date: Mon Jun 26 12:51:37 2023 +0200 tree-optimization/110381 - preserve SLP permutation with in-order reductions The following fixes a bug that manifests itself during fold-left reduction transform in picking not the last scalar def to replace and thus double-counting some elements. But the underlying issue is that we merge a load permutation into the in-order reduction which is of course wrong. Now, reduction analysis has not yet been performend when optimizing permutations so we have to resort to check that ourselves. PR tree-optimization/110381 * tree-vect-slp.cc (vect_optimize_slp_pass::start_choosing_layouts): Materialize permutes before fold-left reductions. * gcc.dg/vect/pr110381.c: New testcase. (cherry picked from commit 53d6f57c1b20c6da52aefce737fb7d5263686ba3)