diff mbox

[RFC] Target-specific limits on vector alignment

Message ID 4FD5EFC2.5010001@arm.com
State New
Headers show

Commit Message

Richard Earnshaw June 11, 2012, 1:16 p.m. UTC
The ARM ABI states that vectors larger than 64 bits in size still have
64-bit alignment; never-the-less, the HW supports alignment hints of up
to 128-bits in some cases and will trap in a vector has an alignment
that less than the hint.  GCC currently hard-codes larger vectors to be
aligned by the size of the vector, which means that 128-bit vectors are
marked as being 128-bit aligned.

The ARM ABI unfortunately does not support generating such alignment for
parameters passed by value and this can lead to traps at run time.  It
seems that the best way to solve this problem is to allow the back-end
to set an upper limit on the alignment permitted for a vector.

I've implemented this as a separate hook, rather than using the existing
hooks because there's a strong likelihood of breaking some existing ABIs
if I did it another way.

There are a couple of tests that will need some re-working before this
can be committed to deal with the fall-out of making this change; I'll
prepare those changes if this patch is deemed generally acceptable.

R.

	* target.def (TARGET_VECTOR_ALIGNMENT): New hook.
	* doc/tm.texi.in (TARGET_VECTOR_ALIGNMENT): Likewise.
	* doc/tm.texi: Regenerate.
	* targhooks.c (default_vector_alignment): New function.
	* arm.c (arm_vector_alignment): New function.
	(TARGET_VECTOR_ALIGNMENT): Define.

Comments

Richard Biener June 11, 2012, 2:17 p.m. UTC | #1
On Mon, Jun 11, 2012 at 3:16 PM, Richard Earnshaw <rearnsha@arm.com> wrote:
> The ARM ABI states that vectors larger than 64 bits in size still have
> 64-bit alignment; never-the-less, the HW supports alignment hints of up
> to 128-bits in some cases and will trap in a vector has an alignment
> that less than the hint.  GCC currently hard-codes larger vectors to be
> aligned by the size of the vector, which means that 128-bit vectors are
> marked as being 128-bit aligned.
>
> The ARM ABI unfortunately does not support generating such alignment for
> parameters passed by value and this can lead to traps at run time.  It
> seems that the best way to solve this problem is to allow the back-end
> to set an upper limit on the alignment permitted for a vector.
>
> I've implemented this as a separate hook, rather than using the existing
> hooks because there's a strong likelihood of breaking some existing ABIs
> if I did it another way.
>
> There are a couple of tests that will need some re-working before this
> can be committed to deal with the fall-out of making this change; I'll
> prepare those changes if this patch is deemed generally acceptable.

Hm.  Where would you use that target hook?

Richard.

> R.
>
>        * target.def (TARGET_VECTOR_ALIGNMENT): New hook.
>        * doc/tm.texi.in (TARGET_VECTOR_ALIGNMENT): Likewise.
>        * doc/tm.texi: Regenerate.
>        * targhooks.c (default_vector_alignment): New function.
>        * arm.c (arm_vector_alignment): New function.
>        (TARGET_VECTOR_ALIGNMENT): Define.
diff mbox

Patch

--- config/arm/arm.c	(revision 187425)
+++ config/arm/arm.c	(local)
@@ -259,6 +259,8 @@  static bool arm_array_mode_supported_p (
 					unsigned HOST_WIDE_INT);
 static enum machine_mode arm_preferred_simd_mode (enum machine_mode);
 static bool arm_class_likely_spilled_p (reg_class_t);
+static HOST_WIDE_INT arm_vector_alignment (const_tree type,
+					   HOST_WIDE_INT align);
 static bool arm_vector_alignment_reachable (const_tree type, bool is_packed);
 static bool arm_builtin_support_vector_misalignment (enum machine_mode mode,
 						     const_tree type,
@@ -607,6 +609,9 @@  static const struct attribute_spec arm_a
 #undef TARGET_CLASS_LIKELY_SPILLED_P
 #define TARGET_CLASS_LIKELY_SPILLED_P arm_class_likely_spilled_p
 
+#undef TARGET_VECTOR_ALIGNMENT
+#define TARGET_VECTOR_ALIGNMENT arm_vector_alignment
+
 #undef TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE
 #define TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE \
   arm_vector_alignment_reachable
@@ -24850,6 +25292,15 @@  arm_have_conditional_execution (void)
   return !TARGET_THUMB1;
 }
 
+/* The AAPCS sets the maximum alignment of a vector to 64 bits.  */
+static HOST_WIDE_INT
+arm_vector_alignment (const_tree type ATTRIBUTE_UNUSED, HOST_WIDE_INT align)
+{
+  if (TARGET_AAPCS_BASED)
+    return MIN (align, 64);
+  return align;
+}
+
 static unsigned int
 arm_autovectorize_vector_sizes (void)
 {
--- doc/tm.texi	(revision 187425)
+++ doc/tm.texi	(local)
@@ -1099,6 +1099,12 @@  make it all fit in fewer cache lines.
 If the value of this macro has a type, it should be an unsigned type.
 @end defmac
 
+@deftypefn {Target Hook} HOST_WIDE_INT TARGET_VECTOR_ALIGNMENT (const_tree @var{type}, HOST_WIDE_INT @var{align})
+This hook can be used to limit the alignment for a vector of type
+@var{type}, in order to comply with a platform ABI.  The default is to
+return @var{align}.
+@end deftypefn
+
 @defmac STACK_SLOT_ALIGNMENT (@var{type}, @var{mode}, @var{basic-align})
 If defined, a C expression to compute the alignment for stack slot.
 @var{type} is the data type, @var{mode} is the widest mode available,
--- doc/tm.texi.in	(revision 187425)
+++ doc/tm.texi.in	(local)
@@ -1087,6 +1087,8 @@  make it all fit in fewer cache lines.
 If the value of this macro has a type, it should be an unsigned type.
 @end defmac
 
+@hook TARGET_VECTOR_ALIGNMENT
+
 @defmac STACK_SLOT_ALIGNMENT (@var{type}, @var{mode}, @var{basic-align})
 If defined, a C expression to compute the alignment for stack slot.
 @var{type} is the data type, @var{mode} is the widest mode available,
--- target.def	(revision 187425)
+++ target.def	(local)
@@ -1615,6 +1615,14 @@  DEFHOOK
  bool, (enum machine_mode mode),
  hook_bool_mode_false)
 
+DEFHOOK
+(vector_alignment,
+ "This hook can be used to limit the alignment for a vector of type\n\
+@var{type}, in order to comply with a platform ABI.  The default is to\n\
+return @var{align}.",
+ HOST_WIDE_INT, (const_tree type, HOST_WIDE_INT align),
+ default_vector_alignment)
+
 /* True if we should try to use a scalar mode to represent an array,
    overriding the usual MAX_FIXED_MODE limit.  */
 DEFHOOK
--- targhooks.c	(revision 187425)
+++ targhooks.c	(local)
@@ -939,6 +939,13 @@  tree default_mangle_decl_assembler_name 
    return id;
 }
 
+HOST_WIDE_INT
+default_vector_alignment (const_tree type ATTRIBUTE_UNUSED,
+			  HOST_WIDE_INT align)
+{
+  return align;
+}
+
 bool
 default_builtin_vector_alignment_reachable (const_tree type, bool is_packed)
 {