https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121659
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Biener <rgue...@gcc.gnu.org>: https://gcc.gnu.org/g:68e692eed9e8e8c47d83586ee08f40c27fa3a78d commit r16-3389-g68e692eed9e8e8c47d83586ee08f40c27fa3a78d Author: Richard Biener <rguent...@suse.de> Date: Tue Aug 26 10:34:01 2025 +0200 tree-optimization/121659 - bogus swap of reduction operands The following addresses a bogus swapping of SLP operands of a reduction operation which gets STMT_VINFO_REDUC_IDX out of sync with the SLP operand order. In fact the most obvious mistake is that we simply swap operands even on the first stmt even when there's no difference in the comparison operators (for == and != at least). But there are more latent issues that I noticed and fixed up in the process. PR tree-optimization/121659 * tree-vect-slp.cc (vect_build_slp_tree_1): Do not allow matching up comparison operators by swapping if that would disturb STMT_VINFO_REDUC_IDX. Make sure to only actually mark operands for swapping when there was a mismatch and we're not processing the first stmt. * gcc.dg/vect/pr121659.c: New testcase.