From fdc8037a592901a47fee51484a4830643f25aea7 Mon Sep 17 00:00:00 2001 From: Andrew Stubbs Date: Wed, 24 Sep 2025 11:58:23 +0000 Subject: [PATCH] amdgcn: Remove vector alignment restrictions 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 | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc index df1c1a5b19b..f3b6efc40c9 100644 --- a/gcc/config/gcn/gcn.cc +++ b/gcc/config/gcn/gcn.cc @@ -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. -- 2.47.3