public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Christophe Lyon <clyon@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/clyon/heads/mve-autovec)] arm: Implement MVE predicates as vectors of booleans
Date: Fri,  1 Oct 2021 14:37:29 +0000 (GMT)	[thread overview]
Message-ID: <20211001143729.55B803857811@sourceware.org> (raw)

https://gcc.gnu.org/g:5abd0f02ff4a881e427c8533f23eb586026a8a3a

commit 5abd0f02ff4a881e427c8533f23eb586026a8a3a
Author: Christophe Lyon <christophe.lyon@foss.st.com>
Date:   Mon Aug 30 17:07:08 2021 +0000

    arm: Implement MVE predicates as vectors of booleans
    
    This patch implements support for vectors of booleans to support MVE
    predicates, instead of HImode.  Since the ABI mandates pred16_t (aka
    uint16_t) to represent predicates in intrinsics prototypes, we
    introduce a new "predicate" type qualifier so that we can map relevant
    builtins HImode arguments and return value to the appropriate vector
    of booleans (VxBI).
    
    We have to update test_vector_ops_duplicate, because it iterates using
    an offset in bytes, where we would need to iterate in bits: we stop
    iterating when we reach the end of the vector of booleans.
    
    2021-09-01  Christophe Lyon  <christophe.lyon@foss.st.com>
    
            gcc/
            PR target/100757
            PR target/101325
            * config/arm/arm-builtins.c (arm_type_qualifiers): Add qualifier_predicate.
            (arm_init_simd_builtin_types): Add new simd types.
            (arm_init_builtin): Map predicate vectors arguments to HImode.
            (arm_expand_builtin_args): Move HImode predicate arguments to VxBI
            rtx. Move return value to HImode rtx.
            * config/arm/arm-modes.def (V16BI, V8BI, V4BI): New modes.
            * config/arm/arm-simd-builtin-types.def (Pred1x16_t,
            Pred2x8_t,Pred4x4_t): New.
            * simplify-rtx.c (test_vector_ops_duplicate): Avoid going past the
            end of the test vector.

Diff:
---
 gcc/config/arm/arm-builtins.c             | 28 +++++++++++++++++++++++++++-
 gcc/config/arm/arm-modes.def              |  5 +++++
 gcc/config/arm/arm-simd-builtin-types.def |  4 ++++
 gcc/simplify-rtx.c                        |  7 +++++++
 4 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/gcc/config/arm/arm-builtins.c b/gcc/config/arm/arm-builtins.c
index 3a9ff8f26b8..771759f0cdd 100644
--- a/gcc/config/arm/arm-builtins.c
+++ b/gcc/config/arm/arm-builtins.c
@@ -92,7 +92,9 @@ enum arm_type_qualifiers
   qualifier_lane_pair_index = 0x1000,
   /* Lane indices selected in quadtuplets - must be within range of previous
      argument = a vector.  */
-  qualifier_lane_quadtup_index = 0x2000
+  qualifier_lane_quadtup_index = 0x2000,
+  /* MVE vector predicates.  */
+  qualifier_predicate = 0x4000
 };
 
 /*  The qualifier_internal allows generation of a unary builtin from
@@ -1633,6 +1635,13 @@ arm_init_simd_builtin_types (void)
   arm_simd_types[Bfloat16x4_t].eltype = arm_bf16_type_node;
   arm_simd_types[Bfloat16x8_t].eltype = arm_bf16_type_node;
 
+  if (TARGET_HAVE_MVE)
+    {
+      arm_simd_types[Pred1x16_t].eltype = unsigned_intHI_type_node;
+      arm_simd_types[Pred2x8_t].eltype = unsigned_intHI_type_node;
+      arm_simd_types[Pred4x4_t].eltype = unsigned_intHI_type_node;
+    }
+
   for (i = 0; i < nelts; i++)
     {
       tree eltype = arm_simd_types[i].eltype;
@@ -1780,6 +1789,11 @@ arm_init_builtin (unsigned int fcode, arm_builtin_datum *d,
       if (qualifiers & qualifier_map_mode)
 	op_mode = d->mode;
 
+      /* MVE Predicates use HImode as mandated by the ABI: pred16_t is unsigned
+	 short.  */
+      if (qualifiers & qualifier_predicate)
+	op_mode = HImode;
+
       /* For pointers, we want a pointer to the basic type
 	 of the vector.  */
       if (qualifiers & qualifier_pointer && VECTOR_MODE_P (op_mode))
