arm: Auto-vectorization for MVE: vorr
authorChristophe Lyon <christophe.lyon@linaro.org>
Fri, 13 Nov 2020 12:34:12 +0000 (12:34 +0000)
committerChristophe Lyon <christophe.lyon@linaro.org>
Fri, 11 Dec 2020 16:22:28 +0000 (16:22 +0000)
This patch enables MVE vorrq instructions for auto-vectorization.  MVE
vorrq insns in mve.md are modified to use ior instead of unspec
expression to support ior<mode>3.  The ior<mode>3 expander is added to
vec-common.md

2020-12-03  Christophe Lyon  <christophe.lyon@linaro.org>

gcc/
* config/arm/iterators.md (supf): Remove VORRQ_S and VORRQ_U.
(VORRQ): Remove.
* config/arm/mve.md (mve_vorrq_s<mode>): New entry for vorr
instruction using expression ior.
(mve_vorrq_u<mode>): New expander.
(mve_vorrq_f<mode>): Use ior code instead of unspec.
* config/arm/neon.md (ior<mode>3): Renamed into ior<mode>3_neon.
* config/arm/predicates.md (imm_for_neon_logic_operand): Enable
for MVE.
* config/arm/unspecs.md (VORRQ_S, VORRQ_U, VORRQ_F): Remove.
* config/arm/vec-common.md (ior<mode>3): New expander.

gcc/testsuite/
* gcc.target/arm/simd/mve-vorr.c: Add vorr tests.

gcc/config/arm/iterators.md
gcc/config/arm/mve.md
gcc/config/arm/neon.md
gcc/config/arm/predicates.md
gcc/config/arm/unspecs.md
gcc/config/arm/vec-common.md
gcc/testsuite/gcc.target/arm/simd/mve-vorr.c [new file with mode: 0644]

index badad2bf2936f7fe403f8e9e12d6328fef501392..f0e1d605cd0386c2b1ff81828c7a2f124af4bba2 100644 (file)
                       (VMULLBQ_INT_S "s") (VMULLBQ_INT_U "u") (VQADDQ_S "s")
                       (VMULLTQ_INT_S "s") (VMULLTQ_INT_U "u") (VQADDQ_U "u")
                       (VMULQ_N_S "s") (VMULQ_N_U "u") (VMULQ_S "s")
-                      (VMULQ_U "u") (VORNQ_S "s") (VORNQ_U "u") (VORRQ_S "s")
-                      (VORRQ_U "u") (VQADDQ_N_S "s") (VQADDQ_N_U "u")
+                      (VMULQ_U "u") (VORNQ_S "s") (VORNQ_U "u")
+                      (VQADDQ_N_S "s") (VQADDQ_N_U "u")
                       (VQRSHLQ_N_S "s") (VQRSHLQ_N_U "u") (VQRSHLQ_S "s")
                       (VQRSHLQ_U "u") (VQSHLQ_N_S "s") (VQSHLQ_N_U "u")
                       (VQSHLQ_R_S "s") (VQSHLQ_R_U "u") (VQSHLQ_S "s")
 (define_int_iterator VMULQ [VMULQ_U VMULQ_S])
 (define_int_iterator VMULQ_N [VMULQ_N_U VMULQ_N_S])
 (define_int_iterator VORNQ [VORNQ_U VORNQ_S])
-(define_int_iterator VORRQ [VORRQ_S VORRQ_U])
 (define_int_iterator VQADDQ [VQADDQ_U VQADDQ_S])
 (define_int_iterator VQADDQ_N [VQADDQ_N_S VQADDQ_N_U])
 (define_int_iterator VQRSHLQ [VQRSHLQ_S VQRSHLQ_U])
index 1ec0d1aa323bf8427601bddaadc2d07af9b6cd8f..4b2e46afc196df8133d81198e5e1d57a7a27ccae 100644 (file)
 ;;
 ;; [vorrq_s, vorrq_u])
 ;;
