public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC] Target-specific limits on vector alignment
@ 2012-06-11 13:39 Richard Earnshaw
  2012-06-11 14:19 ` Richard Guenther
  2012-06-11 23:05 ` [RFC] " Hans-Peter Nilsson
  0 siblings, 2 replies; 24+ messages in thread
From: Richard Earnshaw @ 2012-06-11 13:39 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1356 bytes --]

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.

[-- Attachment #2: vecalign.patch --]
[-- Type: text/plain, Size: 3548 bytes --]

--- 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)
 {

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2012-08-10 16:28 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-11 13:39 [RFC] Target-specific limits on vector alignment Richard Earnshaw
2012-06-11 14:19 ` Richard Guenther
2012-06-11 14:46   ` Richard Earnshaw
2012-06-11 14:53     ` Richard Guenther
2012-06-11 15:38       ` Richard Earnshaw
2012-06-11 18:37         ` Richard Guenther
2012-07-27 15:36           ` [PATCH v2] " Ulrich Weigand
2012-07-30  3:15             ` Hans-Peter Nilsson
2012-07-30 11:12             ` Richard Guenther
2012-07-30 14:44               ` Ulrich Weigand
2012-08-07 14:57               ` [RFA 4.7/4.6] " Ulrich Weigand
2012-08-07 15:04                 ` Richard Guenther
2012-08-07 15:09                   ` Richard Earnshaw
2012-08-07 15:15                   ` Ramana Radhakrishnan
2012-08-10 13:44                     ` [RFA wwwdocs] " Ulrich Weigand
2012-08-10 14:57                       ` Richard Earnshaw
2012-08-10 15:18                         ` Ulrich Weigand
2012-08-10 16:07                           ` Richard Earnshaw
2012-08-10 16:28                             ` Ulrich Weigand
2012-08-10 13:30                   ` [commit 4.7] " Ulrich Weigand
2012-08-10 13:31                   ` [commit 4.6] " Ulrich Weigand
2012-06-11 23:05 ` [RFC] " Hans-Peter Nilsson
2012-07-24 17:39   ` Ulrich Weigand
2012-07-26  0:10     ` Hans-Peter Nilsson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).