public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-10165] veclower: improve selection of vector mode when lowering [PR 112787]
@ 2024-02-19 16:46 Andre Simoes Dias Vieira
  0 siblings, 0 replies; only message in thread
From: Andre Simoes Dias Vieira @ 2024-02-19 16:46 UTC (permalink / raw)
  To: gcc-cvs

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

commit r12-10165-ge84c06f801fbf8376fe43719675a409f588f68bd
Author: Andre Vieira <andre.simoesdiasvieira@arm.com>
Date:   Wed Dec 20 16:41:52 2023 +0000

    veclower: improve selection of vector mode when lowering [PR 112787]
    
    This patch addresses the issue reported in PR target/112787 by improving the
    compute type selection.  We do this by not considering types with more elements
    than the type we are lowering since we'd reject such types anyway.
    
    gcc/ChangeLog:
    
            PR target/112787
            * tree-vect-generic.cc (type_for_widest_vector_mode): Change function to
            use original vector type and check widest vector mode has at most the
            same number of elements.
            (get_compute_type): Pass original vector type rather than the element
            type to type_for_widest_vector_mode and remove now obsolete check for
            the number of elements.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/aarch64/pr112787.c: New test.
    
    (cherry picked from commit a3ff76278efe006dc0b50249c8e5baf565bff56b)

Diff:
---
 gcc/testsuite/gcc.target/aarch64/pr112787.c | 11 +++++++++++
 gcc/tree-vect-generic.cc                    | 22 +++++++++++++---------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/pr112787.c b/gcc/testsuite/gcc.target/aarch64/pr112787.c
new file mode 100644
index 000000000000..8a931705f46b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr112787.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O2 -march=armv9-a -mcpu=neoverse-n2" } */
+
+typedef int __attribute__((__vector_size__ (64))) vec;
+
+vec fn (vec a, vec b)
+{
+  return a + b;
+}
+
+/* { dg-final { scan-assembler-times {add\tv[0-9]+} 4 } } */
diff --git a/gcc/tree-vect-generic.cc b/gcc/tree-vect-generic.cc
index f282e69d53bb..9a3ca26d4143 100644
--- a/gcc/tree-vect-generic.cc
+++ b/gcc/tree-vect-generic.cc
@@ -1376,12 +1376,16 @@ optimize_vector_constructor (gimple_stmt_iterator *gsi)
   gsi_replace (gsi, g, false);
 }
 \f
-/* Return a type for the widest vector mode whose components are of type
-   TYPE, or NULL_TREE if none is found.  */
+/* Return a type for the widest vector mode with the same element type as
+   type ORIGINAL_VECTOR_TYPE, with at most the same number of elements as type
+   ORIGINAL_VECTOR_TYPE and that is supported by the target for an operation
+   with optab OP, or return NULL_TREE if none is found.  */
 
 static tree
-type_for_widest_vector_mode (tree type, optab op)
+type_for_widest_vector_mode (tree original_vector_type, optab op)
 {
+  gcc_assert (VECTOR_TYPE_P (original_vector_type));
+  tree type = TREE_TYPE (original_vector_type);
   machine_mode inner_mode = TYPE_MODE (type);
   machine_mode best_mode = VOIDmode, mode;
   poly_int64 best_nunits = 0;
@@ -1404,7 +1408,9 @@ type_for_widest_vector_mode (tree type, optab op)
   FOR_EACH_MODE_FROM (mode, mode)
     if (GET_MODE_INNER (mode) == inner_mode
 	&& maybe_gt (GET_MODE_NUNITS (mode), best_nunits)
-	&& optab_handler (op, mode) != CODE_FOR_nothing)
+	&& optab_handler (op, mode) != CODE_FOR_nothing
+	&& known_le (GET_MODE_NUNITS (mode),
+		     TYPE_VECTOR_SUBPARTS (original_vector_type)))
       best_mode = mode, best_nunits = GET_MODE_NUNITS (mode);
 
   if (best_mode == VOIDmode)
@@ -1732,9 +1738,8 @@ get_compute_type (enum tree_code code, optab op, tree type)
 	  || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing))
     {
       tree vector_compute_type
-	= type_for_widest_vector_mode (TREE_TYPE (type), op);
+	= type_for_widest_vector_mode (type, op);
       if (vector_compute_type != NULL_TREE
-	  && subparts_gt (compute_type, vector_compute_type)
 	  && maybe_ne (TYPE_VECTOR_SUBPARTS (vector_compute_type), 1U)
 	  && (optab_handler (op, TYPE_MODE (vector_compute_type))
 	      != CODE_FOR_nothing))
@@ -1905,10 +1910,9 @@ expand_vector_conversion (gimple_stmt_iterator *gsi)
       /* Can't use get_compute_type here, as supportable_convert_operation
 	 doesn't necessarily use an optab and needs two arguments.  */
       tree vec_compute_type
-	= type_for_widest_vector_mode (TREE_TYPE (arg_type), mov_optab);
+	= type_for_widest_vector_mode (arg_type, mov_optab);
       if (vec_compute_type
-	  && VECTOR_MODE_P (TYPE_MODE (vec_compute_type))
-	  && subparts_gt (arg_type, vec_compute_type))
+	  && VECTOR_MODE_P (TYPE_MODE (vec_compute_type)))
 	{
 	  unsigned HOST_WIDE_INT nelts
 	    = constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_compute_type));

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-19 16:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-19 16:46 [gcc r12-10165] veclower: improve selection of vector mode when lowering [PR 112787] Andre Simoes Dias Vieira

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).