https://gcc.gnu.org/g:e5e17aa4e628f38ae91cafa96b6bb6eeb7472ddc

commit r17-6225-ge5e17aa4e628f38ae91cafa96b6bb6eeb7472ddc
Author: Dhruv Chawla <[email protected]>
Date:   Thu Nov 5 15:43:53 2026 +0530

    aarch64: Port NEON rounding shifts by an immediate to the pragma-based 
framework
    
    Port the following families of NEON intrinsics to the pragma-based 
framework:
    * vrshr_n
    * vrsra_n
    * vrshrd_n
    * vrsrad_n
    
    Bootstrapped and regtested on aarch64-linux-gnu.
    
    Signed-off-by: Dhruv Chawla <[email protected]>
    
    gcc/ChangeLog:
    
            * config/aarch64/aarch64-neon-builtins-base.cc (vrshr_n, vrshrq_n,
            vrshrd_n, vrsra_n, vrsraq_n, vrsrad_n): New function bases.
            * config/aarch64/aarch64-neon-builtins-base.def: Add the 
corresponding
            function group.
            * config/aarch64/aarch64-simd-builtins.def: Delete the srshr_n,
            urshr_n, srsra_n and ursra_n builtins, which no longer have any
            caller.
            * config/aarch64/arm_neon.h (vrshr_n_s16, vrshr_n_s32, vrshr_n_s64,
            vrshr_n_s8, vrshr_n_u16, vrshr_n_u32, vrshr_n_u64, vrshr_n_u8,
            vrshrd_n_s64, vrshrd_n_u64, vrshrq_n_s16, vrshrq_n_s32, 
vrshrq_n_s64,
            vrshrq_n_s8, vrshrq_n_u16, vrshrq_n_u32, vrshrq_n_u64, vrshrq_n_u8,
            vrsra_n_s16, vrsra_n_s32, vrsra_n_s64, vrsra_n_s8, vrsra_n_u16,
            vrsra_n_u32, vrsra_n_u64, vrsra_n_u8, vrsrad_n_s64, vrsrad_n_u64,
            vrsraq_n_s16, vrsraq_n_s32, vrsraq_n_s64, vrsraq_n_s8, vrsraq_n_u16,
            vrsraq_n_u32, vrsraq_n_u64, vrsraq_n_u8): Delete.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/aarch64/neon/vrshr_n.c: New test.
            * gcc.target/aarch64/arg-type-diagnostics-1.c: Update the expected
            message for a non-constant shift amount.

Diff:
---
 gcc/config/aarch64/aarch64-neon-builtins-base.cc   |   4 +
 gcc/config/aarch64/aarch64-neon-builtins-base.def  |  10 +
 gcc/config/aarch64/aarch64-simd-builtins.def       |   5 -
 gcc/config/aarch64/arm_neon.h                      | 256 ---------------------
 .../gcc.target/aarch64/arg-type-diagnostics-1.c    |   2 +-
 gcc/testsuite/gcc.target/aarch64/neon/vrshr_n.c    |  65 ++++++
 6 files changed, 80 insertions(+), 262 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-neon-builtins-base.cc 
