This is the mail archive of the gcc-bugs@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]

[Bug tree-optimization/81136] [8 Regression] ICE: in vect_update_misalignment_for_peel, at tree-vect-data-refs.c:910


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81136

--- Comment #5 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
Author: aldyh
Date: Wed Sep 13 16:28:36 2017
New Revision: 252290

URL: https://gcc.gnu.org/viewcvs?rev=252290&root=gcc&view=rev
Log:
Pool alignment information for common bases

This patch is a follow-on to the fix for PR81136.  The testcase for that
PR shows that we can (correctly) calculate different base alignments
for two data_references but still tell that their misalignments wrt the
vector size are equal.  This is because we calculate the base alignments
for each dr individually, without looking at the other drs, and in
general the alignment we calculate is only guaranteed if the dr's DR_REF
actually occurs.

This is working as designed, but it does expose a missed opportunity.
We know that if a vectorised loop is reached, all statements in that
loop execute at least once, so it should be safe to pool the alignment
information for all the statements we're vectorising.  The only catch is
that DR_REFs for masked loads and stores only occur if the mask value is
nonzero.  For example, in:

    struct s __attribute__((aligned(32))) {
      int misaligner;
      int array[N];
    };

    int *ptr;
    for (int i = 0; i < n; ++i)
      ptr[i] = c[i] ? ((struct s *) (ptr - 1))->array[i] : 0;

we can only guarantee that ptr points to a "struct s" if at least
one c[i] is true.

This patch adds a DR_IS_CONDITIONAL_IN_STMT flag to record whether
the DR_REF is guaranteed to occur every time that the statement
executes to completion.  It then pools the alignment information
for references that aren't conditional in this sense.

2017-08-04  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
        PR tree-optimization/81136
        * tree-vectorizer.h: Include tree-hash-traits.h.
        (vec_base_alignments): New typedef.
        (vec_info): Add a base_alignments field.
        (vect_record_base_alignments): Declare.
        * tree-data-ref.h (data_reference): Add an is_conditional_in_stmt
        field.
        (DR_IS_CONDITIONAL_IN_STMT): New macro.
        (create_data_ref): Add an is_conditional_in_stmt argument.
        * tree-data-ref.c (create_data_ref): Likewise.  Use it to initialize
        the is_conditional_in_stmt field.
        (data_ref_loc): Add an is_conditional_in_stmt field.
        (get_references_in_stmt): Set the is_conditional_in_stmt field.
        (find_data_references_in_stmt): Update call to create_data_ref.
        (graphite_find_data_references_in_stmt): Likewise.
        * tree-ssa-loop-prefetch.c (determine_loop_nest_reuse): Likewise.
        * tree-vect-data-refs.c (vect_analyze_data_refs): Likewise.
        (vect_record_base_alignment): New function.
        (vect_record_base_alignments): Likewise.
        (vect_compute_data_ref_alignment): Adjust base_addr and aligned_to
        for nested statements even if we fail to compute a misalignment.
        Use pooled base alignments for unconditional references.
        (vect_find_same_alignment_drs): Compare base addresses instead
        of base objects.
        (vect_analyze_data_refs_alignment): Call vect_record_base_alignments.
        * tree-vect-slp.c (vect_slp_analyze_bb_1): Likewise.

gcc/testsuite/
        PR tree-optimization/81136
        * gcc.dg/vect/pr81136.c: Add scan test.

Modified:
    branches/range-gen2/gcc/ChangeLog
    branches/range-gen2/gcc/testsuite/ChangeLog
    branches/range-gen2/gcc/testsuite/gcc.dg/vect/pr81136.c
    branches/range-gen2/gcc/tree-data-ref.c
    branches/range-gen2/gcc/tree-data-ref.h
    branches/range-gen2/gcc/tree-ssa-loop-prefetch.c
    branches/range-gen2/gcc/tree-vect-data-refs.c
    branches/range-gen2/gcc/tree-vect-slp.c
    branches/range-gen2/gcc/tree-vectorizer.h

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