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]

[RFC] PR27770 (alignment with -fsection-anchors and vectorization) fix


Here's an attempt to address PR27770. In the testcase, when using
-fsection-anchors, we compile the function 'bar' assuming natural alignment
for global array 'f', and later, when compiling the function foo, the
vectorizer increases the alignmnet of array 'f', which makes the code we
generated for fucntion bar incorrect.

To fix this we:

1. Don't let the vectorizer increase the alignment of global variables when
section-anchors is enabled.

2. The above might impede vectorization in many cases. To avoid that, we
add a pre-pass that increases the alignmnet of potentially vectorizable
arrays in advance. We do this only if vectorization and section-anchors are
enabled, and only to global arrays whose type is vectorizable (we can
obtain a vector type for it).

Questions/comments:

- Should we invoke this optimization at a different place?

- This optimization would end up increasing the alignment of many arrays
that would not end up being vectorized (used in a vectorized loop). In the
future we may want to do some more aggressive pruning (check if an array is
accessed in a loop? in a likely vectorizable loop?). In the future we'd
also want this optimization as part of an  inter-procedural alignment
analysis, that would probably also apply array padding.

- Given the above, are we happy with the conditions that control the
invocation of this optimization? do we want to introduce a new flag?

- The patch increases the alignment of (global) arrays only. We have a few
testcases though (e.g. vect-69.c) that have global structs that contain
fields that are arrays. Aligning the beginning of these structs can
sometime align one/some of their array fields. Since this patch does not
attempt to do that, we have some tests that will now fail (or fail on
targets that don't support unaligned accesses). As a first step we can
avoid the failures by changing the tests to work with local structs instead
of global structs where possible, and later consider extending the
optimization to align global structs that have array fields that could
become aligned as a result.

Bootstrapped on powerpc-linux, and tested on the vectorizer testcases.

Thanks to Richard Sandiford for analyzing this PR.

dorit

:ADDPATCH vectorizer:

        PR tree-optimization/27770
        * tree-vectorizer.h (get_vectype_for_scalar_type): Function
        declaration removed (moved to tree-flow.h).
        (vect_can_force_dr_alignment_p): Likewise.
        * tree-flow.h (get_vectype_for_scalar_type): New function
declaration
        (moved from tree-vectorizer.h).
        (vect_can_force_dr_alignment_p): Likewise.
        * tree-vectorizer.c (vect_print_dump_info): Allow calling this
function
        from outside the vectorizer - in particular from cgraph stage.
        * tree-vect-analyze.c (vect_compute_data_ref_alignment): Don't
increase
        the alignment of global arrays when -fsection-anchors is enabled.
        * cgraphunit.c (cgraph_increase_alignment): New function.
        (cgraph_optimize): Call cgraph_increase_alignment.

(See attached file: pr27770.patch)(See attached file:
section-anchors-pr27770.c)

Attachment: pr27770.patch
Description: Binary data

Attachment: section-anchors-pr27770.c
Description: Binary data


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