https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115777
--- Comment #11 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:21edcb95340424efe2e66831f3b32cbab9cc6d31 commit r15-6905-g21edcb95340424efe2e66831f3b32cbab9cc6d31 Author: Richard Biener <rguent...@suse.de> Date: Thu Jan 9 11:51:19 2025 +0100 Fix SLP scalar costing with stmts also used in externals When we have the situation of an external SLP node that is permuted the scalar stmts recorded in the permute node do not mean the scalar computation can be removed. We are removing those stmts from the vectorized_scalar_stmts for this reason but we fail to check this set when we cost scalar stmts. Note vectorized_scalar_stmts isn't a complete set so also pass scalar_stmts_in_externs and check that. The following fixes this. This shows in PR115777 when we avoid vectorizing the load, but on it's own doesn't help the PR yet. PR tree-optimization/115777 * tree-vect-slp.cc (vect_bb_slp_scalar_cost): Do not cost a scalar stmt that needs to be preserved.