Pool alignment information for common bases

Programming / Compilers / GCC - rsandifo [138bc75d-0d04-0410-961f-82ee72b054a4] - 4 August 2017 06:42 EDT

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

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.

4f372c2 Pool alignment information for common bases
gcc/ChangeLog | 29 ++++++++++++++
gcc/testsuite/ChangeLog | 5 +++
gcc/testsuite/gcc.dg/vect/pr81136.c | 2 +
gcc/tree-data-ref.c | 33 ++++++++++-----
gcc/tree-data-ref.h | 9 ++++-
gcc/tree-ssa-loop-prefetch.c | 2 +-
gcc/tree-vect-data-refs.c | 80 +++++++++++++++++++++++++++++++++++--
gcc/tree-vect-slp.c | 2 +
gcc/tree-vectorizer.h | 11 +++++
9 files changed, 159 insertions(+), 14 deletions(-)

Upstream: gcc.gnu.org


  • Share