From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 850943858C50 for ; 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 ) id 1pC1Zy-00086R-TQ for gcc-patches@gcc.gnu.org; Sun, 01 Jan 2023 11:52:59 -0500 From: "Roger Sayle" To: "'GCC Patches'" 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 List-Id: This is a multipart message in MIME format. ------=_NextPart_000_005B_01D91E01.80BDC020 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 gcc/ChangeLog PR target/108229 * config/i386/i386-features.cc (general_scalar_chain::compute_convert_gain) : Consider the gain/cost of converting a MEM operand. Thanks in advance, Roger -- ------=_NextPart_000_005B_01D91E01.80BDC020 Content-Type: text/plain; name="patchvs2.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchvs2.txt" diff --git a/gcc/config/i386/i386-features.cc = b/gcc/config/i386/i386-features.cc=0A= index 0f59be0..f420f83 100644=0A= --- a/gcc/config/i386/i386-features.cc=0A= +++ b/gcc/config/i386/i386-features.cc=0A= @@ -567,6 +567,14 @@ general_scalar_chain::compute_convert_gain ()=0A= igain -=3D vector_const_cost (XEXP (src, 0));=0A= if (CONST_INT_P (XEXP (src, 1)))=0A= igain -=3D vector_const_cost (XEXP (src, 1));=0A= + if (MEM_P (XEXP (src, 1)))=0A= + {=0A= + if (optimize_insn_for_size_p ())=0A= + igain -=3D COSTS_N_BYTES (m =3D=3D 2 ? 3 : 5);=0A= + else=0A= + igain +=3D m * ix86_cost->int_load[2]=0A= + - ix86_cost->sse_load[sse_cost_idx];=0A= + }=0A= break;=0A= =0A= case NEG:=0A= ------=_NextPart_000_005B_01D91E01.80BDC020--