https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112406
--- Comment #22 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Robin Dapp <rd...@gcc.gnu.org>: https://gcc.gnu.org/g:2bbc7f4ef6329df62146fd6d0da5f30750cc72b4 commit r14-5697-g2bbc7f4ef6329df62146fd6d0da5f30750cc72b4 Author: Robin Dapp <rd...@ventanamicro.com> Date: Tue Nov 21 12:51:12 2023 +0100 vect: Allow reduc_index != 1 for COND_OPs. In PR112406 Tamar found another problem with COND_OP reductions. I wrongly assumed that the reduction variable will always remain in operand 1, just as we create the COND_OP in ifcvt. But of course, addition being commutative, we are free to swap operand 1 and 2 and we end up with e.g. _ifc__60 = .COND_ADD (_2, _6, MADPictureC1_lsm.10_25, MADPictureC1_lsm.10_25); which does not pass the asserts I put in place. This patch removes this restriction and allows the reduction index to be 2 as well. gcc/ChangeLog: PR middle-end/112406 * tree-vect-loop.cc (vectorize_fold_left_reduction): Allow reduction index != 1. (vect_transform_reduction): Handle reduction index != 1. gcc/testsuite/ChangeLog: * gcc.target/aarch64/pr112406-2.c: New test.