-(define_insn "mve_vorrq_<supf><mode>"
+;; signed and unsigned versions are the same: define the unsigned
+;; insn, and use an expander for the signed one as we still reference
+;; both names from arm_mve.h.
+;; We use the same code as in neon.md (TODO: avoid this duplication).
+(define_insn "mve_vorrq_s<mode>"
   [
-   (set (match_operand:MVE_2 0 "s_register_operand" "=w")
-       (unspec:MVE_2 [(match_operand:MVE_2 1 "s_register_operand" "w")
-                      (match_operand:MVE_2 2 "s_register_operand" "w")]
-        VORRQ))
+   (set (match_operand:MVE_2 0 "s_register_operand" "=w,w")
+       (ior:MVE_2 (match_operand:MVE_2 1 "s_register_operand" "w,0")
+                  (match_operand:MVE_2 2 "neon_logic_op2" "w,Dl")))
   ]
   "TARGET_HAVE_MVE"
-  "vorr %q0, %q1, %q2"
+  "@
+   vorr\t%q0, %q1, %q2
+   * return neon_output_logic_immediate (\"vorr\", &operands[2], <MODE>mode, 0, VALID_NEON_QREG_MODE (<MODE>mode));"
   [(set_attr "type" "mve_move")
 ])
+(define_expand "mve_vorrq_u<mode>"
+  [
+   (set (match_operand:MVE_2 0 "s_register_operand")
+       (ior:MVE_2 (match_operand:MVE_2 1 "s_register_operand")
+                  (match_operand:MVE_2 2 "neon_logic_op2")))
+  ]
+  "TARGET_HAVE_MVE"
+)
 
 ;;
 ;; [vqaddq_n_s, vqaddq_n_u])
 (define_insn "mve_vorrq_f<mode>"
   [
    (set (match_operand:MVE_0 0 "s_register_operand" "=w")
-       (unspec:MVE_0 [(match_operand:MVE_0 1 "s_register_operand" "w")
-                      (match_operand:MVE_0 2 "s_register_operand" "w")]
-        VORRQ_F))
+       (ior:MVE_0 (match_operand:MVE_0 1 "s_register_operand" "w")
+                  (match_operand:MVE_0 2 "s_register_operand" "w")))
   ]
   "TARGET_HAVE_MVE && TARGET_HAVE_MVE_FLOAT"
   "vorr %q0, %q1, %q2"
index dc4707d7447dfd4168d70823307c5c74bed1813f..669c34da4e0c67d714455fbf07832029abc7d19d 100644 (file)
    (set_attr "predicable" "no")]
 )
 
