This patch is a reworking of the previous vectorize inductions that are live after the loop patch. It now supports SLP and an optimisation has been moved to patch [3/3].
Stmts which are live (ie: defined inside a loop and then used after the loop) are not currently supported by the vectorizer. In many cases vectorization can still occur because the SCEV cprop pass will hoist the definition of the stmt outside of the loop before the vectorizor pass. However, there are various cases SCEV cprop cannot hoist, for example: for (i = 0; i < n; ++i) { ret = x[i]; x[i] = i; } return i; Currently stmts are marked live using a bool, and the relevant state using an enum. Both these states are propagated to the definition of all uses of the stmt. Also, a stmt can be live but not relevant. This patch vectorizes a live stmt definition normally within the loop and then after the loop uses BIT_FIELD_REF to extract the final scalar value from the vector. This patch adds a new relevant state (vect_used_only_live) for when a stmt is used only outside the loop. The relevant state is still propagated to all it's uses, but the live bool is not (this ensures that vectorizable_live_operation is only called with stmts that really are live). Tested on x86 and aarch64. gcc/ * tree-vect-loop.c (vect_analyze_loop_operations): Allow live stmts. (vectorizable_reduction): Check for new relevant state. (vectorizable_live_operation): vectorize live stmts using BIT_FIELD_REF. Remove special case for gimple assigns stmts. * tree-vect-stmts.c (is_simple_and_all_uses_invariant): New function. (vect_stmt_relevant_p): Check for stmts which are only used live. (process_use): Use of a stmt does not inherit it's live value. (vect_mark_stmts_to_be_vectorized): Simplify relevance inheritance. (vect_analyze_stmt): Check for new relevant state. *tree-vect-slp.c (vect_get_slp_vect_defs): Make global *tree-vectorizer.h (vect_relevant): New entry for a stmt which is used outside the loop, but not inside it. testsuite/ * gcc.dg/tree-ssa/pr64183.c: Ensure test does not vectorize. * testsuite/gcc.dg/vect/no-scevccp-vect-iv-2.c: Remove xfail. * gcc.dg/vect/vect-live-1.c: New test. * gcc.dg/vect/vect-live-2.c: New test. * gcc.dg/vect/vect-live-3.c: New test. * gcc.dg/vect/vect-live-4.c: New test. * gcc.dg/vect/vect-live-5.c: New test. * gcc.dg/vect/vect-live-slp-1.c: New test. * gcc.dg/vect/vect-live-slp-2.c: New test. * gcc.dg/vect/vect-live-slp-3.c: New test. * gcc.dg/vect/vect-live-slp-4.c: New test. Alan.
live2.patch
Description: Binary data