The vectorizer relies on the bug that cfgcleaup for no changed bbs from fix_loop_structure rewrites the whole function into loop-closed-SSA again. Loop-closed PHI node creation in vect_create_epilog_for_reduction does not handle outer loop uses of the reduction result properly (those uses are not yet vectorized). For example gcc.dg/pr50133.c.
This blocks fixing of tree-ssa-loop-manip.c:find_uses_to_rename /* ??? If CHANGED_BBS is empty we rewrite the whole function -- why? */ if (changed_bbs && !bitmap_empty_p (changed_bbs)) { EXECUTE_IF_SET_IN_BITMAP (changed_bbs, 0, index, bi) which can be a major resource hog. Also relying on that bug is broken, without checking we can end up generating wrong-code this way. Incremental betterness can be achieved by Index: gcc/tree-vect-stmts.c =================================================================== --- gcc/tree-vect-stmts.c (revision 195938) +++ gcc/tree-vect-stmts.c (working copy) @@ -5834,46 +5834,6 @@ vect_transform_stmt (gimple stmt, gimple } } - /* 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 ... - } - } - } - /* Handle stmts whose DEF is used outside the loop-nest that is being vectorized. */ But still FAIL: gcc.dg/vect/no-scevccp-outer-22.c (internal compiler error) FAIL: gcc.dg/vect/no-scevccp-outer-22.c (test for excess errors) WARNING: gcc.dg/vect/no-scevccp-outer-22.c compilation failed to produce executable FAIL: gcc.dg/vect/no-scevccp-noreassoc-outer-4.c (internal compiler error) FAIL: gcc.dg/vect/no-scevccp-noreassoc-outer-4.c (test for excess errors) WARNING: gcc.dg/vect/no-scevccp-noreassoc-outer-4.c compilation failed to produce executable FAIL: gcc.dg/vect/no-scevccp-noreassoc-outer-4.c scan-tree-dump-times vect "OUTER LOOP VECTORIZED." 1
Note the ??? is now moved to tree-vectorizer.c: if (num_vectorized_loops > 0) { /* If we vectorized any loop only virtual SSA form needs to be updated. ??? Also while we try hard to update loop-closed SSA form we fail to properly do this in some corner-cases (see PR56286). */ rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa_only_virtuals); return TODO_cleanup_cfg;
The fixme is still there: /* If we vectorized any loop only virtual SSA form needs to be updated. ??? Also while we try hard to update loop-closed SSA form we fail to properly do this in some corner-cases (see PR56286). */ rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa_only_virtuals); ret |= TODO_cleanup_cfg;