From patchwork Thu Sep 14 14:38:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1834270 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=NKxfJ/7M; dkim-atps=neutral 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 4Rmg234yfrz1yh0 for ; Fri, 15 Sep 2023 00:39:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7578A3857704 for ; Thu, 14 Sep 2023 14:39:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7578A3857704 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694702360; bh=pJc+Wm19WaF886i1k+6q78CobFhNp/Dc6JaGJlvYftA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NKxfJ/7MWNfihUQeoLhw6quyOSYQKY/hXPh1MjJ3PieUiQq0w9WKnwprCfJnN1ij1 EbW5jyYN9FDpwfU+9DLNHThnFKnGXOuUBX1s3RV3PATTn2iFkQnMR+SkObO498Nl0C 4fosh7/zN1GUbEDWprkkabGyV5SitBZQQQ/mSubQ= 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 BF6DA3858CDA for ; Thu, 14 Sep 2023 14:39:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF6DA3858CDA 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 83D291FB for ; Thu, 14 Sep 2023 07:39:37 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EC5A73F738 for ; Thu, 14 Sep 2023 07:38:59 -0700 (PDT) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH] aarch64: Restore SVE WHILE costing Date: Thu, 14 Sep 2023 15:38:58 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-24.9 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 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: , X-Patchwork-Original-From: Richard Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" AArch64 previously costed WHILELO instructions on the first call to add_stmt_cost. This was because, at the time, only add_stmt_cost had access to the loop_vec_info. However, after the AVX512 changes, we only calculate the masks later. This patch moves the WHILELO costing to finish_cost, which is in any case a more logical place for it to be. It also means that we can check the final decision about whether to use predicated loops. Tested on aarch64-linux-gnu & applied. Richard gcc/ * config/aarch64/aarch64.cc (aarch64_vector_costs::analyze_loop_info): Move WHILELO handling to... (aarch64_vector_costs::finish_cost): ...here. Check whether the vectorizer has decided to use a predicated loop. gcc/testsuite/ * gcc.target/aarch64/sve/cost_model_15.c: New test. --- gcc/config/aarch64/aarch64.cc | 36 ++++++++++--------- .../gcc.target/aarch64/sve/cost_model_15.c | 13 +++++++ 2 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/cost_model_15.c diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 3739a44bfd9..0962fc4f56e 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -16310,22 +16310,6 @@ aarch64_vector_costs::analyze_loop_vinfo (loop_vec_info loop_vinfo) /* Detect whether we're vectorizing for SVE and should apply the unrolling heuristic described above m_unrolled_advsimd_niters. */ record_potential_advsimd_unrolling (loop_vinfo); - - /* Record the issue information for any SVE WHILE instructions that the - loop needs. */ - if (!m_ops.is_empty () && !LOOP_VINFO_MASKS (loop_vinfo).is_empty ()) - { - unsigned int num_masks = 0; - rgroup_controls *rgm; - unsigned int num_vectors_m1; - FOR_EACH_VEC_ELT (LOOP_VINFO_MASKS (loop_vinfo).rgc_vec, - num_vectors_m1, rgm) - if (rgm->type) - num_masks += num_vectors_m1 + 1; - for (auto &ops : m_ops) - if (auto *issue = ops.sve_issue_info ()) - ops.pred_ops += num_masks * issue->while_pred_ops; - } } /* Implement targetm.vectorize.builtin_vectorization_cost. */ @@ -17507,9 +17491,27 @@ adjust_body_cost (loop_vec_info loop_vinfo, void aarch64_vector_costs::finish_cost (const vector_costs *uncast_scalar_costs) { + /* Record the issue information for any SVE WHILE instructions that the + loop needs. */ + loop_vec_info loop_vinfo = dyn_cast (m_vinfo); + if (!m_ops.is_empty () + && loop_vinfo + && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)) + { + unsigned int num_masks = 0; + rgroup_controls *rgm; + unsigned int num_vectors_m1; + FOR_EACH_VEC_ELT (LOOP_VINFO_MASKS (loop_vinfo).rgc_vec, + num_vectors_m1, rgm) + if (rgm->type) + num_masks += num_vectors_m1 + 1; + for (auto &ops : m_ops) + if (auto *issue = ops.sve_issue_info ()) + ops.pred_ops += num_masks * issue->while_pred_ops; + } + auto *scalar_costs = static_cast (uncast_scalar_costs); - loop_vec_info loop_vinfo = dyn_cast (m_vinfo); if (loop_vinfo && m_vec_flags && aarch64_use_new_vector_costs_p ()) diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cost_model_15.c b/gcc/testsuite/gcc.target/aarch64/sve/cost_model_15.c new file mode 100644 index 00000000000..b9e6306bb59 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/cost_model_15.c @@ -0,0 +1,13 @@ +/* { dg-options "-Ofast -mtune=neoverse-v1" } */ + +double f(double *restrict x, double *restrict y, int *restrict z) +{ + double res = 0.0; + for (int i = 0; i < 100; ++i) + res += x[i] * y[z[i]]; + return res; +} + +/* { dg-final { scan-assembler-times {\tld1sw\tz[0-9]+\.d,} 1 } } */ +/* { dg-final { scan-assembler-times {\tld1d\tz[0-9]+\.d,} 2 } } */ +/* { dg-final { scan-assembler-times {\tfmla\tz[0-9]+\.d,} 1 } } */