b/gcc/config/aarch64/aarch64-neon-builtins-base.cc
index 3a0fd215b5ad..3a5aacf7a789 100644
--- a/gcc/config/aarch64/aarch64-neon-builtins-base.cc
+++ b/gcc/config/aarch64/aarch64-neon-builtins-base.cc
@@ -1643,6 +1643,10 @@ NEON_FUNCTION (vqshl,  vqshlq,  vqshlb,  vqshlh,  
vqshls,  vqshld,
 NEON_FUNCTION (vqrshl, vqrshlq, vqrshlb, vqrshlh, vqrshls, vqrshld,
               gimple_unspec_based_function, (code_for_qshl, UNSPEC_SQRSHL, 
UNSPEC_UQRSHL))
 
+// Rounding shifts by an immediate
+NEON_FUNCTION (vrshr_n, vrshrq_n, vrshrd_n, gimple_rtx_code_function, 
(code_for_aarch64_rshr_n, ASHIFTRT, LSHIFTRT))
+NEON_FUNCTION (vrsra_n, vrsraq_n, vrsrad_n, gimple_rtx_code_function, 
(code_for_aarch64_rsra_n, ASHIFTRT, LSHIFTRT))
+
 
 // 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 972fd0c75aef..b405d2da30ef 100644
--- a/gcc/config/aarch64/aarch64-neon-builtins-base.def
+++ b/gcc/config/aarch64/aarch64-neon-builtins-base.def
@@ -423,6 +423,16 @@ DEF_NEON_FUNCTION (vqrshls, s_integer,   ("s0,s0,ss0"))
 DEF_NEON_FUNCTION (vqrshld, d_integer,   ("s0,s0,ss0"))
 #undef REQUIRED_EXTENSIONS
 
+// Rounding shifts by an immediate
+#define REQUIRED_EXTENSIONS nonstreaming_only (AARCH64_FL_SIMD)
+DEF_NEON_FUNCTION (vrshr_n,  all_integer, ("D0,D0,ss32",    shift_right<1>))
+DEF_NEON_FUNCTION (vrshrq_n, all_integer, ("Q0,Q0,ss32",    shift_right<1>))
+DEF_NEON_FUNCTION (vrsra_n,  all_integer, ("D0,D0,D0,ss32", shift_right<2>))
+DEF_NEON_FUNCTION (vrsraq_n, all_integer, ("Q0,Q0,Q0,ss32", shift_right<2>))
+DEF_NEON_FUNCTION (vrshrd_n, d_integer,   ("s0,s0,ss32",    shift_right<1>))
+DEF_NEON_FUNCTION (vrsrad_n, d_integer,   ("s0,s0,s0,ss32", shift_right<2>))
+#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 119719279546..34950e82531f 100644
--- a/gcc/config/aarch64/aarch64-simd-builtins.def
+++ b/gcc/config/aarch64/aarch64-simd-builtins.def
@@ -408,11 +408,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>shr_n<mode>.  */
-  BUILTIN_VSDQ_I_DI (SHIFTIMM, srshr_n, 0, DEFAULT)
-  BUILTIN_VSDQ_I_DI (USHIFTIMM, urshr_n, 0, DEFAULT)
-  BUILTIN_VSDQ_I_DI (SHIFTACC, srsra_n, 0, DEFAULT)
-  BUILTIN_VSDQ_I_DI (USHIFTACC, ursra_n, 0, DEFAULT)
   /* Implemented by aarch64_<sur>shll_n<mode>.  */
   BUILTIN_VD_BHSI (SHIFTIMM, sshll_n, 0, DEFAULT)
   BUILTIN_VD_BHSI (USHIFTIMM, ushll_n, 0, DEFAULT)
diff --git a/gcc/config/aarch64/arm_neon.h b/gcc/config/aarch64/arm_neon.h
index 34cadd50c74e..ab05e3bd8738 100644
--- a/gcc/config/aarch64/arm_neon.h
+++ b/gcc/config/aarch64/arm_neon.h
@@ -11967,134 +11967,6 @@ vrecpxd_f64 (float64_t __a)
   return __builtin_aarch64_frecpxdf (__a);
 }
 
-/* vrshr */
-
-__extension__ extern __inline int8x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshr_n_s8 (int8x8_t __a, const int __b)
-{
-  return (int8x8_t) __builtin_aarch64_srshr_nv8qi (__a, __b);
-}
-
-__extension__ extern __inline int16x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshr_n_s16 (int16x4_t __a, const int __b)
-{
-  return (int16x4_t) __builtin_aarch64_srshr_nv4hi (__a, __b);
-}
-
-__extension__ extern __inline int32x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshr_n_s32 (int32x2_t __a, const int __b)
-{
-  return (int32x2_t) __builtin_aarch64_srshr_nv2si (__a, __b);
-}
-
-__extension__ extern __inline int64x1_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshr_n_s64 (int64x1_t __a, const int __b)
-{
-  return (int64x1_t) {__builtin_aarch64_srshr_ndi (__a[0], __b)};
-}
-
-__extension__ extern __inline uint8x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshr_n_u8 (uint8x8_t __a, const int __b)
-{
-  return __builtin_aarch64_urshr_nv8qi_uus (__a, __b);
-}
-
-__extension__ extern __inline uint16x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshr_n_u16 (uint16x4_t __a, const int __b)
-{
-  return __builtin_aarch64_urshr_nv4hi_uus (__a, __b);
-}
-
-__extension__ extern __inline uint32x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshr_n_u32 (uint32x2_t __a, const int __b)
-{
-  return __builtin_aarch64_urshr_nv2si_uus (__a, __b);
-}
-
-__extension__ extern __inline uint64x1_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshr_n_u64 (uint64x1_t __a, const int __b)
-{
-  return (uint64x1_t) {__builtin_aarch64_urshr_ndi_uus (__a[0], __b)};
-}
-
-__extension__ extern __inline int8x16_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshrq_n_s8 (int8x16_t __a, const int __b)
-{
-  return (int8x16_t) __builtin_aarch64_srshr_nv16qi (__a, __b);
-}
-
-__extension__ extern __inline int16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshrq_n_s16 (int16x8_t __a, const int __b)
-{
-  return (int16x8_t) __builtin_aarch64_srshr_nv8hi (__a, __b);
-}
-
-__extension__ extern __inline int32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshrq_n_s32 (int32x4_t __a, const int __b)
-{
-  return (int32x4_t) __builtin_aarch64_srshr_nv4si (__a, __b);
-}
-
-__extension__ extern __inline int64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshrq_n_s64 (int64x2_t __a, const int __b)
-{
-  return (int64x2_t) __builtin_aarch64_srshr_nv2di (__a, __b);
-}
-
-__extension__ extern __inline uint8x16_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshrq_n_u8 (uint8x16_t __a, const int __b)
-{
-  return __builtin_aarch64_urshr_nv16qi_uus (__a, __b);
-}
-
-__extension__ extern __inline uint16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshrq_n_u16 (uint16x8_t __a, const int __b)
-{
-  return __builtin_aarch64_urshr_nv8hi_uus (__a, __b);
-}
-
-__extension__ extern __inline uint32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshrq_n_u32 (uint32x4_t __a, const int __b)
-{
-  return __builtin_aarch64_urshr_nv4si_uus (__a, __b);
-}
-
-__extension__ extern __inline uint64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshrq_n_u64 (uint64x2_t __a, const int __b)
-{
-  return __builtin_aarch64_urshr_nv2di_uus (__a, __b);
-}
-
-__extension__ extern __inline int64_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshrd_n_s64 (int64_t __a, const int __b)
-{
-  return __builtin_aarch64_srshr_ndi (__a, __b);
-}
-
-__extension__ extern __inline uint64_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrshrd_n_u64 (uint64_t __a, const int __b)
-{
-  return __builtin_aarch64_urshr_ndi_uus (__a, __b);
-}
-
 /* vrsqrte.  */
 
 __extension__ extern __inline float32_t
@@ -12184,134 +12056,6 @@ vrsqrtsq_f64 (float64x2_t __a, float64x2_t __b)
   return __builtin_aarch64_rsqrtsv2df (__a, __b);
 }
 
-/* vrsra */
-
-__extension__ extern __inline int8x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsra_n_s8 (int8x8_t __a, int8x8_t __b, const int __c)
-{
-  return (int8x8_t) __builtin_aarch64_srsra_nv8qi (__a, __b, __c);
-}
-
-__extension__ extern __inline int16x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsra_n_s16 (int16x4_t __a, int16x4_t __b, const int __c)
-{
-  return (int16x4_t) __builtin_aarch64_srsra_nv4hi (__a, __b, __c);
-}
-
-__extension__ extern __inline int32x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsra_n_s32 (int32x2_t __a, int32x2_t __b, const int __c)
-{
-  return (int32x2_t) __builtin_aarch64_srsra_nv2si (__a, __b, __c);
-}
-
-__extension__ extern __inline int64x1_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsra_n_s64 (int64x1_t __a, int64x1_t __b, const int __c)
-{
-  return (int64x1_t) {__builtin_aarch64_srsra_ndi (__a[0], __b[0], __c)};
-}
-
-__extension__ extern __inline uint8x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsra_n_u8 (uint8x8_t __a, uint8x8_t __b, const int __c)
-{
-  return __builtin_aarch64_ursra_nv8qi_uuus (__a, __b, __c);
-}
-
-__extension__ extern __inline uint16x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsra_n_u16 (uint16x4_t __a, uint16x4_t __b, const int __c)
-{
-  return __builtin_aarch64_ursra_nv4hi_uuus (__a, __b, __c);
-}
-
-__extension__ extern __inline uint32x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsra_n_u32 (uint32x2_t __a, uint32x2_t __b, const int __c)
-{
-  return __builtin_aarch64_ursra_nv2si_uuus (__a, __b, __c);
-}
-
-__extension__ extern __inline uint64x1_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsra_n_u64 (uint64x1_t __a, uint64x1_t __b, const int __c)
-{
-  return (uint64x1_t) {__builtin_aarch64_ursra_ndi_uuus (__a[0], __b[0], __c)};
-}
-
-__extension__ extern __inline int8x16_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsraq_n_s8 (int8x16_t __a, int8x16_t __b, const int __c)
-{
-  return (int8x16_t) __builtin_aarch64_srsra_nv16qi (__a, __b, __c);
-}
-
-__extension__ extern __inline int16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsraq_n_s16 (int16x8_t __a, int16x8_t __b, const int __c)
-{
-  return (int16x8_t) __builtin_aarch64_srsra_nv8hi (__a, __b, __c);
-}
-
-__extension__ extern __inline int32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsraq_n_s32 (int32x4_t __a, int32x4_t __b, const int __c)
-{
-  return (int32x4_t) __builtin_aarch64_srsra_nv4si (__a, __b, __c);
-}
-
-__extension__ extern __inline int64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsraq_n_s64 (int64x2_t __a, int64x2_t __b, const int __c)
-{
-  return (int64x2_t) __builtin_aarch64_srsra_nv2di (__a, __b, __c);
-}
-
-__extension__ extern __inline uint8x16_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsraq_n_u8 (uint8x16_t __a, uint8x16_t __b, const int __c)
-{
-  return __builtin_aarch64_ursra_nv16qi_uuus (__a, __b, __c);
-}
-
-__extension__ extern __inline uint16x8_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsraq_n_u16 (uint16x8_t __a, uint16x8_t __b, const int __c)
-{
-  return __builtin_aarch64_ursra_nv8hi_uuus (__a, __b, __c);
-}
-
-__extension__ extern __inline uint32x4_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsraq_n_u32 (uint32x4_t __a, uint32x4_t __b, const int __c)
-{
-  return __builtin_aarch64_ursra_nv4si_uuus (__a, __b, __c);
-}
-
-__extension__ extern __inline uint64x2_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsraq_n_u64 (uint64x2_t __a, uint64x2_t __b, const int __c)
-{
-  return __builtin_aarch64_ursra_nv2di_uuus (__a, __b, __c);
-}
-
-__extension__ extern __inline int64_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsrad_n_s64 (int64_t __a, int64_t __b, const int __c)
-{
-  return __builtin_aarch64_srsra_ndi (__a, __b, __c);
-}
-
-__extension__ extern __inline uint64_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-vrsrad_n_u64 (uint64_t __a, uint64_t __b, const int __c)
-{
-  return __builtin_aarch64_ursra_ndi_uuus (__a, __b, __c);
-}
-
 /* vshl */
 
 __extension__ extern __inline int16x8_t
diff --git a/gcc/testsuite/gcc.target/aarch64/arg-type-diagnostics-1.c 
b/gcc/testsuite/gcc.target/aarch64/arg-type-diagnostics-1.c
index ad869a3bc018..c97ef85a142e 100644
--- a/gcc/testsuite/gcc.target/aarch64/arg-type-diagnostics-1.c
+++ b/gcc/testsuite/gcc.target/aarch64/arg-type-diagnostics-1.c
@@ -15,6 +15,6 @@ foo (int a)
      not in the final line (which is all that dg-error inspects). Hence,
      we have to tell dg-error to ignore the line number.  */
   result = vrsra_n_s32 (arg1, arg2, a);
-  /* { dg-error "must be a constant immediate" "" { target *-*-* } 0 } */
+  /* { dg-error "must be an integer constant expression" "" { target *-*-* } 0 
} */
   return result;
 }
diff --git a/gcc/testsuite/gcc.target/aarch64/neon/vrshr_n.c 
b/gcc/testsuite/gcc.target/aarch64/neon/vrshr_n.c
new file mode 100644
index 000000000000..6fa7213b31f7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/neon/vrshr_n.c
@@ -0,0 +1,65 @@
+/* { dg-do compile } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "arm_neon_test.h"
+
+/*
+** test_vrshr_n_s8_3:
+** srshr       v0\.8b, v0\.8b, 3
+** ret
+*/
+TEST_UNIFORM_UNARY_N (vrshr_n_s8, int8x8_t, 3)
+
+/*
+** test_vrshrq_n_u32_32:
+** urshr       v0\.4s, v0\.4s, 32
+** ret
+*/
+TEST_UNIFORM_UNARY_N (vrshrq_n_u32, uint32x4_t, 32)
+
+/*
+** test_vrshr_n_s64_64:
+** srshr       d0, d0, 64
+** ret
+*/
+TEST_UNIFORM_UNARY_N (vrshr_n_s64, int64x1_t, 64)
+
+/*
+** test_vrshr_n_u64_9:
+** urshr       d0, d0, 9
+** ret
+*/
+TEST_UNIFORM_UNARY_N (vrshr_n_u64, uint64x1_t, 9)
+
+/*
+** test_vrsraq_n_s16_5:
+** srsra       v0\.8h, v1\.8h, 5
+** ret
+*/
+TEST_UNIFORM_BINARY_N (vrsraq_n_s16, int16x8_t, 5)
+
+/*
+** test_vrsra_n_u64_9:
+** ursra       d0, d1, 9
+** ret
+*/
+TEST_UNIFORM_BINARY_N (vrsra_n_u64, uint64x1_t, 9)
+
+/*
+** test_vrshrd_n_s64_5:
+** fmov        d[0-9]+, x0
+** srshr       d[0-9]+, d[0-9]+, 5
+** fmov        x0, d[0-9]+
+** ret
+*/
+TEST_UNIFORM_UNARY_N (vrshrd_n_s64, int64_t, 5)
+
+/*
+** test_vrsrad_n_u64_5:
+** fmov        d[0-9]+, x0
+** fmov        d[0-9]+, x1
+** ursra       d[0-9]+, d[0-9]+, 5
+** fmov        x0, d[0-9]+
+** ret
+*/
+TEST_UNIFORM_BINARY_N (vrsrad_n_u64, uint64_t, 5)

Reply via email to