]> gcc.gnu.org Git - gcc.git/commitdiff
aarch64: Fix target alignment for SVE [PR98119]
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 31 Mar 2021 10:26:06 +0000 (11:26 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Wed, 31 Mar 2021 10:26:06 +0000 (11:26 +0100)
The vectoriser supports peeling for alignment using predication:
we move back to the previous aligned boundary and make the skipped
elements inactive in the first loop iteration.  As it happens,
the costs for existing CPUs give an equal cost to aligned and
unaligned accesses, so this feature is rarely used.

However, the PR shows that when the feature was forced on, we were
still trying to align to a full-vector boundary even when using
partial vectors.

gcc/
PR target/98119
* config/aarch64/aarch64.c
(aarch64_vectorize_preferred_vector_alignment): Query the size
of the provided SVE vector; do not assume that all SVE vectors
have the same size.

gcc/testsuite/
PR target/98119
* gcc.target/aarch64/sve/pr98119.c: New test.

gcc/config/aarch64/aarch64.c
gcc/testsuite/gcc.target/aarch64/sve/pr98119.c [new file with mode: 0644]

index 5eda9e80bd0ed364b8994c4c983f27243ba6ea7e..f878721f13cce42e4b1806279f3da6addf04ba59 100644 (file)
@@ -20275,10 +20275,11 @@ aarch64_vectorize_preferred_vector_alignment (const_tree type)
 {
   if (aarch64_sve_data_mode_p (TYPE_MODE (type)))
     {
-      /* If the length of the vector is fixed, try to align to that length,
-        otherwise don't try to align at all.  */
+      /* If the length of the vector is a fixed power of 2, try to align
+        to that length, otherwise don't try to align at all.  */
       HOST_WIDE_INT result;
-      if (!BITS_PER_SVE_VECTOR.is_constant (&result))
+      if (!GET_MODE_BITSIZE (TYPE_MODE (type)).is_constant (&result)
+         || !pow2p_hwi (result))
        result = TYPE_ALIGN (TREE_TYPE (type));
       return result;
     }
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr98119.c b/gcc/testsuite/gcc.target/aarch64/sve/pr98119.c
new file mode 100644 (file)
index 0000000..da6208c
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-options "-O3 -msve-vector-bits=512 -mtune=thunderx" } */
+
+void
+f (unsigned short *x)
+{
+  for (int i = 0; i < 1000; ++i)
+    x[i] += x[i - 16];
+}
+
+/* { dg-final { scan-assembler-not {\tubfx\t[wx][0-9]+, [wx][0-9]+, #?1, #?5\n} } } */
+/* { dg-final { scan-assembler-not {\tand\tx[0-9]+, x[0-9]+, #?-63\n} } } */
+/* { dg-final { scan-assembler {\tubfx\t[wx][0-9]+, [wx][0-9]+, #?1, #?4\n} } } */
+/* { dg-final { scan-assembler {\tand\tx[0-9]+, x[0-9]+, #?-31\n} } } */
This page took 0.079106 seconds and 5 git commands to generate.