]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
amdgcn: Remove vector alignment restrictions
authorAndrew Stubbs <ams@baylibre.com>
Wed, 24 Sep 2025 11:58:23 +0000 (11:58 +0000)
committerAndrew Stubbs <ams@baylibre.com>
Fri, 26 Sep 2025 11:23:06 +0000 (11:23 +0000)
The supported misalignment logic seems to be a bit arbitrary.  Some of it looks
like it was copied from the Arm implementation, although testing shows that the
packed accesses do not work (weird subregs happen).

AMD GCN does have some alignment restrictions on Buffer instructions, but as we
don't use those that's irrelvant.  The Flat and Global instructions (that we do
use) have no such restrictions.

LDS memory -- which can be accessed via Flat instructions -- does have
alignment restrictions, but the compiler is not using LDS for arbitrary
vectors.  If the user deliberately choses to place unaligned data in
low-latency memory then a runtime exception should occur (no silent bad
behaviour), so there's no reason to pessimise the normal case.

gcc/ChangeLog:

* config/gcn/gcn.cc
(gcn_vectorize_support_vector_misalignment): Allow any alignment, as
long as it's not packed.

gcc/config/gcn/gcn.cc

index df1c1a5b19ba0af07038d760a02d52296c2c84b3..f3b6efc40c9d4d0654550888feedce8cbd140b8a 100644 (file)
@@ -5368,26 +5368,18 @@ gcn_preferred_vector_alignment (const_tree type)
 
 static bool
 gcn_vectorize_support_vector_misalignment (machine_mode ARG_UNUSED (mode),
-                                          const_tree type, int misalignment,
+                                          const_tree ARG_UNUSED (type),
+                                          int ARG_UNUSED (misalignment),
                                           bool is_packed,
-                                          bool is_gather_scatter)
-{
-  if (is_gather_scatter)
-    return true;
-
-  if (is_packed)
-    return false;
-
-  /* If the misalignment is unknown, we should be able to handle the access
-     so long as it is not to a member of a packed data structure.  */
-  if (misalignment == -1)
-    return true;
-
-  /* Return true if the misalignment is a multiple of the natural alignment
-     of the vector's element type.  This is probably always going to be
-     true in practice, since we've already established that this isn't a
-     packed access.  */
-  return misalignment % TYPE_ALIGN_UNIT (type) == 0;
+                                          bool ARG_UNUSED (is_gather_scatter))
+{
+  /* All Flat and Global load instructions support arbitrary alignment, so
+     the types and such are irrelevant (Buffer instructions are not used).  */
+  /* Disallow packed accesses because expand attempts to take scalar subregs of
+     vector registers, which is nonsense.
+     Testcase: gfortran.dg/recursive_alloc_comp_4.f08   */
+  return !is_packed;
 }
 
 /* Implement TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE.