https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112464
--- Comment #2 from Robin Dapp <rdapp at gcc dot gnu.org> --- I tested diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index a544bc9b059..257fd40793e 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -7084,7 +7084,7 @@ vectorize_fold_left_reduction (loop_vec_info loop_vinfo, opmask, &vec_opmask); } - gimple *sdef = scalar_dest_def_info->stmt; + gimple *sdef = vect_orig_stmt (scalar_dest_def_info)->stmt; overnight on x86 and aarch64. This seems to help for the reduced testcase. It appears as if we "look through" a statement pattern in vect_finish_replace_stmt but not before when we replace the newly created vector statement's lhs. Then the lhs is the statement pattern's lhs while in vect_finish_replace_stmt we assert that it's from the statement the pattern replaced.