-(define_insn "ior<mode>3"
+(define_insn "ior<mode>3_neon"
   [(set (match_operand:VDQ 0 "s_register_operand" "=w,w")
        (ior:VDQ (match_operand:VDQ 1 "s_register_operand" "w,0")
                 (match_operand:VDQ 2 "neon_logic_op2" "w,Dl")))]
index 5f58f7c837ea75eb5acb8eb5e26bac7f03aa34ae..9f863e1b33e2b7f2b8eaa73d2131c7ce58465d54 100644 (file)
 (define_predicate "imm_for_neon_logic_operand"
   (match_code "const_vector")
 {
-  return (TARGET_NEON
+  return ((TARGET_NEON || TARGET_HAVE_MVE)
           && neon_immediate_valid_for_logic (op, mode, 0, NULL, NULL));
 })
 
index 18b304874359057f2f958c68a1292bc014f7add9..c2076c9ce6fcabdd2bb94d124670c39c18a30495 100644 (file)
   VMULQ_S
   VMULQ_N_S
   VORNQ_S
-  VORRQ_S
   VQADDQ_S
   VQADDQ_N_S
   VQRSHLQ_S
   VMULQ_U
   VMULQ_N_U
   VORNQ_U
-  VORRQ_U
   VQADDQ_U
   VQADDQ_N_U
   VQRSHLQ_U
   VMULQ_F
   VMULQ_N_F
   VORNQ_F
-  VORRQ_F
   VSUBQ_F
   VADDLVAQ_U
   VADDLVAQ_S
index 2117e5be5c26cd8e7425c0b0c60dec90367add99..df0a6cda3d543a17e600fcda517cea24c85e9730 100644 (file)
   "TARGET_NEON
    || TARGET_HAVE_MVE"
 )
+
+(define_expand "ior<mode>3"
+  [(set (match_operand:VDQ 0 "s_register_operand" "")
+       (ior:VDQ (match_operand:VDQ 1 "s_register_operand" "")
+                (match_operand:VDQ 2 "neon_logic_op2" "")))]
+  "TARGET_NEON
+   || TARGET_HAVE_MVE"
+)
diff --git a/gcc/testsuite/gcc.target/arm/simd/mve-vorr.c b/gcc/testsuite/gcc.target/arm/simd/mve-vorr.c
new file mode 100644 (file)
index 0000000..b1190f6
--- /dev/null
@@ -0,0 +1,64 @@
+/* { dg-do assemble } */
+/* { dg-require-effective-target arm_v8_1m_mve_ok } */
+/* { dg-add-options arm_v8_1m_mve } */
+/* { dg-additional-options "-O3" } */
+
+#include <stdint.h>
+
+#define FUNC(SIGN, TYPE, BITS, NB, OP, NAME)                           \
+  void test_ ## NAME ##_ ## SIGN ## BITS ## x ## NB (TYPE##BITS##_t * __restrict__ dest, TYPE##BITS##_t *a, TYPE##BITS##_t *b) { \
+    int i;                                                             \
+    for (i=0; i<NB; i++) {                                             \
+      dest[i] = a[i] OP b[i];                                          \
+    }                                                                  \
+}
+
+#define FUNC_IMM(SIGN, TYPE, BITS, NB, OP, NAME)                               \
+  void test_ ## NAME ##_ ## SIGN ## BITS ## x ## NB (TYPE##BITS##_t * __restrict__ dest, TYPE##BITS##_t *a) { \
+    int i;                                                             \
+    for (i=0; i<NB; i++) {                                             \
+      dest[i] = a[i] OP 1;                                             \
+    }                                                                  \
+}
+
+/* 64-bit vectors.  */
+FUNC(s, int, 32, 2, |, vorr)
+FUNC(u, uint, 32, 2, |, vorr)
+FUNC(s, int, 16, 4, |, vorr)
+FUNC(u, uint, 16, 4, |, vorr)
+FUNC(s, int, 8, 8, |, vorr)
+FUNC(u, uint, 8, 8, |, vorr)
+
+/* 128-bit vectors.  */
+FUNC(s, int, 32, 4, |, vorr)
+FUNC(u, uint, 32, 4, |, vorr)
+FUNC(s, int, 16, 8, |, vorr)
+FUNC(u, uint, 16, 8, |, vorr)
+FUNC(s, int, 8, 16, |, vorr)
+FUNC(u, uint, 8, 16, |, vorr)
+
+/* 64-bit vectors.  */
+FUNC_IMM(s, int, 32, 2, |, vorrimm)
+FUNC_IMM(u, uint, 32, 2, |, vorrimm)
+FUNC_IMM(s, int, 16, 4, |, vorrimm)
+FUNC_IMM(u, uint, 16, 4, |, vorrimm)
+FUNC_IMM(s, int, 8, 8, |, vorrimm)
+FUNC_IMM(u, uint, 8, 8, |, vorrimm)
+
+/* 128-bit vectors.  */
+FUNC_IMM(s, int, 32, 4, |, vorrimm)
+FUNC_IMM(u, uint, 32, 4, |, vorrimm)
+FUNC_IMM(s, int, 16, 8, |, vorrimm)
+FUNC_IMM(u, uint, 16, 8, |, vorrimm)
+FUNC_IMM(s, int, 8, 16, |, vorrimm)
+FUNC_IMM(u, uint, 8, 16, |, vorrimm)
+
+/* MVE has only 128-bit vectors, so we can vectorize only half of the
+   functions above.  */
+/* Although float16 and float32 types are supported at assembly level,
+   we cannot test them with the '|' operator, so we check only the
+   integer variants.  */
+/* We emit vorr.i[16|32] qX, #1 for the first four versions of the
+   128-bit vector vorrimm tests.  */
+/* { dg-final { scan-assembler-times {vorr\tq[0-9]+, q[0-9]+, q[0-9]+} 8 } } */
+/* { dg-final { scan-assembler-times {vorr.i[0-9]+\tq[0-9]+} 4 } } */