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: 139625 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp396068vqi; Thu, 14 Sep 2023 07:39:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3xfJjq0lMkn6SJgHsyqF/YEwWM9erD725kegSEXXe/JfF8W0dsShptX4smE2G7NvjQUzF X-Received: by 2002:a05:6402:6d0:b0:521:a4bb:374f with SMTP id n16-20020a05640206d000b00521a4bb374fmr5522151edy.5.1694702384513; Thu, 14 Sep 2023 07:39:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694702384; cv=none; d=google.com; s=arc-20160816; b=jtzTKlXm+R2ryvNaavhOv7+nbYUdZ5MD5NmCjIm9qIIRkro1DGZ+bqcyifngakPNnK ZwnZgCJpDdvTDR3G+cRwZs0TnDAJ+c+S040wfFSyG2SHWz6lHfivfjFRhnUsgRXLfOX9 aVdLGMm8O2Jt9UUONqM8unV1bh3fEgEl47K7ZdNz5bxd0+WEE1pdGEdQW+8HpIGZLpl4 efWk/tMMDdG+ZxponDbaJknVg5Ks33np1MbM7WdHDJfmyGQFAa0CkD48+abWp4Swpmid ewh397RdOX0576YRFDBd8GdviH7RI76LVYot76ElfXfZW59D67pT42e7zJklR+TBaQPM FiXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:message-id:date:subject:mail-followup-to:to:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=pJc+Wm19WaF886i1k+6q78CobFhNp/Dc6JaGJlvYftA=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=Wg821qJKNc6Ef6HggRjIn3Wwic7rAqsMqx3nBziwi6XAoWZBcGk2TNV9Jj7pq/L37Q sCWiz6EqGrypW8MizfyE5cyRc5+LFvOZOq6iVsWWF2leVOkCn9ELGAG/IBhQPY8LJpDF 1cUIFREwA20eA8bX/lHteWm8S2+ksLuzaYRrB04GMwz2kDDLmQgCAGKAgWdc8Jp4Wa7D ompv+YwiSPFWjWCC4VB8lzQxyvfo7PylV3rMhCROqBDan2X+I2v2L+gbjzUJVYGedVK4 yBFPy9TLnAOM7adVib7+StI5JRHdl9mzOWUP14UG40zTCVNKQ0/t/3iECYSoEgcXEFAq OKPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Dk4YOd5S; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x6-20020aa7dac6000000b0052a0565809fsi1433970eds.356.2023.09.14.07.39.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 07:39:44 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Dk4YOd5S; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6AD9C3857BA4 for ; Thu, 14 Sep 2023 14:39:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6AD9C3857BA4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694702383; 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=Dk4YOd5SnkQGAvqPrkVzY0tOGTGbu+Fe2NoJwDob6V+O/9r5nR9Gxx3jfdUKnNKfm SlbRX5R0lpY0k6VyoNM7xHf0rEpmr8k06YTLEspO9JOtW8MaviMOVzljwMUzYAjBfA pinC+k3nWyAVRaIFD5C+00CV3a1lzKWo+ujSJx88= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777024247165382807 X-GMAIL-MSGID: 1777024247165382807 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 } } */