]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Add smov alternative to sign_extend pattern
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Wed, 28 Jul 2021 15:34:03 +0000 (16:34 +0100)
committerKyrylo Tkachov <kyrylo.tkachov@arm.com>
Wed, 28 Jul 2021 15:34:03 +0000 (16:34 +0100)
In the testcase here we were generating a umov + sxth to move
a half-word value from SIMD to GP regs with sign-extension.
We can use a single smov instruction for it instead but the
sign-extend pattern was missing the right alternative.
The *zero_extend<SHORT:mode><GPI:mode>2_aarch64 pattern for
zero-extension already has the right alternative for
the analogous umov instruction, so this mirrors that pattern.

Bootstrapped and tested on aarch64-none-linux-gnu.

The test gcc.target/aarch64/sve/clastb_4.c is adjusted to scan for
the clastb  h0, p0, h0, z0.h form
instead of
the clastb  w0, p0, w0, z0.h form.

This is an improvement as the W forms of the clast instructions are more expensive.

gcc/ChangeLog:

* config/aarch64/aarch64.md (*extend<SHORT:mode><GPI:mode>2_aarch64):
Add "r,w" alternative.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/smov_1.c: New test.
* gcc.target/aarch64/sve/clastb_4.c: Adjust clast scan-assembler.

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

index 8cd259fca9cdfaae71e8b6c2ccea1ba7d128078e..eb8ccd4b97bbd4f0c3ff5791e48cfcfb42ec6c2e 100644 (file)
 )
 
 (define_insn "*extend<SHORT:mode><GPI:mode>2_aarch64"
-  [(set (match_operand:GPI 0 "register_operand" "=r,r")
-        (sign_extend:GPI (match_operand:SHORT 1 "nonimmediate_operand" "r,m")))]
+  [(set (match_operand:GPI 0 "register_operand" "=r,r,r")
+        (sign_extend:GPI (match_operand:SHORT 1 "nonimmediate_operand" "r,m,w")))]
   ""
   "@
    sxt<SHORT:size>\t%<GPI:w>0, %w1
-   ldrs<SHORT:size>\t%<GPI:w>0, %1"
-  [(set_attr "type" "extend,load_4")]
+   ldrs<SHORT:size>\t%<GPI:w>0, %1
+   smov\t%w0, %1.<SHORT:size>[0]"
+  [(set_attr "type" "extend,load_4,neon_to_gp")
+   (set_attr "arch" "*,*,fp")]
 )
 
 (define_insn "*zero_extend<SHORT:mode><GPI:mode>2_aarch64"
diff --git a/gcc/testsuite/gcc.target/aarch64/smov_1.c b/gcc/testsuite/gcc.target/aarch64/smov_1.c
new file mode 100644 (file)
index 0000000..53280ea
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=armv8.2-a+sve" } */
+
+/* Check that we avoid an explicit sxth in favour of smov.  */
+
+#include <arm_sve.h>
+
+int foo(svint16_t a) {
+  return svminv_s16(svptrue_b16(), a);
+}
+
+/* { dg-final { scan-assembler-not "sxth" } } */
index 788e29fe982f736f65d7c93c76fce52a21727448..7603d475a818a83388897089fa311bb98e7302d2 100644 (file)
@@ -6,4 +6,4 @@
 #include "clastb_2.c"
 
 /* { dg-final { scan-tree-dump "operating on partial vectors." "vect" } } */
-/* { dg-final { scan-assembler {\tclastb\tw[0-9]+, p[0-7], w[0-9]+, z[0-9]+\.h} } } */
+/* { dg-final { scan-assembler {\tclastb\th[0-9]+, p[0-7], h[0-9]+, z[0-9]+\.h} } } */