https://gcc.gnu.org/g:04a69e68bb4c6334595f0e7da837ea0944ae0dcd

commit r17-6229-g04a69e68bb4c6334595f0e7da837ea0944ae0dcd
Author: Dhruv Chawla <[email protected]>
Date:   Thu Nov 5 15:43:57 2026 +0530

    aarch64: Port NEON widening shifts by an immediate to the pragma-based 
framework
    
    Port the following families of NEON intrinsics to the pragma-based 
framework:
    * vshll_n
    * vshll_high_n
    
    Bootstrapped and regtested on aarch64-linux-gnu.
    
    Signed-off-by: Dhruv Chawla <[email protected]>
    
    gcc/ChangeLog:
    
            * config/aarch64/aarch64-builtins.cc
            (aarch64_types_unsigned_shift_qualifiers, TYPES_USHIFTIMM): Delete.
            * config/aarch64/aarch64-neon-builtins-base.cc (vshll_n, 
vshll_high_n):
            New function bases.
            * config/aarch64/aarch64-neon-builtins-base.def: Add the 
corresponding
            function group.
            * config/aarch64/aarch64-simd-builtins.def: Delete the sshll_n,
            ushll_n, sshll2_n and ushll2_n builtins, which no longer have any
            caller.
            * config/aarch64/arm_neon.h (vshll_high_n_s16, vshll_high_n_s32,
            vshll_high_n_s8, vshll_high_n_u16, vshll_high_n_u32, 
vshll_high_n_u8,
            vshll_n_s16, vshll_n_s32, vshll_n_s8, vshll_n_u16, vshll_n_u32,
            vshll_n_u8): Delete.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/aarch64/neon/vshll_n.c: New test.
            * gcc.target/aarch64/neon/shift_imm_range.c: Likewise.

Diff:
---
 gcc/config/aarch64/aarch64-builtins.cc             |  4 -
 gcc/config/aarch64/aarch64-neon-builtins-base.cc   |  3 +
 gcc/config/aarch64/aarch64-neon-builtins-base.def  |  6 ++
 gcc/config/aarch64/aarch64-simd-builtins.def       |  6 --
 gcc/config/aarch64/arm_neon.h                      | 86 ----------------------
 .../gcc.target/aarch64/neon/shift_imm_range.c      | 48 ++++++++++++
 gcc/testsuite/gcc.target/aarch64/neon/vshll_n.c    | 39 ++++++++++
 7 files changed, 96 insertions(+), 96 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-builtins.cc 
b/gcc/config/aarch64/aarch64-builtins.cc
index 87e588d19fee..840963be8dab 100644
--- a/gcc/config/aarch64/aarch64-builtins.cc
+++ b/gcc/config/aarch64/aarch64-builtins.cc
@@ -344,10 +344,6 @@ static enum aarch64_type_qualifiers
 aarch64_types_fcvt_from_unsigned_qualifiers[SIMD_MAX_BUILTIN_ARGS]
   = { qualifier_none, qualifier_unsigned, qualifier_immediate };
 #define TYPES_FCVTIMM_SUS (aarch64_types_fcvt_from_unsigned_qualifiers)
-static enum aarch64_type_qualifiers
-aarch64_types_unsigned_shift_qualifiers[SIMD_MAX_BUILTIN_ARGS]
-  = { qualifier_unsigned, qualifier_unsigned, qualifier_immediate };
-#define TYPES_USHIFTIMM (aarch64_types_unsigned_shift_qualifiers)
 
 static enum aarch64_type_qualifiers
 aarch64_types_load1_qualifiers[SIMD_MAX_BUILTIN_ARGS]
