[PATCH, ARM] Misaligned access support for ARM Neon

Julian Brown julian@codesourcery.com
Tue Nov 17 17:21:00 GMT 2009


This patch provides support for misaligned accesses (for the
vectorizer) for ARM Neon in little-endian mode, and some of the
infrastructure for support in big-endian mode also (though big-endian
support doesn't actually work yet). (Most of the tricky bits in here are
by Paul Brook, so apologies if I've messed up the explanations!)

Supporting big-endian mode for vectorization is tricky for Neon, because
no distinction is made in the vectorizer at present between whole-vector
memory accesses and accesses of arrays of elements. For Neon, these are
supported by distinct operations, which (in big-endian mode at least)
access elements in different orders (namely, vldr/vstr/vstm/vldm for
whole vectors, vld1/vst1 for elements).

The right way to order vectors is (i.e. has been decided to be, AIUI) as
if one had a union, e.g.:

union {
  v4si vector;
  int elements[4];
};

then the numbering of the vector's elements is the same as accessing
the elements through the array. This is the ordering provided by the
vld1/vst1 instructions in both big- and little-endian mode.

However, the vectorizer will (at present) create regular vector
loads/stores (i.e. the ones using vldr/vstr/vldm/vstm) for aligned
accesses. This patch introduces a target hook (vector_always_misalign)
which forces it to always use the misaligned variant (which DTRT in
big-endian mode), even for aligned accesses.

Neon vld1/vst1 can't be used for *arbitrary* alignments: the
minimum alignment is the element size for the access in question.
Another target hook (vector_min_alignment) is defined to teach the
vectorizer this. Correspondingly for the testsuite,
check_effective_target_vect_element_align has been added to
target-supports.exp.

The latter unfortunately is fairly redundant with
check_effective_target_vect_hw_misalign, which has been introduced
since this patch was written. *_vect_element_align provides a weaker
promise (i.e. element alignment vs. arbitrary alignment), though one
which is probably sufficient in most cases. I'm not sure if it makes
sense to keep both predicates: at present, I've updated quite a few
tests which previously used *_vect_hw_misalign to use
*_vect_element_align instead when it improves test results for ARM, but
not exhaustively.

Test results (cross to ARM Linux) show some additional failures. I
think these are just showing up missing features elsewhere in the Neon
support appearing now because of the dejagnu tweaks, rather than
problems with this patch as such.

OK to apply?

Julian

ChangeLog

    Julian Brown  <julian@codesourcery.com>
    Paul Brook  <paul@codesourcery.com>
    Daniel Jacobowitz  <dan@codesourcery.com>
    Joseph Myers  <joseph@codesourcery.com>

    gcc/
    * expr.c (expand_assignment): Handle MISALIGNED_INDIRECT_REF as a
    destination.
    (expand_expr_real_1): Handle writes to MISALIGNED_INDIRECT_REF.
    * target-def.h (TARGET_VECTOR_MIN_ALIGNMENT)
    (TARGET_VECTOR_ALWAYS_MISALIGN): Define.
    (TARGET_VECTORIZE): Use them.
    * target.h (gcc_target): Add vectorize.vector_min_alignment and
    vectorize.always_misalign.
    * targhooks.c (default_vector_min_alignment): New function.
    * targhooks.h (default_vector_min_alignment): Add prototype.
    * tree-vect-data-refs.c (vect_compute_data_ref_alignment): Use
    targetm.vectorize.vector_min_alignment.
    * tree-vect-loop-manip.c (target.h): Include.
    (vect_gen_niters_for_prolog_loop): Use
    targetm.vectorize.vector_min_alignment.
    * tree-vect-stmts.c (vectorizable_store): Honour
    targetm.vectorize.always_misalign.
    (vectorizable_load): Ditto.
    * config/arm/arm.c (arm_vector_min_alignment)
    (arm_vector_always_misalign): New functions.
    (TARGET_VECTOR_MIN_ALIGNMENT, TARGET_VECTOR_ALWAYS_MISALIGN):
    Define macros, using above.
    (neon_vector_mem_operand): Disallow PRE_DEC for array loads.
    (arm_print_operand): Include alignment qualifier in %A.
    * config/arm/neon.md (UNSPEC_MISALIGNED_ACCESS): New constant.
    (movmisalign<mode>): New expander.
    (movmisalign<mode>_neon_store, movmisalign<mode>_neon_load): New
    insn patterns.

    gcc/testsuite/
    * lib/target-supports.exp
    (check_effective_target_arm_vect_no_misalign): New function.
    (check_effective_target_vect_no_align): Use above.
    (check_effective_target_vect_element_align): New function.
    * gcc.dg/vect/no-section-anchors-vect-31.c: Use vect_element_align (instead of
    vect_hw_misalign where appropriate).
    * gcc.dg/vect/no-section-anchors-vect-64.c: Ditto.
    * gcc.dg/vect/no-section-anchors-vect-66.c: Ditto.
    * gcc.dg/vect/no-section-anchors-vect-68.c: Ditto.
    * gcc.dg/vect/no-section-anchors-vect-69.c: Ditto.
    * gcc.dg/vect/section-anchors-vect-69.c: Ditto.
    * gcc.dg/vect/slp-25.c: Ditto.
    * gcc.dg/vect/vect-109.c: Ditto.
    * gcc.dg/vect/vect-26.c: Ditto.
    * gcc.dg/vect/vect-27.c: Ditto.
    * gcc.dg/vect/vect-28.c: Ditto.
    * gcc.dg/vect/vect-29.c: Ditto.
    * gcc.dg/vect/vect-33.c: Ditto.
    * gcc.dg/vect/vect-42.c: Ditto.
    * gcc.dg/vect/vect-44.c: Ditto.
    * gcc.dg/vect/vect-48.c: Ditto.
    * gcc.dg/vect/vect-50.c: Ditto.
    * gcc.dg/vect/vect-52.c: Ditto.
    * gcc.dg/vect/vect-54.c: Ditto.
    * gcc.dg/vect/vect-56.c: Ditto.
    * gcc.dg/vect/vect-58.c: Ditto.
    * gcc.dg/vect/vect-60.c: Ditto.
    * gcc.dg/vect/vect-70.c: Ditto.
    * gcc.dg/vect/vect-72.c: Ditto.
    * gcc.dg/vect/vect-75.c: Ditto.
    * gcc.dg/vect/vect-87.c: Ditto.
    * gcc.dg/vect/vect-88.c: Ditto.
    * gcc.dg/vect/vect-89.c: Ditto.
    * gcc.dg/vect/vect-91.c: Ditto.
    * gcc.dg/vect/vect-92.c: Ditto.
    * gcc.dg/vect/vect-93.c: Ditto.
    * gcc.dg/vect/vect-95.c: Ditto.
    * gcc.dg/vect/vect-96.c: Ditto.
    * gcc.dg/vect/vect-align-1.c: Ditto.
    * gcc.dg/vect/vect-align-2.c: Ditto.
    * gcc.dg/vect/vect-multitypes-1.c: Ditto.
    * gcc.dg/vect/vect-multitypes-3.c: Ditto.
    * gcc.dg/vect/vect-multitypes-4.c: Ditto.
    * gcc.dg/vect/vect-multitypes-6.c: Ditto.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: misaligned-neon-fsf-4.diff
Type: text/x-patch
Size: 53518 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20091117/6d2a26a3/attachment.bin>


More information about the Gcc-patches mailing list