This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Vectorize inductions that are live after the loop.


Vectorize inductions that are live after the loop.

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 outside the
    loop.
    (process_use): Use of a stmt does not inherit it's live value.
    (vect_mark_stmts_to_be_vectorized): Simplify relevance inheritance.
    (vect_get_vec_def_for_operand): Split body into...
    (vect_get_vec_def_for_operand_internal): ...new function
    (vect_get_vec_def_for_operand_outside): New. Same as above but for
    stmts outside a loop.
    (vect_analyze_stmt): Check for new relevant state.
    *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.


Cheers,
Alan.

Attachment: liveInductions.patch
Description: liveInductions.patch


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]