public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Andre Simoes Dias Vieira <avieira@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-10165] veclower: improve selection of vector mode when lowering [PR 112787] Date: Mon, 19 Feb 2024 16:46:48 +0000 (GMT) [thread overview] Message-ID: <20240219164648.709173858D20@sourceware.org> (raw) 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));
reply other threads:[~2024-02-19 16:46 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20240219164648.709173858D20@sourceware.org \ --to=avieira@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: linkBe 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).