@@ -3024,6 +3038,11 @@ arm_expand_builtin_args (rtx target, machine_mode map_mode, int fcode,
 	    case ARG_BUILTIN_COPY_TO_REG:
 	      if (POINTER_TYPE_P (TREE_TYPE (arg[argc])))
 		op[argc] = convert_memory_address (Pmode, op[argc]);
+
+	      /* MVE uses mve_pred16_t (aka HImode) for vectors of predicates.  */
+	      if (GET_MODE_CLASS (mode[argc]) == MODE_VECTOR_BOOL)
+		op[argc] = gen_lowpart (mode[argc], op[argc]);
+
 	      /*gcc_assert (GET_MODE (op[argc]) == mode[argc]); */
 	      if (!(*insn_data[icode].operand[opno].predicate)
 		  (op[argc], mode[argc]))
@@ -3229,6 +3248,13 @@ constant_arg:
   else
     emit_insn (insn);
 
+  if (GET_MODE_CLASS (tmode) == MODE_VECTOR_BOOL)
+    {
+      rtx HItarget = gen_reg_rtx (HImode);
+      emit_move_insn (HItarget, gen_lowpart (HImode, target));
+      return HItarget;
+    }
+
   return target;
 }
 
diff --git a/gcc/config/arm/arm-modes.def b/gcc/config/arm/arm-modes.def
index a5e74ba3943..b414a709a62 100644
--- a/gcc/config/arm/arm-modes.def
+++ b/gcc/config/arm/arm-modes.def
@@ -84,6 +84,11 @@ VECTOR_MODE (FLOAT, BF, 2);   /*                 V2BF.  */
 VECTOR_MODE (FLOAT, BF, 4);   /*		 V4BF.  */
 VECTOR_MODE (FLOAT, BF, 8);   /*		 V8BF.  */
 
+/* Predicates for MVE.  */
+VECTOR_BOOL_MODE (V16BI, 16, 2);
+VECTOR_BOOL_MODE (V8BI, 8, 2);
+VECTOR_BOOL_MODE (V4BI, 4, 2);
+
 /* Fraction and accumulator vector modes.  */
 VECTOR_MODES (FRACT, 4);      /* V4QQ  V2HQ */
 VECTOR_MODES (UFRACT, 4);     /* V4UQQ V2UHQ */
diff --git a/gcc/config/arm/arm-simd-builtin-types.def b/gcc/config/arm/arm-simd-builtin-types.def
index c19a1b6e3eb..d3987985b4c 100644
--- a/gcc/config/arm/arm-simd-builtin-types.def
+++ b/gcc/config/arm/arm-simd-builtin-types.def
@@ -51,3 +51,7 @@
   ENTRY (Bfloat16x2_t, V2BF, none, 32, bfloat16, 20)
   ENTRY (Bfloat16x4_t, V4BF, none, 64, bfloat16, 20)
   ENTRY (Bfloat16x8_t, V8BF, none, 128, bfloat16, 20)
+
+  ENTRY (Pred1x16_t, V16BI, unsigned, 16, uint16, 21)
+  ENTRY (Pred2x8_t, V8BI, unsigned, 8, uint16, 21)
+  ENTRY (Pred4x4_t, V4BI, unsigned, 4, uint16, 21)
diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index a719f57870f..1453f984f99 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -7642,6 +7642,13 @@ test_vector_ops_duplicate (machine_mode mode, rtx scalar_reg)
 	  rtx mask = GEN_INT ((HOST_WIDE_INT_1U << i) | (i + 1));
 	  rtx vm = gen_rtx_VEC_MERGE (mode, duplicate, vector_reg, mask);
 	  poly_uint64 offset = i * GET_MODE_SIZE (inner_mode);
+
+	  /* OFFSET is in bytes, so stop testing when we go past the end of a
+	     vector of booleans, where we would need an offset in bits.  */
+	  if ((GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL)
+	      && (maybe_ge (offset, GET_MODE_SIZE (mode))))
+	    break;
+
 	  ASSERT_RTX_EQ (scalar_reg,
 			 simplify_gen_subreg (inner_mode, vm,
 					      mode, offset));


             reply	other threads:[~2021-10-01 14:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01 14:37 Christophe Lyon [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-02-22  9:08 Christophe Lyon
2022-01-12  8:27 Christophe Lyon
2021-11-16 14:06 Christophe Lyon
2021-09-29  7:30 Christophe Lyon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211001143729.55B803857811@sourceware.org \
    --to=clyon@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).