https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83867
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rsandifo at gcc dot gnu.org --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- The issue is that vectorized stmts replacing scalar stmts via vect_finish_replace_stmt leave the scalar stmt def dangling in no BB. Here 9525 /* Handle inner-loop stmts whose DEF is used in the loop-nest that 9526 is being vectorized, but outside the immediately enclosing loop. */ 9527 if (vec_stmt 9528 && STMT_VINFO_LOOP_VINFO (stmt_info) 9529 && nested_in_vect_loop_p (LOOP_VINFO_LOOP ( 9530 STMT_VINFO_LOOP_VINFO (stmt_info)), stmt) passes the dangling 'stmt' to nested_in_vect_loop_p. Replacing the scalar def in this way is somewhat hacky given the caller still has its hand on 'stmt' :/ We could fix this particular fallout but why do we need to re-use the original SSA def? This is from vectorize_fold_left_reduction. Anyway, I see it is convenient but I do expect more fallout from this. Index: gcc/tree-vect-stmts.c =================================================================== --- gcc/tree-vect-stmts.c (revision 256722) +++ gcc/tree-vect-stmts.c (working copy) @@ -9426,6 +9426,11 @@ vect_transform_stmt (gimple *stmt, gimpl gcc_assert (slp_node || !PURE_SLP_STMT (stmt_info)); gimple *old_vec_stmt = STMT_VINFO_VEC_STMT (stmt_info); + bool nested_p = (STMT_VINFO_LOOP_VINFO (stmt_info) + && nested_in_vect_loop_p + (LOOP_VINFO_LOOP (STMT_VINFO_LOOP_VINFO (stmt_info)), + stmt)); + switch (STMT_VINFO_TYPE (stmt_info)) { case type_demotion_vec_info_type: @@ -9525,9 +9530,7 @@ vect_transform_stmt (gimple *stmt, gimpl /* Handle inner-loop stmts whose DEF is used in the loop-nest that is being vectorized, but outside the immediately enclosing loop. */ if (vec_stmt - && STMT_VINFO_LOOP_VINFO (stmt_info) - && nested_in_vect_loop_p (LOOP_VINFO_LOOP ( - STMT_VINFO_LOOP_VINFO (stmt_info)), stmt) + && nested_p && STMT_VINFO_TYPE (stmt_info) != reduc_vec_info_type && (STMT_VINFO_RELEVANT (stmt_info) == vect_used_in_outer || STMT_VINFO_RELEVANT (stmt_info) ==