Hi Ezra,
On 28/10/2026 21:00, [email protected] wrote:
> From: Ezra Sitorus <[email protected]>
>
> Add support for these new pairwise intrinsic operations: svaddqp, svaddsubp
> and
> svsubp.
>
> gcc/ChangeLog:
> * config/aarch64/aarch64-sve-builtins-sve2.cc
> (svsubp, svaddqp, svaddsubp): Define new function bases.
> * config/aarch64/aarch64-sve-builtins-sve2.def
> (svaddqp, svaddsubp, svsubp): Define new SVE functions.
> * config/aarch64/aarch64-sve-builtins-sve2.h
> (svaddqp, svaddsubp, svsubp): Declare new function bases.
> * config/aarch64/aarch64-sve2.md: Merge the saturating binary
> arithmetic section into the general binary arithmetic section.
> (@aarch64_sve_<sve_int_op><mode>): Remove TARGET_SVE2 condition.
> * config/aarch64/iterators.md
> (UNSPEC_ADDQP): New unspec.
> (UNSPEC_ADDSUBP): Likewise.
> (UNSPEC_SUBP): Likewise.
> (SVE2_INT_BINARY): Add UNSPEC_ADDQP, UNSPEC_ADDSUBP with
> TARGET_SVE2p3_OR_SME2p3 conditions. Add TARGET_SVE2 conditions to
> UNSPEC_SQDMULH, UNSPEC_SQRDMULH.
> (SVE2_INT_BINARY_PAIR): Add UNSPEC_SUBP.
> (sve_int_op): Add new unspec variants.
>
> gcc/testsuite/ChangeLog:
> * gcc.target/aarch64/sve2/acle/asm/addqp_s16.c: New test.
> * gcc.target/aarch64/sve2/acle/asm/addqp_s32.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addqp_s64.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addqp_s8.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addqp_u16.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addqp_u32.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addqp_u64.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addqp_u8.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addsubp_s16.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addsubp_s32.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addsubp_s64.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addsubp_s8.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addsubp_u16.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addsubp_u32.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addsubp_u64.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/addsubp_u8.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/subp_s16.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/subp_s32.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/subp_s64.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/subp_s8.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/subp_u16.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/subp_u32.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/subp_u64.c: Likewise.
> * gcc.target/aarch64/sve2/acle/asm/subp_u8.c: Likewise.
> ---
>
> Changes from v3:
> * Extend SVE2_INT_BINARY with ADDQP and ADDSUBP instead of
> adding another instruction pattern
> * Remove SVE2p3_INT_BINARY_PAIR_UNPRED iterator.
> * Move the target checks into the iterator SVE2_INT_BINARY
> entries. Merge the saturating binary arithmetic documentation
> into the general binary arithmetic section.
> * Split up testcases.
>
> Changes from v2:
> * Make it compatible with recent changes in SVE framework.
>
> .../aarch64/aarch64-sve-builtins-sve2.cc | 3 +
> .../aarch64/aarch64-sve-builtins-sve2.def | 6 ++
> .../aarch64/aarch64-sve-builtins-sve2.h | 3 +
> gcc/config/aarch64/aarch64-sve2.md | 16 ++---
> gcc/config/aarch64/iterators.md | 13 +++-
> .../aarch64/sve2/acle/asm/addqp_s16.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addqp_s32.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addqp_s64.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addqp_s8.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addqp_u16.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addqp_u32.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addqp_u64.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addqp_u8.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addsubp_s16.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addsubp_s32.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addsubp_s64.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addsubp_s8.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addsubp_u16.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addsubp_u32.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addsubp_u64.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/addsubp_u8.c | 36 +++++++++++
> .../aarch64/sve2/acle/asm/subp_s16.c | 59 +++++++++++++++++++
> .../aarch64/sve2/acle/asm/subp_s32.c | 59 +++++++++++++++++++
> .../aarch64/sve2/acle/asm/subp_s64.c | 59 +++++++++++++++++++
> .../aarch64/sve2/acle/asm/subp_s8.c | 59 +++++++++++++++++++
> .../aarch64/sve2/acle/asm/subp_u16.c | 59 +++++++++++++++++++
> .../aarch64/sve2/acle/asm/subp_u32.c | 59 +++++++++++++++++++
> .../aarch64/sve2/acle/asm/subp_u64.c | 59 +++++++++++++++++++
> .../aarch64/sve2/acle/asm/subp_u8.c | 59 +++++++++++++++++++
> 29 files changed, 1077 insertions(+), 12 deletions(-)
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addqp_s16.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addqp_s32.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addqp_s64.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addqp_s8.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addqp_u16.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addqp_u32.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addqp_u64.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addqp_u8.c
> create mode 100644
> gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addsubp_s16.c
> create mode 100644
> gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addsubp_s32.c
> create mode 100644
> gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addsubp_s64.c
> create mode 100644
> gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addsubp_s8.c
> create mode 100644
> gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addsubp_u16.c
> create mode 100644
> gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addsubp_u32.c
> create mode 100644
> gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addsubp_u64.c
> create mode 100644
> gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/addsubp_u8.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/subp_s16.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/subp_s32.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/subp_s64.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/subp_s8.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/subp_u16.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/subp_u32.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/subp_u64.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/subp_u8.c
>
> diff --git a/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc
> b/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc
> index 0b59de34e056..5b9e6161fc1f 100644
> --- a/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc
> +++ b/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc
> @@ -1068,7 +1068,9 @@ FUNCTION (svaddlbt, unspec_based_function,
> (UNSPEC_SADDLBT))
> FUNCTION (svaddlt, unspec_based_function, (UNSPEC_SADDLT, UNSPEC_UADDLT))
> FUNCTION (svaddp, unspec_based_pred_function, (UNSPEC_ADDP, UNSPEC_ADDP,
> UNSPEC_FADDP))
> +FUNCTION (svaddqp, unspec_based_function, (UNSPEC_ADDQP, UNSPEC_ADDQP))
> FUNCTION (svaddqv, reduction, (UNSPEC_ADDQV, UNSPEC_ADDQV, UNSPEC_FADDQV))
> +FUNCTION (svaddsubp, unspec_based_function, (UNSPEC_ADDSUBP, UNSPEC_ADDSUBP))
> FUNCTION (svaddwb, unspec_based_function, (UNSPEC_SADDWB, UNSPEC_UADDWB))
> FUNCTION (svaddwt, unspec_based_function, (UNSPEC_SADDWT, UNSPEC_UADDWT))
> FUNCTION (svaesd, fixed_insn_function, (CODE_FOR_aarch64_sve2_aesd))
> @@ -1320,6 +1322,7 @@ FUNCTION (svsublb, unspec_based_function,
> (UNSPEC_SSUBLB, UNSPEC_USUBLB))
> FUNCTION (svsublbt, unspec_based_function, (UNSPEC_SSUBLBT))
> FUNCTION (svsublt, unspec_based_function, (UNSPEC_SSUBLT, UNSPEC_USUBLT))
> FUNCTION (svsubltb, unspec_based_function, (UNSPEC_SSUBLTB))
> +FUNCTION (svsubp, unspec_based_pred_function, (UNSPEC_SUBP, UNSPEC_SUBP))
> FUNCTION (svsubwb, unspec_based_function, (UNSPEC_SSUBWB, UNSPEC_USUBWB))
> FUNCTION (svsubwt, unspec_based_function, (UNSPEC_SSUBWT, UNSPEC_USUBWT))
> FUNCTION (svtbl2, svtbl2_impl,)
> diff --git a/gcc/config/aarch64/aarch64-sve-builtins-sve2.def
> b/gcc/config/aarch64/aarch64-sve-builtins-sve2.def
> index 3e9d709f2b85..de2da5bfd2cd 100644
> --- a/gcc/config/aarch64/aarch64-sve-builtins-sve2.def
> +++ b/gcc/config/aarch64/aarch64-sve-builtins-sve2.def
> @@ -298,6 +298,12 @@ DEF_SVE_FUNCTION_GS (svwhilelt, compare_scalar, while_x,
> x2, none)
> DEF_SVE_FUNCTION (svwhilelt, compare_scalar_count, while_x_c, none)
> #undef REQUIRED_EXTENSIONS
>
> +#define REQUIRED_EXTENSIONS sve_and_sme (AARCH64_FL_SVE2p3,
> AARCH64_FL_SME2p3)
> +DEF_SVE_FUNCTION (svaddqp, binary, all_integer, none)
> +DEF_SVE_FUNCTION (svaddsubp, binary, all_integer, none)
> +DEF_SVE_FUNCTION (svsubp, binary, all_integer, mx)
> +#undef REQUIRED_EXTENSIONS
> +
> #define REQUIRED_EXTENSIONS nonstreaming_sve (AARCH64_FL_SVE2p1)
> DEF_SVE_FUNCTION (svld1q_gather, load_gather64_sv_offset, all_data, implicit)
> DEF_SVE_FUNCTION (svld1q_gather, load_gather64_sv_index, hsd_data, implicit)
> diff --git a/gcc/config/aarch64/aarch64-sve-builtins-sve2.h
> b/gcc/config/aarch64/aarch64-sve-builtins-sve2.h
> index 393c2c8ca2c8..e07e631861b0 100644
> --- a/gcc/config/aarch64/aarch64-sve-builtins-sve2.h
> +++ b/gcc/config/aarch64/aarch64-sve-builtins-sve2.h
> @@ -39,7 +39,9 @@ namespace aarch64_acle
> extern const function_base *const svaddlbt;
> extern const function_base *const svaddlt;
> extern const function_base *const svaddp;
> + extern const function_base *const svaddqp;
> extern const function_base *const svaddqv;
> + extern const function_base *const svaddsubp;
> extern const function_base *const svaddwb;
> extern const function_base *const svaddwt;
> extern const function_base *const svaesd;
> @@ -249,6 +251,7 @@ namespace aarch64_acle
> extern const function_base *const svsublbt;
> extern const function_base *const svsublt;
> extern const function_base *const svsubltb;
> + extern const function_base *const svsubp;
> extern const function_base *const svsubwb;
> extern const function_base *const svsubwt;
> extern const function_base *const svtbl2;
> diff --git a/gcc/config/aarch64/aarch64-sve2.md
> b/gcc/config/aarch64/aarch64-sve2.md
> index 7d8504db3048..c8178e0535c8 100644
> --- a/gcc/config/aarch64/aarch64-sve2.md
> +++ b/gcc/config/aarch64/aarch64-sve2.md
> @@ -59,7 +59,6 @@
> ;; ---- [INT] Unpredicated high-part multiplication
> ;; ---- [INT] Scaled high-part multiplication
> ;; ---- [INT] General binary arithmetic that maps to unspecs
> -;; ---- [INT] Saturating binary arithmetic
> ;; ---- [INT] Saturating left shifts
> ;; ---- [FP] Non-widening bfloat16 arithmetic
> ;; ---- [FP] Clamp to minimum/maximum
> @@ -1036,9 +1035,13 @@
> ;; ---- [INT] General binary arithmetic that maps to unspecs
> ;; -------------------------------------------------------------------------
> ;; Includes:
> +;; - ADDQP
> +;; - ADDSUBP
> ;; - SHADD
> ;; - SHSUB
> ;; - SHSUBR
> +;; - SQDMULH
> +;; - SQRDMULH
> ;; - SQRSHL
> ;; - SQRSHLR
> ;; - SRHADD
> @@ -1282,21 +1285,13 @@
> (set_attr "sve_type" "sve_int_general")]
> )
>
> -;; -------------------------------------------------------------------------
> -;; ---- [INT] Saturating binary arithmetic
> -;; -------------------------------------------------------------------------
> -;; Includes:
> -;; - SQDMULH
> -;; - SQRDMULH
> -;; -------------------------------------------------------------------------
> -
Can we add a comment immediately above the pattern here, something like:
; Unpredicated binary arithmetic.
? This should make it clear how it relates to the previous patterns in this
section.
> (define_insn "@aarch64_sve_<sve_int_op><mode>"
> [(set (match_operand:SVE_FULL_I 0 "register_operand" "=w")
> (unspec:SVE_FULL_I
> [(match_operand:SVE_FULL_I 1 "register_operand" "w")
> (match_operand:SVE_FULL_I 2 "register_operand" "w")]
> SVE2_INT_BINARY))]
> - "TARGET_SVE2"
> + ""
I think we want to keep the TARGET_SVE2 condition here, following what you did
with SVE2_INT_BINARY_PAIR. Note that its definition is:
#define TARGET_SVE2 (AARCH64_HAVE_ISA (SVE2) || TARGET_STREAMING)
and it can be shown that the condition:
TARGET_SVE2 && (TARGET_SVE2p3 || TARGET_SME2p3)
is equivalent to:
TARGET_SVE2p3 || (TARGET_SME2p3 && TARGET_STREAMING)
for all valid architectural states, where the latter is the more
obviously correct condition for the new instructions, but the former is
what we end up with if you keep TARGET_SVE2 above (i.e. follow what you
did with SVE2_INT_BINARY_PAIR).
Essentially the `|| TARGET_STREAMING` part of TARGET_SVE2 is important
here, otherwise the patch as is will allow use of the instructions
outside of streaming mode with only TARGET_SME2p3 present.
> "<sve_int_op>\t%0.<Vetype>, %1.<Vetype>, %2.<Vetype>"
> )
>
> @@ -3287,6 +3282,7 @@
> ;; - ADDP
> ;; - SMAXP
> ;; - SMINP
> +;; - SUBP
> ;; - UMAXP
> ;; - UMINP
> ;; -------------------------------------------------------------------------
> diff --git a/gcc/config/aarch64/iterators.md b/gcc/config/aarch64/iterators.md
> index ae78fbe5b5bd..9ad0f59bc448 100644
> --- a/gcc/config/aarch64/iterators.md
> +++ b/gcc/config/aarch64/iterators.md
> @@ -1365,7 +1365,9 @@
> UNSPEC_PERMUTE_PRED
>
> ;; All used in aarch64-sve2.md
> + UNSPEC_ADDQP
> UNSPEC_ADDQV
> + UNSPEC_ADDSUBP
> UNSPEC_ANDQV
> UNSPEC_DUPQ
> UNSPEC_EORQV
> @@ -1395,6 +1397,7 @@
> UNSPEC_ST1_TRUNCQ
> UNSPEC_ST1Q_SCATTER
> UNSPEC_STNQ
> + UNSPEC_SUBP
> UNSPEC_UMAXQV
> UNSPEC_UMINQV
> UNSPEC_UQCVT
> @@ -4108,8 +4111,10 @@
> UNSPEC_SQXTUNT
> UNSPEC_UQXTNT])
>
> -(define_int_iterator SVE2_INT_BINARY [UNSPEC_SQDMULH
> - UNSPEC_SQRDMULH])
> +(define_int_iterator SVE2_INT_BINARY [(UNSPEC_SQDMULH "TARGET_SVE2")
> + (UNSPEC_SQRDMULH "TARGET_SVE2")
> + (UNSPEC_ADDQP "TARGET_SVE2p3_OR_SME2p3")
> + (UNSPEC_ADDSUBP
> "TARGET_SVE2p3_OR_SME2p3")])
Of course if you restore the TARGET_SVE2 condition on the pattern then there's
no need to add it in for the first two entries here.
>
> (define_int_iterator SVE2_INT_BINARY_LANE [UNSPEC_SQDMULH
> UNSPEC_SQRDMULH])
> @@ -4158,6 +4163,7 @@
> (define_int_iterator SVE2_INT_BINARY_PAIR [UNSPEC_ADDP
> UNSPEC_SMAXP
> UNSPEC_SMINP
> + (UNSPEC_SUBP
> "TARGET_SVE2p3_OR_SME2p3")
> UNSPEC_UMAXP
> UNSPEC_UMINP])
>
> @@ -5055,6 +5061,8 @@
> (UNSPEC_ADCLT "adclt")
> (UNSPEC_ADDHNB "addhnb")
> (UNSPEC_ADDHNT "addhnt")
> + (UNSPEC_ADDQP "addqp")
> + (UNSPEC_ADDSUBP "addsubp")
> (UNSPEC_ADDP "addp")
> (UNSPEC_ANDV "andv")
> (UNSPEC_ASHIFTRT_WIDE "asr")
> @@ -5164,6 +5172,7 @@
> (UNSPEC_SSUBWT "ssubwt")
> (UNSPEC_SUBHNB "subhnb")
> (UNSPEC_SUBHNT "subhnt")
> + (UNSPEC_SUBP "subp")
> (UNSPEC_SUQADD "suqadd")
> (UNSPEC_UABAL "uabal")
> (UNSPEC_UABDLB "uabdlb")
<snip>
> diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/subp_s16.c
> b/gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/subp_s16.c
> new file mode 100644
> index 000000000000..29411e82a385
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/aarch64/sve2/acle/asm/subp_s16.c
> @@ -0,0 +1,59 @@
> +/* { dg-do assemble { target aarch64_asm_sve2p3_ok } } */
> +/* { dg-do compile { target { ! aarch64_asm_sve2p3_ok } } } */
> +/* { dg-final { check-function-bodies "**" "" "-DCHECK_ASM" } } */
> +
> +#pragma GCC target "+sve2p3"
> +#include "test_sve_acle.h"
> +#ifdef STREAMING_COMPATIBLE
> +#pragma GCC target "+sme2p3"
> +#endif
> +
> +/*
> +** subp_s16_m_tied1:
> +** subp z0\.h, p0/m, z0\.h, z1\.h
> +** ret
> +*/
> +TEST_UNIFORM_Z (subp_s16_m_tied1, svint16_t,
> + z0 = svsubp_s16_m (p0, z0, z1),
> + z0 = svsubp_m (p0, z0, z1))
> +
> +/*
> +** subp_s16_m_tied2:
> +** mov (z[0-9]+)\.d, z0\.d
> +** movprfx z0, z1
> +** subp z0\.h, p0/m, z0\.h, \1\.h
> +** ret
> +*/
> +TEST_UNIFORM_Z (subp_s16_m_tied2, svint16_t,
> + z0 = svsubp_s16_m (p0, z1, z0),
> + z0 = svsubp_m (p0, z1, z0))
I'll note that this codegen is a little ugly, I've raised
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128601 to track this, but it's
clearly a pre-existing problem that shouldn't hold up this patch.
So the patch is OK with the above changes.
Thanks,
Alex
> +
> +/*
> +** subp_s16_x_tied1:
> +** subp z0\.h, p0/m, z0\.h, z1\.h
> +** ret
> +*/
> +TEST_UNIFORM_Z (subp_s16_x_tied1, svint16_t,
> + z0 = svsubp_s16_x (p0, z0, z1),
> + z0 = svsubp_x (p0, z0, z1))
> +
> +/*
> +** subp_s16_x_tied2:
> +** mov (z[0-9]+)\.d, z0\.d
> +** movprfx z0, z1
> +** subp z0\.h, p0/m, z0\.h, \1\.h
> +** ret
> +*/
> +TEST_UNIFORM_Z (subp_s16_x_tied2, svint16_t,
> + z0 = svsubp_s16_x (p0, z1, z0),
> + z0 = svsubp_x (p0, z1, z0))
> +
> +/*
> +** subp_s16_x_untied:
> +** movprfx z0, z1
> +** subp z0\.h, p0/m, z0\.h, z2\.h
> +** ret
> +*/
> +TEST_UNIFORM_Z (subp_s16_x_untied, svint16_t,
> + z0 = svsubp_s16_x (p0, z1, z2),
> + z0 = svsubp_x (p0, z1, z2))
<snip>