diff --git a/gcc/config/aarch64/aarch64-neon-builtins-base.cc 
b/gcc/config/aarch64/aarch64-neon-builtins-base.cc
index cdd46dbeb863..e57015d52df9 100644
--- a/gcc/config/aarch64/aarch64-neon-builtins-base.cc
+++ b/gcc/config/aarch64/aarch64-neon-builtins-base.cc
@@ -1701,6 +1701,9 @@ NEON_FUNCTION (vqrshrun_n, vqrshrunh_n, vqrshruns_n, 
vqrshrund_n,
 NEON_FUNCTION (vqshrun_high_n,  gimple_code_for_mode_function, 
(code_for_aarch64_sqshrun2_n, 1))
 NEON_FUNCTION (vqrshrun_high_n, gimple_code_for_mode_function, 
(code_for_aarch64_sqrshrun2_n, 1))
 
+// Widening shifts by an immediate
+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))
 
 // Bitwise operations
 NEON_FUNCTION (vand,  vandq,  gimple_expr,    (BIT_AND_EXPR))
diff --git a/gcc/config/aarch64/aarch64-neon-builtins-base.def 
b/gcc/config/aarch64/aarch64-neon-builtins-base.def
index 2684ae281799..981e101cfdb2 100644
--- a/gcc/config/aarch64/aarch64-neon-builtins-base.def
+++ b/gcc/config/aarch64/aarch64-neon-builtins-base.def
@@ -491,6 +491,12 @@ DEF_NEON_FUNCTION (vqrshruns_n,     s_signed,    
("shu0,s0,ss32",      shift_rig
 DEF_NEON_FUNCTION (vqrshrund_n,     d_signed,    ("shu0,s0,ss32",      
shift_right_narrow<1>))
 #undef REQUIRED_EXTENSIONS
 
+// Widening shifts by an immediate
+#define REQUIRED_EXTENSIONS nonstreaming_only (AARCH64_FL_SIMD)
+DEF_NEON_FUNCTION (vshll_n,      bhs_integer, ("Qd0,D0,ss32", 
shift_left_long<1>))
+DEF_NEON_FUNCTION (vshll_high_n, bhs_integer, ("Qd0,Q0,ss32", 
shift_left_long<1>))
+#undef REQUIRED_EXTENSIONS
+
 // Bitwise operations (FEAT_SHA3)
 #define REQUIRED_EXTENSIONS nonstreaming_only (AARCH64_FL_SHA3)
 DEF_NEON_FUNCTION (vbcaxq, all_integer, ("Q0,Q0,Q0,Q0"))
diff --git a/gcc/config/aarch64/aarch64-simd-builtins.def 
b/gcc/config/aarch64/aarch64-simd-builtins.def
index c7c9ac4466b3..0288c4c3e482 100644
--- a/gcc/config/aarch64/aarch64-simd-builtins.def
+++ b/gcc/config/aarch64/aarch64-simd-builtins.def
@@ -396,12 +396,6 @@
   BUILTIN_VQ_HSF (QUADOP_LANE_PAIR, fcmlaq_lane90, 0, FP)
   BUILTIN_VQ_HSF (QUADOP_LANE_PAIR, fcmlaq_lane180, 0, FP)
   BUILTIN_VQ_HSF (QUADOP_LANE_PAIR, fcmlaq_lane270, 0, FP)
-  /* Implemented by aarch64_<sur>shll_n<mode>.  */
-  BUILTIN_VD_BHSI (SHIFTIMM, sshll_n, 0, DEFAULT)
-  BUILTIN_VD_BHSI (USHIFTIMM, ushll_n, 0, DEFAULT)
-  /* Implemented by aarch64_<sur>shll2_n<mode>.  */
-  BUILTIN_VQW (SHIFTIMM, sshll2_n, 0, DEFAULT)
-  BUILTIN_VQW (SHIFTIMM, ushll2_n, 0, DEFAULT)
 
   /* Implemented by aarch64_xtn2<mode>.  */
   BUILTIN_VQN (BINOP, xtn2, 0, DEFAULT)
diff --git a/gcc/config/aarch64/arm_neon.h b/gcc/config/aarch64/arm_neon.h
index 24213304be03..94aca0706c77 100644
--- a/gcc/config/aarch64/arm_neon.h
+++ b/gcc/config/aarch64/arm_neon.h
@@ -11176,92 +11176,6 @@ vrsqrtsq_f64 (float64x2_t __a, float64x2_t __b)
   return __builtin_aarch64_rsqrtsv2df (__a, __b);
 }
 
-/* vshl */
-
-__extension__ extern __inline int16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vshll_high_n_s8 (int8x16_t __a, const int __b)
-{
-  return __builtin_aarch64_sshll2_nv16qi (__a, __b);
-}
-
-__extension__ extern __inline int32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vshll_high_n_s16 (int16x8_t __a, const int __b)
-{
-  return __builtin_aarch64_sshll2_nv8hi (__a, __b);
-}
-
-__extension__ extern __inline int64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vshll_high_n_s32 (int32x4_t __a, const int __b)
-{
-  return __builtin_aarch64_sshll2_nv4si (__a, __b);
-}
-
-__extension__ extern __inline uint16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vshll_high_n_u8 (uint8x16_t __a, const int __b)
-{
-  return (uint16x8_t) __builtin_aarch64_ushll2_nv16qi ((int8x16_t) __a, __b);
-}
-
-__extension__ extern __inline uint32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vshll_high_n_u16 (uint16x8_t __a, const int __b)
-{
-  return (uint32x4_t) __builtin_aarch64_ushll2_nv8hi ((int16x8_t) __a, __b);
-}
-
-__extension__ extern __inline uint64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vshll_high_n_u32 (uint32x4_t __a, const int __b)
-{
-  return (uint64x2_t) __builtin_aarch64_ushll2_nv4si ((int32x4_t) __a, __b);
-}
-
-__extension__ extern __inline int16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vshll_n_s8 (int8x8_t __a, const int __b)
-{
-  return __builtin_aarch64_sshll_nv8qi (__a, __b);
-}
-
-__extension__ extern __inline int32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vshll_n_s16 (int16x4_t __a, const int __b)
-{
-  return __builtin_aarch64_sshll_nv4hi (__a, __b);
-}
-
-__extension__ extern __inline int64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vshll_n_s32 (int32x2_t __a, const int __b)
-{
-  return __builtin_aarch64_sshll_nv2si (__a, __b);
-}
-
-__extension__ extern __inline uint16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vshll_n_u8 (uint8x8_t __a, const int __b)
-{
-  return __builtin_aarch64_ushll_nv8qi_uus (__a, __b);
-}
-
-__extension__ extern __inline uint32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vshll_n_u16 (uint16x4_t __a, const int __b)
-{
-  return __builtin_aarch64_ushll_nv4hi_uus (__a, __b);
-}
-
-__extension__ extern __inline uint64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vshll_n_u32 (uint32x2_t __a, const int __b)
-{
-  return __builtin_aarch64_ushll_nv2si_uus (__a, __b);
-}
-
 /* vsqadd */
 
 __extension__ extern __inline uint8x8_t
diff --git a/gcc/testsuite/gcc.target/aarch64/neon/shift_imm_range.c 
b/gcc/testsuite/gcc.target/aarch64/neon/shift_imm_range.c
new file mode 100644
index 000000000000..c41bb56b4a7e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/neon/shift_imm_range.c
@@ -0,0 +1,48 @@
+/* { dg-do compile } */
+
+#include "arm_neon_test.h"
+
+void
+test_left (int8x8_t a, int16x8_t b)
+{
+  /* Left shifts take 0 to one less than the element width.  */
+  vshl_n_s8 (a, 0);
+  vshl_n_s8 (a, 7);
+  vshl_n_s8 (a, 8); /* { dg-error {passing 8 to argument 2 of 'vshl_n_s8', 
which expects a value in the range \[0, 7\]} } */
+  vqshl_n_s8 (a, 8); /* { dg-error {passing 8 to argument 2 of 'vqshl_n_s8', 
which expects a value in the range \[0, 7\]} } */
+  vqshlu_n_s8 (a, 8); /* { dg-error {passing 8 to argument 2 of 'vqshlu_n_s8', 
which expects a value in the range \[0, 7\]} } */
+  vsli_n_s8 (a, a, 8); /* { dg-error {passing 8 to argument 3 of 'vsli_n_s8', 
which expects a value in the range \[0, 7\]} } */
+}
+
+void
+test_right (int8x8_t a, int16x8_t b)
+{
+  /* Right shifts take 1 to the element width.  */
+  vshr_n_s8 (a, 1);
+  vshr_n_s8 (a, 8);
+  vshr_n_s8 (a, 0); /* { dg-error {passing 0 to argument 2 of 'vshr_n_s8', 
which expects a value in the range \[1, 8\]} } */
+  vshr_n_s8 (a, 9); /* { dg-error {passing 9 to argument 2 of 'vshr_n_s8', 
which expects a value in the range \[1, 8\]} } */
+  vrshr_n_s8 (a, 0); /* { dg-error {passing 0 to argument 2 of 'vrshr_n_s8', 
which expects a value in the range \[1, 8\]} } */
+  vsra_n_s8 (a, a, 0); /* { dg-error {passing 0 to argument 3 of 'vsra_n_s8', 
which expects a value in the range \[1, 8\]} } */
+  vsri_n_s8 (a, a, 0); /* { dg-error {passing 0 to argument 3 of 'vsri_n_s8', 
which expects a value in the range \[1, 8\]} } */
+}
+
+void
+test_narrow (int16x8_t a)
+{
+  /* Narrowing shifts take 1 to the width of the result elements, which is
+     half the width of the argument's.  */
+  vshrn_n_s16 (a, 8);
+  vshrn_n_s16 (a, 9); /* { dg-error {passing 9 to argument 2 of 'vshrn_n_s16', 
which expects a value in the range \[1, 8\]} } */
+  vqshrn_n_s16 (a, 0); /* { dg-error {passing 0 to argument 2 of 
'vqshrn_n_s16', which expects a value in the range \[1, 8\]} } */
+  vqshrun_n_s16 (a, 9); /* { dg-error {passing 9 to argument 2 of 
'vqshrun_n_s16', which expects a value in the range \[1, 8\]} } */
+}
+
+void
+test_long (int8x8_t a, int8x16_t b)
+{
+  /* Widening shifts may name the element width itself, which selects SHLL.  */
+  vshll_n_s8 (a, 8);
+  vshll_n_s8 (a, 9); /* { dg-error {passing 9 to argument 2 of 'vshll_n_s8', 
which expects a value in the range \[0, 8\]} } */
+  vshll_high_n_s8 (b, 9); /* { dg-error {passing 9 to argument 2 of 
'vshll_high_n_s8', which expects a value in the range \[0, 8\]} } */
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/neon/vshll_n.c 
b/gcc/testsuite/gcc.target/aarch64/neon/vshll_n.c
new file mode 100644
index 000000000000..ddd5a7367e36
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/neon/vshll_n.c
@@ -0,0 +1,39 @@
+/* { dg-do compile } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "arm_neon_test.h"
+
+/*
+** test_vshll_n_s8_3:
+** sshll       v0\.8h, v0\.8b, 3
+** ret
+*/
+TEST_UNARY_N (vshll_n_s8, int16x8_t, int8x8_t, 3)
+
+/*
+** test_vshll_n_u16_0:
+** uxtl        v0\.4s, v0\.4h
+** ret
+*/
+TEST_UNARY_N (vshll_n_u16, uint32x4_t, uint16x4_t, 0)
+
+/*
+** test_vshll_n_u8_8:
+** shll        v0\.8h, v0\.8b, 8
+** ret
+*/
+TEST_UNARY_N (vshll_n_u8, uint16x8_t, uint8x8_t, 8)
+
+/*
+** test_vshll_high_n_s16_5:
+** sshll2      v0\.4s, v0\.8h, 5
+** ret
+*/
+TEST_UNARY_N (vshll_high_n_s16, int32x4_t, int16x8_t, 5)
+
+/*
+** test_vshll_high_n_u32_32:
+** shll2       v0\.2d, v0\.4s, 32
+** ret
+*/
+TEST_UNARY_N (vshll_high_n_u32, uint64x2_t, uint32x4_t, 32)

Reply via email to