From: Dhruv Chawla <[email protected]>

Port the following intrinsics to the pragma-based framework:
* vmull
* vmlal
* vmlsl

Folding is left until the function is in SSA form. Before that a constant
operand is still an unresolved declaration which is indistinguishable from a
variable, and folding one would widen it to the result type where no
widening instruction matches it any more.

The fold handles the following forms that the widening intrinsics need:
 - both multiplicands are the upper halves of 128-bit vectors: redirect to
   the high form.
 - one multiplicand is a constant: redirect to the high form when that saves
   extracting a half, otherwise decline.
 - exactly one multiplicand is an upper half: decline, so that expand sees the
   extraction rather than an SXTL2 and a plain multiply.

Some notes:
 - The accumulation for vmlal and vmlsl is done in the unsigned type so that
   signed overflow wraps as the ACLE requires.
 - The 32-bit forms cannot be folded. AArch64 has no vector multiply for
   64-bit elements, eg. `(int64x2_t) a * (int64x2_t) b` would only be
   scalarised again so those rely on expand instead.

vmull_p8, vmull_p64 and their _high forms map to PMULL rather than a
widening multiply, and are left in arm_neon.h.

Bootstrapped and regtested on aarch64-linux-gnu.

Signed-off-by: Dhruv Chawla <[email protected]>

gcc/ChangeLog:

        * config/aarch64/aarch64-builtin-pairs.def (BINOP_LONG_LH_PAIRS,
        TERNOP_LONG_LH_PAIRS): Drop the pairs for the ported intrinsics.
        * config/aarch64/aarch64-builtins.cc (aarch64_v128_highpart_src_reg):
        New function.
        (aarch64_fold_lo_call_to_hi): Use it.
        (aarch64_build_vector_cst): Make non-static.
        * config/aarch64/aarch64-builtins.h (aarch64_v128_highpart_src_reg,
        aarch64_build_vector_cst): Declare.
        * config/aarch64/aarch64-neon-builtins-base.cc: Include
        aarch64-builtins.h and aarch64-neon-builtins-shapes.h.
        (build_vec_extract_half): New function.
        (gimple_get_half::fold): Use it.
        (gimple_widen_mult): New class.
        (vmull, vmull_high, vmlal, vmlal_high, vmlsl, vmlsl_high): New
        function bases.
        * config/aarch64/aarch64-neon-builtins-base.def (vmull, vmull_high,
        vmlal, vmlal_high, vmlsl, vmlsl_high): New function groups.
        * config/aarch64/aarch64-simd-builtins.def (smlal, umlal, smlsl,
        umlsl, intrinsic_vec_smult_lo_, intrinsic_vec_umult_lo_): Delete,
        now that nothing expands to them.
        * config/aarch64/aarch64-simd.md
        (aarch64_intrinsic_vec_<su>mult_lo_<mode>): Rename to ...
        (@aarch64_intrinsic_vec_<su>mult_lo_<mode>): ... this, so that it
        can be selected by mode.
        (aarch64_<su>mlal<mode>): Rename to ...
        (@aarch64_<su>mlal<mode>): ... this.
        (aarch64_<su>mlsl<mode>): Rename to ...
        (@aarch64_<su>mlsl<mode>): ... this.
        (aarch64_<su>mlal_hi<mode>): Rename to ...
        (@aarch64_<su>mlal_hi<mode>): ... this.
        (aarch64_<su>mlsl_hi<mode>): Rename to ...
        (@aarch64_<su>mlsl_hi<mode>): ... this.
        * config/aarch64/arm_neon.h (vmlal_high_s8, vmlal_high_s16,
        vmlal_high_s32, vmlal_high_u8, vmlal_high_u16, vmlal_high_u32,
        vmlal_s8, vmlal_s16, vmlal_s32, vmlal_u8, vmlal_u16, vmlal_u32,
        vmlsl_high_s8, vmlsl_high_s16, vmlsl_high_s32, vmlsl_high_u8,
        vmlsl_high_u16, vmlsl_high_u32, vmlsl_s8, vmlsl_s16, vmlsl_s32,
        vmlsl_u8, vmlsl_u16, vmlsl_u32, vmull_high_s8, vmull_high_s16,
        vmull_high_s32, vmull_high_u8, vmull_high_u16, vmull_high_u32,
        vmull_s8, vmull_s16, vmull_s32, vmull_u8, vmull_u16, vmull_u32):
        Delete functions.

gcc/testsuite/ChangeLog:

        * gcc.target/aarch64/neon/discarded_result.c (test_vmull_s8,
        test_vmull_high_s16, test_vmull_s32, test_vmlal_u8,
        test_vmlsl_high_s16, test_vmull_high_redirect,
        test_vmull_splat_redirect): New functions.
        * gcc.target/aarch64/neon/vmlal.c: New test.
        * gcc.target/aarch64/neon/vmlsl.c: Likewise.
        * gcc.target/aarch64/neon/vmull.c: Likewise.
        * gcc.target/aarch64/simd/fold_to_highpart_1.c: Allow either operand
        order for vmlsl, which GIMPLE is free to commute.
---
 gcc/config/aarch64/aarch64-builtin-pairs.def  |   4 -
 gcc/config/aarch64/aarch64-builtins.cc        |  14 +-
 gcc/config/aarch64/aarch64-builtins.h         |   5 +
 .../aarch64/aarch64-neon-builtins-base.cc     | 240 ++++++++++++++++-
 .../aarch64/aarch64-neon-builtins-base.def    |  10 +
 gcc/config/aarch64/aarch64-simd-builtins.def  |  11 -
 gcc/config/aarch64/aarch64-simd.md            |  10 +-
 gcc/config/aarch64/arm_neon.h                 | 252 ------------------
 .../aarch64/neon/discarded_result.c           |  63 +++++
 gcc/testsuite/gcc.target/aarch64/neon/vmlal.c | 102 +++++++
 gcc/testsuite/gcc.target/aarch64/neon/vmlsl.c |  88 ++++++
 gcc/testsuite/gcc.target/aarch64/neon/vmull.c | 131 +++++++++
 .../aarch64/simd/fold_to_highpart_1.c         |   8 +-
 13 files changed, 656 insertions(+), 282 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/neon/vmlal.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/neon/vmlsl.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/neon/vmull.c

diff --git a/gcc/config/aarch64/aarch64-builtin-pairs.def 
b/gcc/config/aarch64/aarch64-builtin-pairs.def
index 77d61cdd55c..f86b2a9acb0 100644
--- a/gcc/config/aarch64/aarch64-builtin-pairs.def
+++ b/gcc/config/aarch64/aarch64-builtin-pairs.def
@@ -47,8 +47,6 @@
   LO_HI_PAIR_V_US_WI (BINOP,  addl, addl2) \
   LO_HI_PAIR_V_US_WI (BINOP,  subl, subl2) \
   LO_HI_PAIR_V_US_WI (BINOP,  abdl, abdl2) \
-  LO_HI_PAIR_V_WI (BINOP,  intrinsic_vec_smult_lo_, vec_widen_smult_hi_) \
-  LO_HI_PAIR_V_WI (BINOPU, intrinsic_vec_umult_lo_, vec_widen_umult_hi_) \
   LO_HI_PAIR_V_HSI (BINOP,  sqdmull, sqdmull2) \
   LO_HI_PAIR (BINOPP_pmullv8qi, BINOPP_pmull_hiv16qi)
 
@@ -61,8 +59,6 @@
   LO_HI_PAIR_V_US_WI (BINOP,  addw, addw2)
 
 #define TERNOP_LONG_LH_PAIRS \
-  LO_HI_PAIR_V_US_WI (TERNOP,  mlal, mlal_hi) \
-  LO_HI_PAIR_V_US_WI (TERNOP,  mlsl, mlsl_hi) \
   LO_HI_PAIR_V_US_WI (TERNOP,  abal, abal2) \
   LO_HI_PAIR_V_HSI (TERNOP, sqdmlal, sqdmlal2) \
   LO_HI_PAIR_V_HSI (TERNOP, sqdmlsl, sqdmlsl2)
diff --git a/gcc/config/aarch64/aarch64-builtins.cc 
b/gcc/config/aarch64/aarch64-builtins.cc
index 743e85a2136..39de137ffc7 100644
--- a/gcc/config/aarch64/aarch64-builtins.cc
+++ b/gcc/config/aarch64/aarch64-builtins.cc
@@ -4439,9 +4439,18 @@ aarch64_v128_highpart_ref (const_tree ref)
   return NULL_TREE;
 }
 
+/* Like aarch64_v128_highpart_ref, but only return the vector when it is a
+   register.  */
+tree
+aarch64_v128_highpart_src_reg (const_tree ref)
+{
+  tree obj = aarch64_v128_highpart_ref (ref);
+  return obj && is_gimple_reg (obj) ? obj : NULL_TREE;
+}
+
 /* Build and return a new VECTOR_CST of type OUT_TY, using repeated
    copies of the elements of VEC_IN.  */
-static tree
+tree
 aarch64_build_vector_cst (const_tree vec_in, tree out_ty)
 {
   gcc_assert (TREE_CODE (vec_in) == VECTOR_CST
@@ -4508,8 +4517,7 @@ aarch64_fold_lo_call_to_hi (unsigned int fcode, gcall 
*stmt,
          gcc_assert (wi::to_widest (TYPE_SIZE (type_lo)) == 64
                      && wi::to_widest (TYPE_SIZE (type_hi)) == 128);
 
-         tree vq = aarch64_v128_highpart_ref (arg);
-         if (vq && is_gimple_reg (vq))
+         if (auto vq = aarch64_v128_highpart_src_reg (arg))
            {
              vec_highparts.safe_push (argno);
              arg = vq;
diff --git a/gcc/config/aarch64/aarch64-builtins.h 
b/gcc/config/aarch64/aarch64-builtins.h
index ff5c1495fb0..a75653a411b 100644
--- a/gcc/config/aarch64/aarch64-builtins.h
+++ b/gcc/config/aarch64/aarch64-builtins.h
@@ -108,4 +108,9 @@ extern const aarch64_simd_type_info aarch64_simd_types[];
 extern aarch64_simd_type_info_trees aarch64_simd_types_trees[];
 extern tree aarch64_simd_tuple_types[ARM_NEON_H_TYPES_LAST][3];
 
+/* Shared with the pragma-based builtin folders, which do the same
+   lo-to-high-form rewriting for the families they have taken over.  */
+extern tree aarch64_v128_highpart_src_reg (const_tree);
+extern tree aarch64_build_vector_cst (const_tree, tree);
+
 #endif
diff --git a/gcc/config/aarch64/aarch64-neon-builtins-base.cc 
b/gcc/config/aarch64/aarch64-neon-builtins-base.cc
index 2e576eac66a..547d4ce626d 100644
--- a/gcc/config/aarch64/aarch64-neon-builtins-base.cc
+++ b/gcc/config/aarch64/aarch64-neon-builtins-base.cc
@@ -39,9 +39,11 @@
 #include "tree-vector-builder.h"
 #include "rtx-vector-builder.h"
 #include "vec-perm-indices.h"
+#include "aarch64-builtins.h"
 #include "aarch64-acle-builtins.h"
 #include "aarch64-neon-builtins-base.h"
 #include "aarch64-neon-builtins-functions.h"
+#include "aarch64-neon-builtins-shapes.h"
 #include "gimple-fold.h"
 #include "ssa.h"
 #include "emit-rtl.h"
@@ -116,6 +118,16 @@ build_lane_set (tree vec, tree index, tree elem)
   return fold_build3 (BIT_INSERT_EXPR, vec_type, vec, elem, offset);
 }
 
+/* Build an extract of type TYPE (which must be a 64-bit vector type) for half
+   of the 128-bit vector VEC.  HIGH_P selects the upper half.  */
+tree
+build_vec_extract_half (tree type, tree vec, bool high_p)
+{
+  gcc_assert (known_eq (GET_MODE_BITSIZE (TYPE_MODE (type)), 64));
+  return fold_build3 (BIT_FIELD_REF, type, vec, bitsize_int (64),
+                     bitsize_int (high_p ^ BYTES_BIG_ENDIAN ? 64 : 0));
+}
+
 /* Build an expression for a vector with all lanes set to `ELEM`.  */
 tree
 build_vec_dup (tree type, tree elem)
@@ -607,9 +619,7 @@ struct gimple_get_half : public gimple_function_base
   gimple *fold (gimple_folder &f) const override
   {
     auto src = gimple_call_arg (f.call, 0);
-    auto half
-      = fold_build3 (BIT_FIELD_REF, f.ret_type, src, bitsize_int (64),
-                    bitsize_int (high_half_p ^ BYTES_BIG_ENDIAN ? 64 : 0));
+    auto half = build_vec_extract_half (f.ret_type, src, high_half_p);
     return gimple_build_assign (f.lhs (), half);
   }
 };
@@ -1856,6 +1866,211 @@ using gimple_compare_abs = 
gimple_compare_base<compare_kind::abs>;
 using gimple_compare_zero = gimple_compare_base<compare_kind::zero>;
 using gimple_tst = gimple_compare_base<compare_kind::tst>;
 
+/* Widening multiply with optional accumulator.  HIGH_P selects the high forms,
+   usually spelled as `<name>_high`, eg. vmlsl_high.  */
+template <bool high_p> class gimple_widen_mult : public gimple_function_base
+{
+public:
+  /* How an intrinsic combines the widened product with an accumulator.  */
+  enum accumulation
+  {
+    NO_ACCUM,
+    PLUS_ACCUM,
+    MINUS_ACCUM
+  };
+
+private:
+  struct high_form
+  {
+    const char *name;
+    const function_base *const *base;
+    const function_shape *const *shape;
+  };
+
+  accumulation m_accum;
+
+  /* Used to redirect the low forms to the high forms.  */
+  high_form m_high;
+
+  /* The first multiplicand is operand 0 for VMULL and 1 otherwise.  */
+  int first_mult_arg () const { return m_accum != NO_ACCUM; }
+
+  /* Return the VECTOR_CST corresponding to VAL if it is one or if it is an
+     SSA_NAME which defines one.  */
+  tree vector_constant_value (tree val) const
+  {
+    if (TREE_CODE (val) == SSA_NAME)
+      {
+       gimple *def = SSA_NAME_DEF_STMT (val);
+       if (gimple_assign_single_p (def))
+         val = gimple_assign_rhs1 (def);
+      }
+
+    return TREE_CODE (val) == VECTOR_CST ? val : NULL_TREE;
+  }
+
+  /* Return true if VAL can be profitably passed to the high form.  */
+  bool widenable_for_high_form_p (tree val) const
+  {
+    return aarch64_v128_highpart_src_reg (val) != NULL_TREE
+          || vector_constant_value (val) != NULL_TREE
+          || ssa_uniform_vector_p (val) != NULL_TREE;
+  }
+
+  /* Build and return the 128-bit vector that the high form should be given in
+     place of VAL when widenable_for_high_form_p holds true.  */
+  tree build_high_form_operand (gimple_folder &f, tree val) const
+  {
+    tree narrow_type = TREE_TYPE (val);
+    gcc_assert (known_eq (GET_MODE_BITSIZE (TYPE_MODE (narrow_type)), 64));
+    tree wide_type = build_vector_type (TREE_TYPE (narrow_type),
+                                       TYPE_VECTOR_SUBPARTS (narrow_type) * 2);
+
+    /* BIT_FIELD_REF of upper half.  Handle vreinterprets by view-converting to
+       the actual type we want.  */
+    if (tree obj = aarch64_v128_highpart_src_reg (val))
+      return types_compatible_p (TREE_TYPE (obj), wide_type)
+              ? obj
+              : f.force_val (build1 (VIEW_CONVERT_EXPR, wide_type, obj));
+
+    /* Constant.  */
+    if (tree cst = vector_constant_value (val))
+      return aarch64_build_vector_cst (cst, wide_type);
+
+    /* Splat.  */
+    if (tree elt = ssa_uniform_vector_p (val))
+      return f.force_val (build_vec_dup (wide_type, elt));
+
+    gcc_unreachable ();
+  }
+
+  /* Redirect the call in F to its high form if possible, otherwise return
+     NULL.  */
+  gimple *redirect_to_high_form (gimple_folder &f, unsigned int first,
+                                const high_form &high) const
+  {
+    if (!high.name)
+      return NULL;
+
+    tree orig1 = gimple_call_arg (f.call, first);
+    tree orig2 = gimple_call_arg (f.call, first + 1);
+
+    if (!widenable_for_high_form_p (orig1) || !widenable_for_high_form_p 
(orig2)
+       || (!aarch64_v128_highpart_src_reg (orig1)
+           && !aarch64_v128_highpart_src_reg (orig2)))
+      return NULL;
+
+    function_instance instance (high.name, *high.base, *high.shape,
+                               f.mode_suffix_id, f.type_suffix_ids, GROUP_none,
+                               PRED_none, FPM_unused);
+    gcall *call = f.redirect_call (instance);
+    if (!call)
+      return NULL;
+
+    gimple_call_set_arg (call, first, build_high_form_operand (f, orig1));
+    gimple_call_set_arg (call, first + 1, build_high_form_operand (f, orig2));
+    return call;
+  }
+
+public:
+  constexpr gimple_widen_mult (accumulation accum = NO_ACCUM,
+                              high_form high = {})
+    : m_accum (accum), m_high (high) {}
+
+  gimple *fold (gimple_folder &f) const override
+  {
+    /* Folding is deferred until the function is in SSA form as
+       SSA_NAME_DEF_STMT is not able to look through user-defined constant 
decls
+       until then.  */
+    if ((cfun->curr_properties & PROP_ssa) == 0)
+      return nullptr;
+
+    int first = first_mult_arg ();
+
+    /* First try to optimize to the high form if both operands are extracts of
+       upper halves of vectors.  */
+    if (gimple *high_call = redirect_to_high_form (f, first, m_high))
+      return high_call;
+
+    /* Folding is not profitable if only one operand is widenable or if the
+       resulting element size is >= 64 bits (which leads to scalarization). 
Punt
+       on those cases.  */
+    if (TYPE_PRECISION (TREE_TYPE (f.ret_type)) >= 64
+       || widenable_for_high_form_p (gimple_call_arg (f.call, first))
+       || widenable_for_high_form_p (gimple_call_arg (f.call, first + 1)))
+      return NULL;
+
+    /* Otherwise translate to GIMPLE as `(WIDE_TYPE) A * (WIDE_TYPE) B`.  */
+    tree wide_type = f.ret_type;
+    tree a = gimple_call_arg (f.call, first);
+    tree b = gimple_call_arg (f.call, first + 1);
+    gcc_assert (TYPE_PRECISION (TREE_TYPE (wide_type))
+               == TYPE_PRECISION (TREE_TYPE (TREE_TYPE (a))) * 2);
+    if (high_p)
+      {
+       tree half_type = build_vector_type (TREE_TYPE (TREE_TYPE (a)),
+                                           TYPE_VECTOR_SUBPARTS (wide_type));
+       a = f.force_val (build_vec_extract_half (half_type, a, true));
+       b = f.force_val (build_vec_extract_half (half_type, b, true));
+      }
+    a = f.force_val (fold_build1 (CONVERT_EXPR, wide_type, a));
+    b = f.force_val (fold_build1 (CONVERT_EXPR, wide_type, b));
+    tree product = fold_build2 (MULT_EXPR, wide_type, a, b);
+
+    /* Non-accumulating intrinsic.  */
+    if (m_accum == NO_ACCUM)
+      return gimple_build_assign (f.lhs (), product);
+
+    /* Accumulating intrinsic.  */
+    tree_code accum_code = m_accum == PLUS_ACCUM ? PLUS_EXPR : MINUS_EXPR;
+    tree accumulator = gimple_call_arg (f.call, 0);
+    product = f.force_val (product);
+
+    /* Accumulate in an unsigned mode to match wrapping semantics.  */
+    tree uwide_type = wide_type;
+    if (!TYPE_UNSIGNED (TREE_TYPE (wide_type)))
+      {
+       uwide_type = unsigned_type_for (wide_type);
+       accumulator = f.force_val (build_cast (uwide_type, accumulator));
+       product = f.force_val (build_cast (uwide_type, product));
+      }
+
+    return gimple_build_assign (
+      f.lhs (),
+      build_cast (wide_type, f.force_val (fold_build2 (accum_code, uwide_type,
+                                                      accumulator, product))));
+  }
+
+  rtx expand (function_expander &e) const override
+  {
+    auto mode = GET_MODE (e.args[first_mult_arg ()]);
+    auto ext = e.type_suffix (0).unsigned_p ? ZERO_EXTEND : SIGN_EXTEND;
+
+    insn_code icode;
+    switch (m_accum)
+      {
+      case NO_ACCUM:
+       icode = high_p
+                 ? e.direct_optab_handler_for_sign (vec_widen_smult_hi_optab,
+                                                    vec_widen_umult_hi_optab,
+                                                    0, mode)
+                 : code_for_aarch64_intrinsic_vec_mult_lo (ext, mode);
+       break;
+      case PLUS_ACCUM:
+       icode = high_p ? code_for_aarch64_mlal_hi (ext, mode)
+                      : code_for_aarch64_mlal (ext, mode);
+       break;
+      case MINUS_ACCUM:
+       icode = high_p ? code_for_aarch64_mlsl_hi (ext, mode)
+                      : code_for_aarch64_mlsl (ext, mode);
+       break;
+      default:
+       gcc_unreachable ();
+      }
+    return e.use_exact_insn (icode);
+  }
+};
+
 // Reinterpret
 NEON_FUNCTION (vreinterpret, vreinterpretq, gimple_reinterpret,)
 
@@ -2008,6 +2223,25 @@ NEON_FUNCTION (vqrshrun_high_n, 
gimple_code_for_mode_function, (code_for_aarch64
 NEON_FUNCTION (vshll_n,      gimple_unspec_based_function, 
(code_for_aarch64_shll_n, UNSPEC_SSHLL, UNSPEC_USHLL))
 NEON_FUNCTION (vshll_high_n, gimple_unspec_based_function, 
(code_for_aarch64_shll2_n, UNSPEC_SSHLL, UNSPEC_USHLL))
 
+// Widening multiply and multiply-accumulate
+NEON_FUNCTION (vmull,      gimple_widen_mult<false>,
+              (gimple_widen_mult<false>::NO_ACCUM,
+               { "vmull_high", &functions::vmull_high,
+                 &shapes::vmull_high_bhs_integer_shape }))
+NEON_FUNCTION (vmull_high, gimple_widen_mult<true>,)
+NEON_FUNCTION (vmlal,      gimple_widen_mult<false>,
+              (gimple_widen_mult<false>::PLUS_ACCUM,
+               { "vmlal_high", &functions::vmlal_high,
+                 &shapes::vmlal_high_bhs_integer_shape }))
+NEON_FUNCTION (vmlal_high, gimple_widen_mult<true>,
+              (gimple_widen_mult<true>::PLUS_ACCUM))
+NEON_FUNCTION (vmlsl,      gimple_widen_mult<false>,
+              (gimple_widen_mult<false>::MINUS_ACCUM,
+               { "vmlsl_high", &functions::vmlsl_high,
+                 &shapes::vmlsl_high_bhs_integer_shape }))
+NEON_FUNCTION (vmlsl_high, gimple_widen_mult<true>,
+              (gimple_widen_mult<true>::MINUS_ACCUM))
+
 // Bitwise operations
 NEON_FUNCTION (vand,  vandq,  gimple_expr,    (BIT_AND_EXPR))
 NEON_FUNCTION (vbic,  vbicq,  gimple_not_rhs, (BIT_AND_EXPR))
diff --git a/gcc/config/aarch64/aarch64-neon-builtins-base.def 
b/gcc/config/aarch64/aarch64-neon-builtins-base.def
index f59942e8251..6e5b4d44d12 100644
--- a/gcc/config/aarch64/aarch64-neon-builtins-base.def
+++ b/gcc/config/aarch64/aarch64-neon-builtins-base.def
@@ -519,6 +519,16 @@ DEF_NEON_FUNCTION (vcltz,  h_float, ("Du0,D0"))
 DEF_NEON_FUNCTION (vcltzq, h_float, ("Qu0,Q0"))
 #undef REQUIRED_EXTENSIONS
 
+// Widening multiply and multiply-accumulate
+#define REQUIRED_EXTENSIONS nonstreaming_only (AARCH64_FL_SIMD)
+DEF_NEON_FUNCTION (vmull,       bhs_integer, ("Qd0,D0,D0"))
+DEF_NEON_FUNCTION (vmull_high,  bhs_integer, ("Qd0,Q0,Q0"))
+DEF_NEON_FUNCTION (vmlal,       bhs_integer, ("Qd0,Qd0,D0,D0"))
+DEF_NEON_FUNCTION (vmlal_high,  bhs_integer, ("Qd0,Qd0,Q0,Q0"))
+DEF_NEON_FUNCTION (vmlsl,       bhs_integer, ("Qd0,Qd0,D0,D0"))
+DEF_NEON_FUNCTION (vmlsl_high,  bhs_integer, ("Qd0,Qd0,Q0,Q0"))
+#undef REQUIRED_EXTENSIONS
+
 // Bitwise operations
 #define REQUIRED_EXTENSIONS nonstreaming_only (AARCH64_FL_SIMD)
 DEF_NEON_FUNCTION (vand,   all_integer, ("D0,D0,D0"))
diff --git a/gcc/config/aarch64/aarch64-simd-builtins.def 
b/gcc/config/aarch64/aarch64-simd-builtins.def
index 2f004292b28..c2a07fe3e2a 100644
--- a/gcc/config/aarch64/aarch64-simd-builtins.def
+++ b/gcc/config/aarch64/aarch64-simd-builtins.def
@@ -140,18 +140,10 @@
   BUILTIN_VQN (UNOP, xtn, 0, DEFAULT)
   BUILTIN_VQN (UNOPU, xtn, 0, DEFAULT)
 
-  /* Implemented by aarch64_<su>mlsl<mode>.  */
-  BUILTIN_VD_BHSI (TERNOP, smlsl, 0, DEFAULT)
-  BUILTIN_VD_BHSI (TERNOPU, umlsl, 0, DEFAULT)
-
   /* Implemented by aarch64_<su>mlsl_n<mode>.  */
   BUILTIN_VD_HSI (TERNOP, smlsl_n, 0, DEFAULT)
   BUILTIN_VD_HSI (TERNOPU, umlsl_n, 0, DEFAULT)
 
-  /* Implemented by aarch64_<su>mlal<mode>.  */
-  BUILTIN_VD_BHSI (TERNOP, smlal, 0, DEFAULT)
-  BUILTIN_VD_BHSI (TERNOPU, umlal, 0, DEFAULT)
-
   /* Implemented by aarch64_<su>mlal_n<mode>.  */
   BUILTIN_VD_HSI (TERNOP, smlal_n, 0, DEFAULT)
   BUILTIN_VD_HSI (TERNOPU, umlal_n, 0, DEFAULT)
@@ -215,9 +207,6 @@
   BUILTIN_VQ_HSI (TERNOP, sqdmlal2_n, 0, DEFAULT)
   BUILTIN_VQ_HSI (TERNOP, sqdmlsl2_n, 0, DEFAULT)
 
-  BUILTIN_VD_BHSI (BINOP, intrinsic_vec_smult_lo_, 0, DEFAULT)
-  BUILTIN_VD_BHSI (BINOPU, intrinsic_vec_umult_lo_, 0, DEFAULT)
-
   BUILTIN_VQW (BINOP, vec_widen_smult_hi_, 10, DEFAULT)
   BUILTIN_VQW (BINOPU, vec_widen_umult_hi_, 10, DEFAULT)
 
diff --git a/gcc/config/aarch64/aarch64-simd.md 
b/gcc/config/aarch64/aarch64-simd.md
index 681a7c97a3d..d75cac58833 100644
--- a/gcc/config/aarch64/aarch64-simd.md
+++ b/gcc/config/aarch64/aarch64-simd.md
@@ -2351,7 +2351,7 @@
   [(set_attr "type" "neon_mla_<Vetype>_long")]
 )
 
-(define_expand "aarch64_<su>mlal_hi<mode>"
+(define_expand "@aarch64_<su>mlal_hi<mode>"
   [(match_operand:<VWIDE> 0 "register_operand")
    (match_operand:<VWIDE> 1 "register_operand")
    (ANY_EXTEND:<VWIDE>(match_operand:VQW 2 "register_operand"))
@@ -2428,7 +2428,7 @@
   [(set_attr "type" "neon_mla_<Vetype>_long")]
 )
 
-(define_expand "aarch64_<su>mlsl_hi<mode>"
+(define_expand "@aarch64_<su>mlsl_hi<mode>"
   [(match_operand:<VWIDE> 0 "register_operand")
    (match_operand:<VWIDE> 1 "register_operand")
    (ANY_EXTEND:<VWIDE>(match_operand:VQW 2 "register_operand"))
@@ -2473,7 +2473,7 @@
 }
 )
 
-(define_insn "aarch64_<su>mlal<mode>"
+(define_insn "@aarch64_<su>mlal<mode>"
   [(set (match_operand:<VWIDE> 0 "register_operand" "=w")
         (plus:<VWIDE>
           (mult:<VWIDE>
@@ -2502,7 +2502,7 @@
   [(set_attr "type" "neon_mla_<Vetype>_long")]
 )
 
-(define_insn "aarch64_<su>mlsl<mode>"
+(define_insn "@aarch64_<su>mlsl<mode>"
   [(set (match_operand:<VWIDE> 0 "register_operand" "=w")
         (minus:<VWIDE>
           (match_operand:<VWIDE> 1 "register_operand" "0")
@@ -2544,7 +2544,7 @@
   [(set_attr "type" "neon_mul_<Vetype>_long")]
 )
 
-(define_insn "aarch64_intrinsic_vec_<su>mult_lo_<mode>"
+(define_insn "@aarch64_intrinsic_vec_<su>mult_lo_<mode>"
   [(set (match_operand:<VWIDE> 0 "register_operand" "=w")
        (mult:<VWIDE> (ANY_EXTEND:<VWIDE>
                         (match_operand:VD_BHSI 1 "register_operand" "w"))
diff --git a/gcc/config/aarch64/arm_neon.h b/gcc/config/aarch64/arm_neon.h
index 8769a119a64..45c71fa7724 100644
--- a/gcc/config/aarch64/arm_neon.h
+++ b/gcc/config/aarch64/arm_neon.h
@@ -1373,48 +1373,6 @@ vmlal_high_n_u32 (uint64x2_t __a, uint32x4_t __b, 
uint32_t __c)
   return __builtin_aarch64_umlal_hi_nv4si_uuuu (__a, __b, __c);
 }
 
-__extension__ extern __inline int16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlal_high_s8 (int16x8_t __a, int8x16_t __b, int8x16_t __c)
-{
-  return __builtin_aarch64_smlal_hiv16qi (__a, __b, __c);
-}
-
-__extension__ extern __inline int32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlal_high_s16 (int32x4_t __a, int16x8_t __b, int16x8_t __c)
-{
-  return __builtin_aarch64_smlal_hiv8hi (__a, __b, __c);
-}
-
-__extension__ extern __inline int64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlal_high_s32 (int64x2_t __a, int32x4_t __b, int32x4_t __c)
-{
-  return __builtin_aarch64_smlal_hiv4si (__a, __b, __c);
-}
-
-__extension__ extern __inline uint16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlal_high_u8 (uint16x8_t __a, uint8x16_t __b, uint8x16_t __c)
-{
-  return __builtin_aarch64_umlal_hiv16qi_uuuu (__a, __b, __c);
-}
-
-__extension__ extern __inline uint32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlal_high_u16 (uint32x4_t __a, uint16x8_t __b, uint16x8_t __c)
-{
-  return __builtin_aarch64_umlal_hiv8hi_uuuu (__a, __b, __c);
-}
-
-__extension__ extern __inline uint64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlal_high_u32 (uint64x2_t __a, uint32x4_t __b, uint32x4_t __c)
-{
-  return __builtin_aarch64_umlal_hiv4si_uuuu (__a, __b, __c);
-}
-
 __extension__ extern __inline int32x4_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
 vmlal_lane_s16 (int32x4_t __acc, int16x4_t __a, int16x4_t __b, const int __c)
@@ -1499,48 +1457,6 @@ vmlal_n_u32 (uint64x2_t __a, uint32x2_t __b, uint32_t 
__c)
   return __builtin_aarch64_umlal_nv2si_uuuu (__a, __b, __c);
 }
 
-__extension__ extern __inline int16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlal_s8 (int16x8_t __a, int8x8_t __b, int8x8_t __c)
-{
-  return __builtin_aarch64_smlalv8qi (__a, __b, __c);
-}
-
-__extension__ extern __inline int32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlal_s16 (int32x4_t __a, int16x4_t __b, int16x4_t __c)
-{
-  return __builtin_aarch64_smlalv4hi (__a, __b, __c);
-}
-
-__extension__ extern __inline int64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlal_s32 (int64x2_t __a, int32x2_t __b, int32x2_t __c)
-{
-  return __builtin_aarch64_smlalv2si (__a, __b, __c);
-}
-
-__extension__ extern __inline uint16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlal_u8 (uint16x8_t __a, uint8x8_t __b, uint8x8_t __c)
-{
-  return __builtin_aarch64_umlalv8qi_uuuu (__a, __b, __c);
-}
-
-__extension__ extern __inline uint32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlal_u16 (uint32x4_t __a, uint16x4_t __b, uint16x4_t __c)
-{
-  return __builtin_aarch64_umlalv4hi_uuuu (__a, __b, __c);
-}
-
-__extension__ extern __inline uint64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlal_u32 (uint64x2_t __a, uint32x2_t __b, uint32x2_t __c)
-{
-  return __builtin_aarch64_umlalv2si_uuuu (__a, __b, __c);
-}
-
 __extension__ extern __inline int32x4_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
 vmlsl_high_lane_s16(int32x4_t __a, int16x8_t __b, int16x4_t __v,
@@ -1633,48 +1549,6 @@ vmlsl_high_n_u32 (uint64x2_t __a, uint32x4_t __b, 
uint32_t __c)
   return __builtin_aarch64_umlsl_hi_nv4si_uuuu (__a, __b, __c);
 }
 
-__extension__ extern __inline int16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlsl_high_s8 (int16x8_t __a, int8x16_t __b, int8x16_t __c)
-{
-  return __builtin_aarch64_smlsl_hiv16qi (__a, __b, __c);
-}
-
-__extension__ extern __inline int32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlsl_high_s16 (int32x4_t __a, int16x8_t __b, int16x8_t __c)
-{
-  return __builtin_aarch64_smlsl_hiv8hi (__a, __b, __c);
-}
-
-__extension__ extern __inline int64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlsl_high_s32 (int64x2_t __a, int32x4_t __b, int32x4_t __c)
-{
-  return __builtin_aarch64_smlsl_hiv4si (__a, __b, __c);
-}
-
-__extension__ extern __inline uint16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlsl_high_u8 (uint16x8_t __a, uint8x16_t __b, uint8x16_t __c)
-{
-  return __builtin_aarch64_umlsl_hiv16qi_uuuu (__a, __b, __c);
-}
-
-__extension__ extern __inline uint32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlsl_high_u16 (uint32x4_t __a, uint16x8_t __b, uint16x8_t __c)
-{
-  return __builtin_aarch64_umlsl_hiv8hi_uuuu (__a, __b, __c);
-}
-
-__extension__ extern __inline uint64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlsl_high_u32 (uint64x2_t __a, uint32x4_t __b, uint32x4_t __c)
-{
-  return __builtin_aarch64_umlsl_hiv4si_uuuu (__a, __b, __c);
-}
-
 __extension__ extern __inline int32x4_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
 vmlsl_lane_s16 (int32x4_t __a, int16x4_t __b, int16x4_t __v, const int __lane)
@@ -1763,48 +1637,6 @@ vmlsl_n_u32 (uint64x2_t __a, uint32x2_t __b, uint32_t 
__c)
   return __builtin_aarch64_umlsl_nv2si_uuuu (__a, __b, __c);
 }
 
-__extension__ extern __inline int16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlsl_s8 (int16x8_t __a, int8x8_t __b, int8x8_t __c)
-{
-  return __builtin_aarch64_smlslv8qi (__a, __b, __c);
-}
-
-__extension__ extern __inline int32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlsl_s16 (int32x4_t __a, int16x4_t __b, int16x4_t __c)
-{
-  return __builtin_aarch64_smlslv4hi (__a, __b, __c);
-}
-
-__extension__ extern __inline int64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlsl_s32 (int64x2_t __a, int32x2_t __b, int32x2_t __c)
-{
-  return __builtin_aarch64_smlslv2si (__a, __b, __c);
-}
-
-__extension__ extern __inline uint16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlsl_u8 (uint16x8_t __a, uint8x8_t __b, uint8x8_t __c)
-{
-  return __builtin_aarch64_umlslv8qi_uuuu (__a, __b, __c);
-}
-
-__extension__ extern __inline uint32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlsl_u16 (uint32x4_t __a, uint16x4_t __b, uint16x4_t __c)
-{
-  return __builtin_aarch64_umlslv4hi_uuuu (__a, __b, __c);
-}
-
-__extension__ extern __inline uint64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmlsl_u32 (uint64x2_t __a, uint32x2_t __b, uint32x2_t __c)
-{
-  return __builtin_aarch64_umlslv2si_uuuu (__a, __b, __c);
-}
-
 __extension__ extern __inline int16x8_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
 vmovl_high_s8 (int8x16_t __a)
@@ -2064,48 +1896,6 @@ vmull_high_p8 (poly8x16_t __a, poly8x16_t __b)
   return __builtin_aarch64_pmull_hiv16qi_ppp (__a, __b);
 }
 
-__extension__ extern __inline int16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmull_high_s8 (int8x16_t __a, int8x16_t __b)
-{
-  return __builtin_aarch64_vec_widen_smult_hi_v16qi (__a, __b);
-}
-
-__extension__ extern __inline int32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmull_high_s16 (int16x8_t __a, int16x8_t __b)
-{
-  return __builtin_aarch64_vec_widen_smult_hi_v8hi (__a, __b);
-}
-
-__extension__ extern __inline int64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmull_high_s32 (int32x4_t __a, int32x4_t __b)
-{
-  return __builtin_aarch64_vec_widen_smult_hi_v4si (__a, __b);
-}
-
-__extension__ extern __inline uint16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmull_high_u8 (uint8x16_t __a, uint8x16_t __b)
-{
-  return __builtin_aarch64_vec_widen_umult_hi_v16qi_uuu (__a, __b);
-}
-
-__extension__ extern __inline uint32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmull_high_u16 (uint16x8_t __a, uint16x8_t __b)
-{
-  return __builtin_aarch64_vec_widen_umult_hi_v8hi_uuu (__a, __b);
-}
-
-__extension__ extern __inline uint64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmull_high_u32 (uint32x4_t __a, uint32x4_t __b)
-{
-  return __builtin_aarch64_vec_widen_umult_hi_v4si_uuu (__a, __b);
-}
-
 __extension__ extern __inline int32x4_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
 vmull_lane_s16 (int16x4_t __a, int16x4_t __b, const int __c)
@@ -2197,48 +1987,6 @@ vmull_p8 (poly8x8_t __a, poly8x8_t __b)
   return __builtin_aarch64_pmullv8qi_ppp (__a, __b);
 }
 
-__extension__ extern __inline int16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmull_s8 (int8x8_t __a, int8x8_t __b)
-{
-  return __builtin_aarch64_intrinsic_vec_smult_lo_v8qi (__a, __b);
-}
-
-__extension__ extern __inline int32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmull_s16 (int16x4_t __a, int16x4_t __b)
-{
-  return __builtin_aarch64_intrinsic_vec_smult_lo_v4hi (__a, __b);
-}
-
-__extension__ extern __inline int64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmull_s32 (int32x2_t __a, int32x2_t __b)
-{
-  return __builtin_aarch64_intrinsic_vec_smult_lo_v2si (__a, __b);
-}
-
-__extension__ extern __inline uint16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmull_u8 (uint8x8_t __a, uint8x8_t __b)
-{
-  return __builtin_aarch64_intrinsic_vec_umult_lo_v8qi_uuu (__a, __b);
-}
-
-__extension__ extern __inline uint32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmull_u16 (uint16x4_t __a, uint16x4_t __b)
-{
-  return __builtin_aarch64_intrinsic_vec_umult_lo_v4hi_uuu (__a, __b);
-}
-
-__extension__ extern __inline uint64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vmull_u32 (uint32x2_t __a, uint32x2_t __b)
-{
-  return __builtin_aarch64_intrinsic_vec_umult_lo_v2si_uuu (__a, __b);
-}
-
 __extension__ extern __inline int16x4_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
 vpadal_s8 (int16x4_t __a, int8x8_t __b)
diff --git a/gcc/testsuite/gcc.target/aarch64/neon/discarded_result.c 
b/gcc/testsuite/gcc.target/aarch64/neon/discarded_result.c
index c5033a6429e..ede6a203b01 100644
--- a/gcc/testsuite/gcc.target/aarch64/neon/discarded_result.c
+++ b/gcc/testsuite/gcc.target/aarch64/neon/discarded_result.c
@@ -15,3 +15,66 @@ void foo(float32x2_t a, float32x2_t b)
 {
   vadd_f32 (a, b);
 }
+
+/*
+** test_vmull_s8:
+** ret
+*/
+void test_vmull_s8 (int8x8_t a, int8x8_t b)
+{
+  vmull_s8 (a, b);
+}
+
+/*
+** test_vmull_high_s16:
+** ret
+*/
+void test_vmull_high_s16 (int16x8_t a, int16x8_t b)
+{
+  vmull_high_s16 (a, b);
+}
+
+/*
+** test_vmull_s32:
+** ret
+*/
+void test_vmull_s32 (int32x2_t a, int32x2_t b)
+{
+  vmull_s32 (a, b);
+}
+
+/*
+** test_vmlal_u8:
+** ret
+*/
+void test_vmlal_u8 (uint16x8_t acc, uint8x8_t a, uint8x8_t b)
+{
+  vmlal_u8 (acc, a, b);
+}
+
+/*
+** test_vmlsl_high_s16:
+** ret
+*/
+void test_vmlsl_high_s16 (int32x4_t acc, int16x8_t a, int16x8_t b)
+{
+  vmlsl_high_s16 (acc, a, b);
+}
+
+/*
+** test_vmull_high_redirect:
+** ret
+*/
+void test_vmull_high_redirect (int32x4_t x, int32x4_t y)
+{
+  vmull_s32 (vget_high_s32 (x), vget_high_s32 (y));
+}
+
+/*
+** test_vmull_splat_redirect:
+** ret
+*/
+void test_vmull_splat_redirect (int8x16_t x)
+{
+  vmull_s8 (vget_high_s8 (x), vdup_n_s8 (3));
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/neon/vmlal.c 
b/gcc/testsuite/gcc.target/aarch64/neon/vmlal.c
new file mode 100644
index 00000000000..1466631a959
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/neon/vmlal.c
@@ -0,0 +1,102 @@
+/* { dg-do compile } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "arm_neon_test.h"
+
+/*
+** test_vmlal_u8:
+** umlal       v0\.8h, (v1\.8b, v2\.8b|v2\.8b, v1\.8b)
+** ret
+*/
+TEST_TERNARY (vmlal_u8, uint16x8_t, uint16x8_t, uint8x8_t, uint8x8_t)
+
+/*
+** test_vmlal_high_u8:
+** umlal2      v0\.8h, (v1\.16b, v2\.16b|v2\.16b, v1\.16b)
+** ret
+*/
+TEST_TERNARY (vmlal_high_u8, uint16x8_t, uint16x8_t, uint8x16_t, uint8x16_t)
+
+/*
+** test_vmlal_s8:
+** smlal       v0\.8h, (v1\.8b, v2\.8b|v2\.8b, v1\.8b)
+** ret
+*/
+TEST_TERNARY (vmlal_s8, int16x8_t, int16x8_t, int8x8_t, int8x8_t)
+
+/*
+** test_vmlal_high_s8:
+** smlal2      v0\.8h, (v1\.16b, v2\.16b|v2\.16b, v1\.16b)
+** ret
+*/
+TEST_TERNARY (vmlal_high_s8, int16x8_t, int16x8_t, int8x16_t, int8x16_t)
+
+/*
+** test_vmlal_u16:
+** umlal       v0\.4s, (v1\.4h, v2\.4h|v2\.4h, v1\.4h)
+** ret
+*/
+TEST_TERNARY (vmlal_u16, uint32x4_t, uint32x4_t, uint16x4_t, uint16x4_t)
+
+/*
+** test_vmlal_high_u16:
+** umlal2      v0\.4s, (v1\.8h, v2\.8h|v2\.8h, v1\.8h)
+** ret
+*/
+TEST_TERNARY (vmlal_high_u16, uint32x4_t, uint32x4_t, uint16x8_t, uint16x8_t)
+
+/*
+** test_vmlal_s16:
+** smlal       v0\.4s, (v1\.4h, v2\.4h|v2\.4h, v1\.4h)
+** ret
+*/
+TEST_TERNARY (vmlal_s16, int32x4_t, int32x4_t, int16x4_t, int16x4_t)
+
+/*
+** test_vmlal_high_s16:
+** smlal2      v0\.4s, (v1\.8h, v2\.8h|v2\.8h, v1\.8h)
+** ret
+*/
+TEST_TERNARY (vmlal_high_s16, int32x4_t, int32x4_t, int16x8_t, int16x8_t)
+
+/*
+** test_vmlal_u32:
+** umlal       v0\.2d, (v1\.2s, v2\.2s|v2\.2s, v1\.2s)
+** ret
+*/
+TEST_TERNARY (vmlal_u32, uint64x2_t, uint64x2_t, uint32x2_t, uint32x2_t)
+
+/*
+** test_vmlal_high_u32:
+** umlal2      v0\.2d, (v1\.4s, v2\.4s|v2\.4s, v1\.4s)
+** ret
+*/
+TEST_TERNARY (vmlal_high_u32, uint64x2_t, uint64x2_t, uint32x4_t, uint32x4_t)
+
+/*
+** test_vmlal_s32:
+** smlal       v0\.2d, (v1\.2s, v2\.2s|v2\.2s, v1\.2s)
+** ret
+*/
+TEST_TERNARY (vmlal_s32, int64x2_t, int64x2_t, int32x2_t, int32x2_t)
+
+/*
+** test_vmlal_high_s32:
+** smlal2      v0\.2d, (v1\.4s, v2\.4s|v2\.4s, v1\.4s)
+** ret
+*/
+TEST_TERNARY (vmlal_high_s32, int64x2_t, int64x2_t, int32x4_t, int32x4_t)
+
+/* Both multiplicands are upper halves, so the fold uses the high form rather
+   than extracting them.  */
+
+/*
+** test_vmlal_both_high:
+** smlal2      v0\.2d, (v1\.4s, v2\.4s|v2\.4s, v1\.4s)
+** ret
+*/
+int64x2_t
+test_vmlal_both_high (int64x2_t acc, int32x4_t a, int32x4_t b)
+{
+  return vmlal_s32 (acc, vget_high_s32 (a), vget_high_s32 (b));
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/neon/vmlsl.c 
b/gcc/testsuite/gcc.target/aarch64/neon/vmlsl.c
new file mode 100644
index 00000000000..c4f433e6e54
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/neon/vmlsl.c
@@ -0,0 +1,88 @@
+/* { dg-do compile } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "arm_neon_test.h"
+
+/*
+** test_vmlsl_u8:
+** umlsl       v0\.8h, (v1\.8b, v2\.8b|v2\.8b, v1\.8b)
+** ret
+*/
+TEST_TERNARY (vmlsl_u8, uint16x8_t, uint16x8_t, uint8x8_t, uint8x8_t)
+
+/*
+** test_vmlsl_high_u8:
+** umlsl2      v0\.8h, (v1\.16b, v2\.16b|v2\.16b, v1\.16b)
+** ret
+*/
+TEST_TERNARY (vmlsl_high_u8, uint16x8_t, uint16x8_t, uint8x16_t, uint8x16_t)
+
+/*
+** test_vmlsl_s8:
+** smlsl       v0\.8h, (v1\.8b, v2\.8b|v2\.8b, v1\.8b)
+** ret
+*/
+TEST_TERNARY (vmlsl_s8, int16x8_t, int16x8_t, int8x8_t, int8x8_t)
+
+/*
+** test_vmlsl_high_s8:
+** smlsl2      v0\.8h, (v1\.16b, v2\.16b|v2\.16b, v1\.16b)
+** ret
+*/
+TEST_TERNARY (vmlsl_high_s8, int16x8_t, int16x8_t, int8x16_t, int8x16_t)
+
+/*
+** test_vmlsl_u16:
+** umlsl       v0\.4s, (v1\.4h, v2\.4h|v2\.4h, v1\.4h)
+** ret
+*/
+TEST_TERNARY (vmlsl_u16, uint32x4_t, uint32x4_t, uint16x4_t, uint16x4_t)
+
+/*
+** test_vmlsl_high_u16:
+** umlsl2      v0\.4s, (v1\.8h, v2\.8h|v2\.8h, v1\.8h)
+** ret
+*/
+TEST_TERNARY (vmlsl_high_u16, uint32x4_t, uint32x4_t, uint16x8_t, uint16x8_t)
+
+/*
+** test_vmlsl_s16:
+** smlsl       v0\.4s, (v1\.4h, v2\.4h|v2\.4h, v1\.4h)
+** ret
+*/
+TEST_TERNARY (vmlsl_s16, int32x4_t, int32x4_t, int16x4_t, int16x4_t)
+
+/*
+** test_vmlsl_high_s16:
+** smlsl2      v0\.4s, (v1\.8h, v2\.8h|v2\.8h, v1\.8h)
+** ret
+*/
+TEST_TERNARY (vmlsl_high_s16, int32x4_t, int32x4_t, int16x8_t, int16x8_t)
+
+/*
+** test_vmlsl_u32:
+** umlsl       v0\.2d, (v1\.2s, v2\.2s|v2\.2s, v1\.2s)
+** ret
+*/
+TEST_TERNARY (vmlsl_u32, uint64x2_t, uint64x2_t, uint32x2_t, uint32x2_t)
+
+/*
+** test_vmlsl_high_u32:
+** umlsl2      v0\.2d, (v1\.4s, v2\.4s|v2\.4s, v1\.4s)
+** ret
+*/
+TEST_TERNARY (vmlsl_high_u32, uint64x2_t, uint64x2_t, uint32x4_t, uint32x4_t)
+
+/*
+** test_vmlsl_s32:
+** smlsl       v0\.2d, (v1\.2s, v2\.2s|v2\.2s, v1\.2s)
+** ret
+*/
+TEST_TERNARY (vmlsl_s32, int64x2_t, int64x2_t, int32x2_t, int32x2_t)
+
+/*
+** test_vmlsl_high_s32:
+** smlsl2      v0\.2d, (v1\.4s, v2\.4s|v2\.4s, v1\.4s)
+** ret
+*/
+TEST_TERNARY (vmlsl_high_s32, int64x2_t, int64x2_t, int32x4_t, int32x4_t)
diff --git a/gcc/testsuite/gcc.target/aarch64/neon/vmull.c 
b/gcc/testsuite/gcc.target/aarch64/neon/vmull.c
new file mode 100644
index 00000000000..3603d44683a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/neon/vmull.c
@@ -0,0 +1,131 @@
+/* { dg-do compile } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "arm_neon_test.h"
+
+/*
+** test_vmull_u8:
+** umull       v0\.8h, (v0\.8b, v1\.8b|v1\.8b, v0\.8b)
+** ret
+*/
+TEST_BINARY (vmull_u8, uint16x8_t, uint8x8_t, uint8x8_t)
+
+/*
+** test_vmull_high_u8:
+** umull2      v0\.8h, (v0\.16b, v1\.16b|v1\.16b, v0\.16b)
+** ret
+*/
+TEST_BINARY (vmull_high_u8, uint16x8_t, uint8x16_t, uint8x16_t)
+
+/*
+** test_vmull_s8:
+** smull       v0\.8h, (v0\.8b, v1\.8b|v1\.8b, v0\.8b)
+** ret
+*/
+TEST_BINARY (vmull_s8, int16x8_t, int8x8_t, int8x8_t)
+
+/*
+** test_vmull_high_s8:
+** smull2      v0\.8h, (v0\.16b, v1\.16b|v1\.16b, v0\.16b)
+** ret
+*/
+TEST_BINARY (vmull_high_s8, int16x8_t, int8x16_t, int8x16_t)
+
+/*
+** test_vmull_u16:
+** umull       v0\.4s, (v0\.4h, v1\.4h|v1\.4h, v0\.4h)
+** ret
+*/
+TEST_BINARY (vmull_u16, uint32x4_t, uint16x4_t, uint16x4_t)
+
+/*
+** test_vmull_high_u16:
+** umull2      v0\.4s, (v0\.8h, v1\.8h|v1\.8h, v0\.8h)
+** ret
+*/
+TEST_BINARY (vmull_high_u16, uint32x4_t, uint16x8_t, uint16x8_t)
+
+/*
+** test_vmull_s16:
+** smull       v0\.4s, (v0\.4h, v1\.4h|v1\.4h, v0\.4h)
+** ret
+*/
+TEST_BINARY (vmull_s16, int32x4_t, int16x4_t, int16x4_t)
+
+/*
+** test_vmull_high_s16:
+** smull2      v0\.4s, (v0\.8h, v1\.8h|v1\.8h, v0\.8h)
+** ret
+*/
+TEST_BINARY (vmull_high_s16, int32x4_t, int16x8_t, int16x8_t)
+
+/*
+** test_vmull_u32:
+** umull       v0\.2d, (v0\.2s, v1\.2s|v1\.2s, v0\.2s)
+** ret
+*/
+TEST_BINARY (vmull_u32, uint64x2_t, uint32x2_t, uint32x2_t)
+
+/*
+** test_vmull_high_u32:
+** umull2      v0\.2d, (v0\.4s, v1\.4s|v1\.4s, v0\.4s)
+** ret
+*/
+TEST_BINARY (vmull_high_u32, uint64x2_t, uint32x4_t, uint32x4_t)
+
+/*
+** test_vmull_s32:
+** smull       v0\.2d, (v0\.2s, v1\.2s|v1\.2s, v0\.2s)
+** ret
+*/
+TEST_BINARY (vmull_s32, int64x2_t, int32x2_t, int32x2_t)
+
+/*
+** test_vmull_high_s32:
+** smull2      v0\.2d, (v0\.4s, v1\.4s|v1\.4s, v0\.4s)
+** ret
+*/
+TEST_BINARY (vmull_high_s32, int64x2_t, int32x4_t, int32x4_t)
+
+/* A low form call whose operands are an upper half and a constant or splat
+   redirects to the high form.  */
+
+/*
+** test_vmull_high_cst:
+** movi        v([0-9]+)\.16b, 0x3
+** smull2      v0\.8h, v0\.16b, v\1\.16b
+** ret
+*/
+int16x8_t
+test_vmull_high_cst (int8x16_t a)
+{
+  return vmull_s8 (vget_high_s8 (a), vdup_n_s8 (3));
+}
+
+/*
+** test_vmull_high_splat:
+** dup v([0-9]+)\.16b, w0
+** smull2      v0\.8h, v0\.16b, v\1\.16b
+** ret
+*/
+int16x8_t
+test_vmull_high_splat (int8x16_t a, int8_t b)
+{
+  return vmull_s8 (vget_high_s8 (a), vdup_n_s8 (b));
+}
+
+/* A constant that reaches the call through a declaration is only recognisable
+   once the function is in SSA form.  */
+
+/*
+** test_vmull_cst_decl:
+** movi        v([0-9]+)\.4h, 0x3
+** smull       v0\.4s, v0\.4h, v\1\.4h
+** ret
+*/
+int32x4_t
+test_vmull_cst_decl (int16x4_t a)
+{
+  int16x4_t b = vdup_n_s16 (3);
+  return vmull_s16 (a, b);
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/simd/fold_to_highpart_1.c 
b/gcc/testsuite/gcc.target/aarch64/simd/fold_to_highpart_1.c
index f082198b54b..b5b261d64a2 100644
--- a/gcc/testsuite/gcc.target/aarch64/simd/fold_to_highpart_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/simd/fold_to_highpart_1.c
@@ -567,25 +567,25 @@ TEST_VMLAL_N
 
 /*
 ** test_vmlsl_s8:
-**     smlsl2  v0\.8h, v1\.16b, v2\.16b
+**     smlsl2  v0\.8h, (v1\.16b, v2\.16b|v2\.16b, v1\.16b)
 **     ret
 */
 
 /*
 ** test_vmlsl_u8:
-**     umlsl2  v0\.8h, v1\.16b, v2\.16b
+**     umlsl2  v0\.8h, (v1\.16b, v2\.16b|v2\.16b, v1\.16b)
 **     ret
 */
 
 /*
 ** test_vmlsl_s16:
-**     smlsl2  v0\.4s, v1\.8h, v2\.8h
+**     smlsl2  v0\.4s, (v1\.8h, v2\.8h|v2\.8h, v1\.8h)
 **     ret
 */
 
 /*
 ** test_vmlsl_u16:
-**     umlsl2  v0\.4s, v1\.8h, v2\.8h
+**     umlsl2  v0\.4s, (v1\.8h, v2\.8h|v2\.8h, v1\.8h)
 **     ret
 */
 
-- 
2.43.0

Reply via email to