Message ID | 005a01d91e01$80bd4af0$8237e0d0$@nextmovesoftware.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3837295wrt; Sun, 1 Jan 2023 08:53:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXsLHE0hM9e5cKmMcmTp/KnaOyVVMd+TAkHg8JzNC9FNU5h5uLYxDxGLaEo0U3uSbbasH4+U X-Received: by 2002:a17:907:c203:b0:7ad:84c7:503a with SMTP id ti3-20020a170907c20300b007ad84c7503amr31958440ejc.72.1672592008348; Sun, 01 Jan 2023 08:53:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672592008; cv=none; d=google.com; s=arc-20160816; b=TWFz20eD+h3ZZn6eCO5JU+Ich3jfOgLNwAyrH2bGCfbJVHayVyk4VSjDHmS4yX3E5H +j1G+AtP+r2a6Uz3UtT1pLxvN6r17TD63gAMRI7ADUoOLxUt1r0/enhZJ9j05ZRVhzzx PA3xnLcza84bxY9xgoy16ElBI11nsm3pZegC79LhM1zF+MMaGoCgGK0kXh4MjOjNE/r4 j2Qep+fqV5NZ5NCNyObNooIBEs22QACfpV0ZmhWCbS0IneWti2B4KHjAElWyHsYIYRXv 71TlosStSXAyFE7pvfssSffGK+St7Yfft1O+eHmERJaq3d6atAW6t0NsPnAehaHUzM63 MMdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:thread-index :mime-version:message-id:date:subject:to:from:dkim-signature :delivered-to; bh=+NrqVA2EcZEguNi3R3ZGFhG9uu/en1yOK9MQYOdEVX4=; b=CxqMykaj9xjoKyzx43H6eg8vjnHRfEAL/b0DbJo0Zyl421Pq6Sw3hrkG2YXEImEQPP DWV1IjFeADxrfHiqOf6Nw9RdoDidHXBtMmojam8JI3Fe6pAU3OZU7fRLfARUUN+ATeWE 73qFs+oblZcFnw5DkEKLvZhmom/wSAG6Mim556I2Xtz1QSUn6x9as0fN8/YYDL3itQ1X aaiI70P8OS6rj++ivXzonLOg9lBvM+uLRPiH5CxpvPRh/6d3XECjDs6W9vKZ+JAu2+lt TRWjtZSal+cAhApk1wsYgq9QjhpiAw5vyQovDBkAPrkpjMT/GtB7iiCuCRgeRTGhcUSL LjFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=lHZBM2MI; 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" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id wv1-20020a170907080100b00787abcb1ce0si25122540ejb.679.2023.01.01.08.53.28 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Jan 2023 08:53:28 -0800 (PST) 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=fail header.i=@nextmovesoftware.com header.s=default header.b=lHZBM2MI; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 094963858D1E for <ouuuleilei@gmail.com>; Sun, 1 Jan 2023 16:53:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 850943858C50 for <gcc-patches@gcc.gnu.org>; Sun, 1 Jan 2023 16:52:59 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=+NrqVA2EcZEguNi3R3ZGFhG9uu/en1yOK9MQYOdEVX4=; b=lHZBM2MIOLhSd3H+wDxDGs6xgB DPY0hWPp4APC/OT+PMiis2cVxf54bTDPp+frm6cO8Yz49T7xBw2xL5vf9kiQFpYg6ekZEQSt6Mx+W v09rnb6lSYFqJAgp2cvxwnZPc84k4hgWjGwieQDTfTzioLG30HwPj6umwWEXIRWSh8Oo61Fx9kibm N12wSJxu3G8OggiYnEXD6BGbBaElRH33D5bh1Bjn3c40e2fpe5UukeaPt2Yk5D1tCdN3HCm3JNX7s YXguINdOyeD1AAgAm7F+5GRayMf2+2dH3y/XjXTagxpmpG5w1HtNBVxjtPINCbqYqdGRuy1UmgGoI JPmVHaAA==; Received: from [185.62.158.67] (port=59343 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from <roger@nextmovesoftware.com>) id 1pC1Zy-00086R-TQ for gcc-patches@gcc.gnu.org; Sun, 01 Jan 2023 11:52:59 -0500 From: "Roger Sayle" <roger@nextmovesoftware.com> To: "'GCC Patches'" <gcc-patches@gcc.gnu.org> Subject: [x86 PATCH] PR target/108229: A minor STV compute_convert_gain tweak. Date: Sun, 1 Jan 2023 16:52:57 -0000 Message-ID: <005a01d91e01$80bd4af0$8237e0d0$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_005B_01D91E01.80BDC020" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdkeAATFzJB7nG+SSx6Iz091a+9YQg== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753839837702905389?= X-GMAIL-MSGID: =?utf-8?q?1753839837702905389?= |
Series |
[x86] PR target/108229: A minor STV compute_convert_gain tweak.
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Roger Sayle
Jan. 1, 2023, 4:52 p.m. UTC
This patch addresses PR target/108229, which is a change in code generation during the STV pass, due to the recently approved patch to handle vec_select (reductions) in the vector unit. The recent change is innocent, but exposes a latent STV "gain" calculation issue that is benign (or closely balanced) on most microarchitectures. The issue is when STV considers converting PLUS with a MEM operand. On TARGET_64BIT (m=1): addq 24(%rdi), %rdx // 4 bytes or with -m32 (m=2) addl 24(%esi), %eax // 3 bytes adcl 28(%esi), %edx // 3 bytes is being converted by STV to vmovq 24(%rdi), %xmm5 // 5 bytes vpaddq %xmm5, %xmm4, %xmm4 // 4 bytes The current code in general_scalar_chain::compute_convert_gain considers that scalar unit addition is replaced with a vector unit addition (usually about the same cost), but doesn't consider anything special about MEM operands, assuming that a scalar load gains/costs nothing compared to a vector load. We can allow the backend slightly better fine tuning by including in the gain calculation that m scalar loads are being replaced by one vector load, and when optimizing for size including that we're increasing code size (e.g. an extra vmovq instruction for a MEM operand). This patch is a win on the CSiBE benchmark when compiled with -Os. Alas I've no new testcase as this is extremely sensitive to the backend microarchitecture parameterization (and it's dangerous to select parameters from the N=1 statistics of a single bugzilla PR). This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, both with and without --target_board=unix{-m32}, with no new failures. Ok for mainline? 2023-01-01 Roger Sayle <roger@nextmovesoftware.com> gcc/ChangeLog PR target/108229 * config/i386/i386-features.cc (general_scalar_chain::compute_convert_gain) <case PLUS>: Consider the gain/cost of converting a MEM operand. Thanks in advance, Roger --
Comments
On Sun, Jan 1, 2023 at 5:53 PM Roger Sayle <roger@nextmovesoftware.com> wrote: > > > This patch addresses PR target/108229, which is a change in code > generation during the STV pass, due to the recently approved patch > to handle vec_select (reductions) in the vector unit. The recent > change is innocent, but exposes a latent STV "gain" calculation issue > that is benign (or closely balanced) on most microarchitectures. > > The issue is when STV considers converting PLUS with a MEM operand. > > On TARGET_64BIT (m=1): > addq 24(%rdi), %rdx // 4 bytes > or with -m32 (m=2) > addl 24(%esi), %eax // 3 bytes > adcl 28(%esi), %edx // 3 bytes > is being converted by STV to > vmovq 24(%rdi), %xmm5 // 5 bytes > vpaddq %xmm5, %xmm4, %xmm4 // 4 bytes > > The current code in general_scalar_chain::compute_convert_gain > considers that scalar unit addition is replaced with a vector > unit addition (usually about the same cost), but doesn't consider > anything special about MEM operands, assuming that a scalar load > gains/costs nothing compared to a vector load. We can allow the > backend slightly better fine tuning by including in the gain > calculation that m scalar loads are being replaced by one vector > load, and when optimizing for size including that we're increasing > code size (e.g. an extra vmovq instruction for a MEM operand). > > This patch is a win on the CSiBE benchmark when compiled with -Os. > Alas I've no new testcase as this is extremely sensitive to the > backend microarchitecture parameterization (and it's dangerous to > select parameters from the N=1 statistics of a single bugzilla PR). > > This patch has been tested on x86_64-pc-linux-gnu with make bootstrap > and make -k check, both with and without --target_board=unix{-m32}, > with no new failures. Ok for mainline? > > > 2023-01-01 Roger Sayle <roger@nextmovesoftware.com> > > gcc/ChangeLog > PR target/108229 > * config/i386/i386-features.cc > (general_scalar_chain::compute_convert_gain) <case PLUS>: Consider > the gain/cost of converting a MEM operand. LGTM. Thanks, Uros. > > Thanks in advance, > Roger > -- >
diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc index 0f59be0..f420f83 100644 --- a/gcc/config/i386/i386-features.cc +++ b/gcc/config/i386/i386-features.cc @@ -567,6 +567,14 @@ general_scalar_chain::compute_convert_gain () igain -= vector_const_cost (XEXP (src, 0)); if (CONST_INT_P (XEXP (src, 1))) igain -= vector_const_cost (XEXP (src, 1)); + if (MEM_P (XEXP (src, 1))) + { + if (optimize_insn_for_size_p ()) + igain -= COSTS_N_BYTES (m == 2 ? 3 : 5); + else + igain += m * ix86_cost->int_load[2] + - ix86_cost->sse_load[sse_cost_idx]; + } break; case NEG: