[committed,AArch64] Add a couple of SVE ACLE comparison folds

Message ID mpt5ziyoc6l.fsf@arm.com
State New
Headers show
Series
  • [committed,AArch64] Add a couple of SVE ACLE comparison folds
Related show

Commit Message

Richard Sandiford Dec. 2, 2019, 5:43 p.m.
When writing vector-length specific SVE code, it's useful to be able
to store an svbool_t predicate in a GNU vector of unsigned chars.
This patch makes sure that there is no overhead when converting
to that form and then immediately reading it back again.

Tested on aarch64-linux-gnu and applied as r278907.

(In case this seems strange for stage 3: the SVE ACLE is a new
feature for GCC 10 and so we'd like it to be as good as we can make it.
Nothing else will be affected.)

Richard


2019-12-02  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* config/aarch64/aarch64-sve-builtins.h
	(gimple_folder::force_vector): Declare.
	* config/aarch64/aarch64-sve-builtins.cc
	(gimple_folder::force_vector): New function.
	* config/aarch64/aarch64-sve-builtins-base.cc
	(svcmp_impl::fold): Likewise.
	(svdup_impl::fold): Handle svdup_z too.

gcc/testsuite/
	* gcc.target/aarch64/sve/acle/general/eqne_dup_1.c: New test.
	* gcc.target/aarch64/sve/acle/asm/dup_f16.c (dup_0_f16_z): Expect
	the call to be folded to zero.
	* gcc.target/aarch64/sve/acle/asm/dup_f32.c (dup_0_f32_z): Likewise.
	* gcc.target/aarch64/sve/acle/asm/dup_f64.c (dup_0_f64_z): Likewise.
	* gcc.target/aarch64/sve/acle/asm/dup_s8.c (dup_0_s8_z): Likewise.
	* gcc.target/aarch64/sve/acle/asm/dup_s16.c (dup_0_s16_z): Likewise.
	* gcc.target/aarch64/sve/acle/asm/dup_s32.c (dup_0_s32_z): Likewise.
	* gcc.target/aarch64/sve/acle/asm/dup_s64.c (dup_0_s64_z): Likewise.
	* gcc.target/aarch64/sve/acle/asm/dup_u8.c (dup_0_u8_z): Likewise.
	* gcc.target/aarch64/sve/acle/asm/dup_u16.c (dup_0_u16_z): Likewise.
	* gcc.target/aarch64/sve/acle/asm/dup_u32.c (dup_0_u32_z): Likewise.
	* gcc.target/aarch64/sve/acle/asm/dup_u64.c (dup_0_u64_z): Likewise.

Patch

Index: gcc/config/aarch64/aarch64-sve-builtins.h
===================================================================
--- gcc/config/aarch64/aarch64-sve-builtins.h	2019-10-29 08:59:18.415479546 +0000
+++ gcc/config/aarch64/aarch64-sve-builtins.h	2019-12-02 17:38:33.888329008 +0000
@@ -488,6 +488,7 @@  class GTY((user)) function_instance
   gimple_folder (const function_instance &, tree,
 		 gimple_stmt_iterator *, gcall *);
 
+  tree force_vector (gimple_seq &, tree, tree);
   tree convert_pred (gimple_seq &, tree, unsigned int);
   tree fold_contiguous_base (gimple_seq &, tree);
   tree load_store_cookie (tree);
Index: gcc/config/aarch64/aarch64-sve-builtins.cc
===================================================================
--- gcc/config/aarch64/aarch64-sve-builtins.cc	2019-11-30 18:48:18.467984552 +0000
+++ gcc/config/aarch64/aarch64-sve-builtins.cc	2019-12-02 17:38:33.888329008 +0000
@@ -2234,6 +2234,17 @@  gimple_folder::gimple_folder (const func
 {
 }
 
+/* VALUE might be a vector of type VECTYPE or a single scalar element.
+   Duplicate it into a vector of type VECTYPE in the latter case, adding any
+   new statements to STMTS.  */
+tree
+gimple_folder::force_vector (gimple_seq &stmts, tree vectype, tree value)
+{
+  if (!VECTOR_TYPE_P (TREE_TYPE (value)))
+    value = gimple_build_vector_from_val (&stmts, vectype, value);
+  return value;
+}
+
 /* Convert predicate argument ARGNO so that it has the type appropriate for
    an operation on VECTYPE.  Add any new statements to STMTS.  */
 tree
Index: gcc/config/aarch64/aarch64-sve-builtins-base.cc
===================================================================
--- gcc/config/aarch64/aarch64-sve-builtins-base.cc	2019-11-16 11:26:06.891163135 +0000
+++ gcc/config/aarch64/aarch64-sve-builtins-base.cc	2019-12-02 17:38:33.888329008 +0000
@@ -333,6 +333,28 @@  public:
   CONSTEXPR svcmp_impl (tree_code code, int unspec_for_fp)
     : m_code (code), m_unspec_for_fp (unspec_for_fp) {}
 
+  gimple *
+  fold (gimple_folder &f) const OVERRIDE
+  {
+    tree pg = gimple_call_arg (f.call, 0);
+    tree rhs1 = gimple_call_arg (f.call, 1);
+    tree rhs2 = gimple_call_arg (f.call, 2);
+
+    /* Convert a ptrue-predicated integer comparison into the corresponding
+       gimple-level operation.  */
+    if (integer_all_onesp (pg)
+	&& f.type_suffix (0).element_bytes == 1
+	&& f.type_suffix (0).integer_p)
+      {
+	gimple_seq stmts = NULL;
+	rhs2 = f.force_vector (stmts, TREE_TYPE (rhs1), rhs2);
+	gsi_insert_seq_before (f.gsi, stmts, GSI_SAME_STMT);
+	return gimple_build_assign (f.lhs, m_code, rhs1, rhs2);
+      }
+
+    return NULL;
+  }
+
   rtx
   expand (function_expander &e) const OVERRIDE
   {
@@ -700,6 +722,17 @@  public:
 	  return gimple_build_assign (f.lhs, VEC_DUPLICATE_EXPR, rhs);
       }
 
+    /* svdup_z (pg, x) == VEC_COND_EXPR <pg, VEC_DUPLICATE_EXPR <x>, 0>.  */
+    if (f.pred == PRED_z)
+      {
+	gimple_seq stmts = NULL;
+	tree pred = f.convert_pred (stmts, vec_type, 0);
+	rhs = f.force_vector (stmts, vec_type, rhs);
+	gsi_insert_seq_before (f.gsi, stmts, GSI_SAME_STMT);
+	return gimple_build_assign (f.lhs, VEC_COND_EXPR, pred, rhs,
+				    build_zero_cst (vec_type));
+      }
+
     return NULL;
   }
 
Index: gcc/testsuite/gcc.target/aarch64/sve/acle/general/eqne_dup_1.c
===================================================================
--- /dev/null	2019-09-17 11:41:18.176664108 +0100
+++ gcc/testsuite/gcc.target/aarch64/sve/acle/general/eqne_dup_1.c	2019-12-02 17:38:33.900328925 +0000
@@ -0,0 +1,40 @@ 
+/* { dg-additional-options "-O" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include <arm_sve.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** cmp1:
+**	ptrue	(p[0-7])\.b(?:[^\n]*)
+**	cmple	p0\.b, \1/z, z0\.b, z1\.d
+**	ret
+*/
+svbool_t
+cmp1 (svint8_t x, svint64_t y)
+{
+  svbool_t res = svcmple_wide (svptrue_b8 (), x, y);
+  svuint8_t res_u8 = svdup_u8_z (res, 1);
+  return svcmpne (svptrue_b8 (), res_u8, 0);
+}
+
+/*
+** cmp2:
+**	ptrue	(p[0-7])\.b(?:[^\n]*)
+**	cmplt	p0\.b, \1/z, z0\.b, z1\.d
+**	ret
+*/
+svbool_t
+cmp2 (svint8_t x, svint64_t y)
+{
+  svbool_t res = svcmplt_wide (svptrue_b8 (), x, y);
+  svuint8_t res_u8 = svdup_u8_z (res, 42);
+  return svcmpeq (svptrue_b8 (), res_u8, 42);
+}
+
+#ifdef __cplusplus
+}
+#endif
Index: gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_f16.c
===================================================================
--- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_f16.c	2019-10-29 09:13:26.125442359 +0000
+++ gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_f16.c	2019-12-02 17:38:33.896328951 +0000
@@ -120,7 +120,7 @@  TEST_UNIFORM_Z (dup_1_f16_z, svfloat16_t
 
 /*
 ** dup_0_f16_z:
-**	mov	z0\.h, p0/z, #0
+**	mov	z0\.[bhsd], #0
 **	ret
 */
 TEST_UNIFORM_Z (dup_0_f16_z, svfloat16_t,
Index: gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_f32.c
===================================================================
--- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_f32.c	2019-10-29 09:13:26.125442359 +0000
+++ gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_f32.c	2019-12-02 17:38:33.896328951 +0000
@@ -118,7 +118,7 @@  TEST_UNIFORM_Z (dup_1_f32_z, svfloat32_t
 
 /*
 ** dup_0_f32_z:
-**	mov	z0\.s, p0/z, #0
+**	mov	z0\.[bhsd], #0
 **	ret
 */
 TEST_UNIFORM_Z (dup_0_f32_z, svfloat32_t,
Index: gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_f64.c
===================================================================
--- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_f64.c	2019-10-29 09:13:26.125442359 +0000
+++ gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_f64.c	2019-12-02 17:38:33.896328951 +0000
@@ -118,7 +118,7 @@  TEST_UNIFORM_Z (dup_1_f64_z, svfloat64_t
 
 /*
 ** dup_0_f64_z:
-**	mov	z0\.d, p0/z, #0
+**	mov	z0\.[bhsd], #0
 **	ret
 */
 TEST_UNIFORM_Z (dup_0_f64_z, svfloat64_t,
Index: gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_s8.c
===================================================================
--- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_s8.c	2019-10-29 09:13:26.125442359 +0000
+++ gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_s8.c	2019-12-02 17:38:33.900328925 +0000
@@ -275,7 +275,7 @@  TEST_UNIFORM_Z (dup_m128_s8_z, svint8_t,
 
 /*
 ** dup_0_s8_z:
-**	mov	z0\.b, p0/z, #0
+**	mov	z0\.[bhsd], #0
 **	ret
 */
 TEST_UNIFORM_Z (dup_0_s8_z, svint8_t,
Index: gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_s16.c
===================================================================
--- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_s16.c	2019-10-29 09:13:26.125442359 +0000
+++ gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_s16.c	2019-12-02 17:38:33.896328951 +0000
@@ -869,7 +869,7 @@  TEST_UNIFORM_Z (dup_m8000_s16_z, svint16
 
 /*
 ** dup_0_s16_z:
-**	mov	z0\.h, p0/z, #0
+**	mov	z0\.[bhsd], #0
 **	ret
 */
 TEST_UNIFORM_Z (dup_0_s16_z, svint16_t,
Index: gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_s32.c
===================================================================
--- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_s32.c	2019-10-29 09:13:26.125442359 +0000
+++ gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_s32.c	2019-12-02 17:38:33.896328951 +0000
@@ -849,7 +849,7 @@  TEST_UNIFORM_Z (dup_m8000_s32_z, svint32
 
 /*
 ** dup_0_s32_z:
-**	mov	z0\.s, p0/z, #0
+**	mov	z0\.[bhsd], #0
 **	ret
 */
 TEST_UNIFORM_Z (dup_0_s32_z, svint32_t,
Index: gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_s64.c
===================================================================
--- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_s64.c	2019-10-29 09:13:26.125442359 +0000
+++ gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_s64.c	2019-12-02 17:38:33.896328951 +0000
@@ -849,7 +849,7 @@  TEST_UNIFORM_Z (dup_m8000_s64_z, svint64
 
 /*
 ** dup_0_s64_z:
-**	mov	z0\.d, p0/z, #0
+**	mov	z0\.[bhsd], #0
 **	ret
 */
 TEST_UNIFORM_Z (dup_0_s64_z, svint64_t,
Index: gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_u8.c
===================================================================
--- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_u8.c	2019-10-29 09:13:26.125442359 +0000
+++ gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_u8.c	2019-12-02 17:38:33.900328925 +0000
@@ -275,7 +275,7 @@  TEST_UNIFORM_Z (dup_m128_u8_z, svuint8_t
 
 /*
 ** dup_0_u8_z:
-**	mov	z0\.b, p0/z, #0
+**	mov	z0\.[bhsd], #0
 **	ret
 */
 TEST_UNIFORM_Z (dup_0_u8_z, svuint8_t,
Index: gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_u16.c
===================================================================
--- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_u16.c	2019-10-29 09:13:26.125442359 +0000
+++ gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_u16.c	2019-12-02 17:38:33.900328925 +0000
@@ -869,7 +869,7 @@  TEST_UNIFORM_Z (dup_m8000_u16_z, svuint1
 
 /*
 ** dup_0_u16_z:
-**	mov	z0\.h, p0/z, #0
+**	mov	z0\.[bhsd], #0
 **	ret
 */
 TEST_UNIFORM_Z (dup_0_u16_z, svuint16_t,
Index: gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_u32.c
===================================================================
--- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_u32.c	2019-10-29 09:13:26.125442359 +0000
+++ gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_u32.c	2019-12-02 17:38:33.900328925 +0000
@@ -849,7 +849,7 @@  TEST_UNIFORM_Z (dup_m8000_u32_z, svuint3
 
 /*
 ** dup_0_u32_z:
-**	mov	z0\.s, p0/z, #0
+**	mov	z0\.[bhsd], #0
 **	ret
 */
 TEST_UNIFORM_Z (dup_0_u32_z, svuint32_t,
Index: gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_u64.c
===================================================================
--- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_u64.c	2019-10-29 09:13:26.125442359 +0000
+++ gcc/testsuite/gcc.target/aarch64/sve/acle/asm/dup_u64.c	2019-12-02 17:38:33.900328925 +0000
@@ -849,7 +849,7 @@  TEST_UNIFORM_Z (dup_m8000_u64_z, svuint6
 
 /*
 ** dup_0_u64_z:
-**	mov	z0\.d, p0/z, #0
+**	mov	z0\.[bhsd], #0
 **	ret
 */
 TEST_UNIFORM_Z (dup_0_u64_z, svuint64_t,