From 84da9bca72558119974db307208eb2fa2b8ad5dd Mon Sep 17 00:00:00 2001 From: Andrew Stubbs Date: Wed, 14 Feb 2024 15:12:43 +0000 Subject: amdgcn: Disallow unsupported permute on RDNA devices The RDNA architecture has limited support for permute operations. This should allow use of the permutations that do work, and fall back to linear code for other cases. gcc/ChangeLog: * config/gcn/gcn-valu.md (vec_extract): Add conditions for RDNA. * config/gcn/gcn.cc (gcn_vectorize_vec_perm_const): Check permutation details are supported on RDNA devices. --- gcc/config/gcn/gcn-valu.md | 3 ++- gcc/config/gcn/gcn.cc | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'gcc') diff --git a/gcc/config/gcn/gcn-valu.md b/gcc/config/gcn/gcn-valu.md index 23b441f..59e27d0 100644 --- a/gcc/config/gcn/gcn-valu.md +++ b/gcc/config/gcn/gcn-valu.md @@ -982,7 +982,8 @@ (match_operand:V_MOV 1 "register_operand") (match_operand 2 "immediate_operand")] "MODE_VF (mode) < MODE_VF (mode) - && mode == mode" + && mode == mode + && (!TARGET_RDNA2_PLUS || MODE_VF (mode) <= 32)" { int numlanes = GET_MODE_NUNITS (mode); int firstlane = INTVAL (operands[2]) * numlanes; diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc index 20be455..4559d69 100644 --- a/gcc/config/gcn/gcn.cc +++ b/gcc/config/gcn/gcn.cc @@ -5110,19 +5110,24 @@ gcn_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode, gcc_assert (nelt <= 64); gcc_assert (sel.length () == nelt); - if (!dst) - { - /* All vector permutations are possible on this architecture, - with varying degrees of efficiency depending on the permutation. */ - return true; - } - unsigned int perm[64]; for (unsigned int i = 0; i < nelt; ++i) perm[i] = sel[i] & (2 * nelt - 1); for (unsigned int i = nelt; i < 64; ++i) perm[i] = 0; + /* RDNA devices can only do permutations within each group of 32-lanes. + Reject permutations that cross the boundary. */ + if (TARGET_RDNA2_PLUS) + for (unsigned int i = 0; i < nelt; i++) + if (i < 31 ? perm[i] > 31 : perm[i] < 32) + return false; + + /* All vector permutations are possible on other architectures, + with varying degrees of efficiency depending on the permutation. */ + if (!dst) + return true; + src0 = force_reg (vmode, src0); src1 = force_reg (vmode, src1); -- cgit v1.1