From patchwork Wed Dec 6 18:49:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 1872942 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SlmfY5Dp3z1yST for ; Thu, 7 Dec 2023 05:49:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 815683857BA0 for ; Wed, 6 Dec 2023 18:49:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 4C1533858D20 for ; Wed, 6 Dec 2023 18:49:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C1533858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4C1533858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701888568; cv=none; b=GHEoHGOH6YNld1xoJcqznzZVQBid8u88KPgFeF6DzHoABE8AkYgg/F9eQ+okMopueiwU55DyJogasg+2Cah92oQSc/Pd5g4fufmYpGJGMzVslKMLf+d39ZHhw47BeWeedQIe1XPqhn6KXC92Cyrp5CjimCtsxqbVDWxo3tbxE8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701888568; c=relaxed/simple; bh=qUFj7cn21KYUgVrDmEkZKIvkiSQBPhkYSDrtoZPUGso=; h=Message-ID:Date:MIME-Version:To:From:Subject; b=bxD0t9N6On+YbDABIt84eMxCSPTzFAF66D5cnYPm8V8u9XCa4ts43r/Od2f/kcJSngAF0vHq5Jc9mz1OQs9pOkvyztAC/4xnZ8XmqU2AUzDpJSjTGH9QktDdqvnxKJBw41AlLPenVB78UVIKQiE+umHLYzekKoqnnXmvejW49nQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C40851042; Wed, 6 Dec 2023 10:50:11 -0800 (PST) Received: from [10.57.74.42] (unknown [10.57.74.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 54A023F762; Wed, 6 Dec 2023 10:49:25 -0800 (PST) Message-ID: <3350dc3b-3471-453b-b631-810939609ba9@arm.com> Date: Wed, 6 Dec 2023 18:49:23 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Cc: Richard Sandiford , Richard Biener From: "Andre Vieira (lists)" Subject: veclower: improve selection of vector mode when lowering [PR 112787] X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, 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 (type_for_widest_vector_mode): Add a parameter to control maximum amount of elements in resulting vector mode. (get_compute_type): Restrict vector_compute_type to a mode no wider than the original compute type. gcc/testsuite/ChangeLog: * gcc.target/aarch64/pr112787.c: New test. Bootstrapped and regression tested on aarch64-unknown-linux-gnu and x86_64-pc-linux-gnu. Is this OK for trunk? Kind regards, Andre Vieira diff --git a/gcc/testsuite/gcc.target/aarch64/pr112787.c b/gcc/testsuite/gcc.target/aarch64/pr112787.c new file mode 100644 index 0000000000000000000000000000000000000000..caca1bf7ef447e4489b2c134d7200a4afd16763f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr112787.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O2 -march=armv8-a+sve -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 a7e6cb87a5e31e3dd2a893ea5652eeebf8d5d214..2dbf3c8f5f64f2623944110dbc371fe0944198f0 100644 --- a/gcc/tree-vect-generic.cc +++ b/gcc/tree-vect-generic.cc @@ -1347,7 +1347,7 @@ optimize_vector_constructor (gimple_stmt_iterator *gsi) TYPE, or NULL_TREE if none is found. */ static tree -type_for_widest_vector_mode (tree type, optab op) +type_for_widest_vector_mode (tree type, optab op, poly_int64 max_nunits = 0) { machine_mode inner_mode = TYPE_MODE (type); machine_mode best_mode = VOIDmode, mode; @@ -1371,7 +1371,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_eq (max_nunits, 0) + || known_lt (GET_MODE_NUNITS (mode), max_nunits))) best_mode = mode, best_nunits = GET_MODE_NUNITS (mode); if (best_mode == VOIDmode) @@ -1702,7 +1704,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 (TREE_TYPE (type), op, + TYPE_VECTOR_SUBPARTS (compute_type)); if (vector_compute_type != NULL_TREE && subparts_gt (compute_type, vector_compute_type) && maybe_ne (TYPE_VECTOR_SUBPARTS (vector_compute_type), 1U)