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 C331B3858D20 for ; Sun, 11 Jun 2023 16:15:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C331B3858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com 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=ROoUEVAusFULULoM5hPU/5U/B37WZI/Sckz3uxDZyn0=; b=UIf5LuxApIcqhtXjpIkXm1+iSl oMTGeEoG4sshu3X3bDeoGHDOQOo09Lw5I/zn12J3yGAjmGOMnUOCm3tb1Kke1yaDnEMML9mB1dDWy /7BoWYXsbTfxJVpq8FAvUqGuR0uEKgFE4K8+u0WQwGkrhTY7cu5xIHuJMErxg/ZTVN4KkGtaCRekz 6kq7lk3rLtw3nzA/mTQXzshcnKk32moJnh3Pq6VR7BpxThq/NDSdPegq3RP+HAvaXdJlsAfnJH7Ij y+UCIKqkkPpshzEyNM4o/+ZhLmqzS/xJeXOfaAOv/PF1+rhD1L8l/0A7r1FmkVZtaSOVjFes99IyN qvAOhulQ==; Received: from [185.62.158.67] (port=58131 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1q8Nim-0004t9-2x for gcc-patches@gcc.gnu.org; Sun, 11 Jun 2023 12:15:17 -0400 From: "Roger Sayle" To: Subject: [PATCH] Avoid duplicate vector initializations during RTL expansion. Date: Sun, 11 Jun 2023 17:15:14 +0100 Message-ID: <00af01d99c7f$e8a7a1e0$b9f6e5a0$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_00B0_01D99C88.4A6E7AE0" X-Mailer: Microsoft Outlook 16.0 Thread-Index: Admcf1AAJPGiynI9RIGbPvULbDsxEg== 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.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,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 List-Id: This is a multipart message in MIME format. ------=_NextPart_000_00B0_01D99C88.4A6E7AE0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This middle-end patch avoids some redundant RTL for vector initialization during RTL expansion. For the simple test case: typedef __int128 v1ti __attribute__ ((__vector_size__ (16))); __int128 key; v1ti foo() { return (v1ti){key}; } the middle-end currently expands: (set (reg:V1TI 85) (const_vector:V1TI [ (const_int 0) ])) (set (reg:V1TI 85) (mem/c:V1TI (symbol_ref:DI ("key")))) where we create a dead instruction that initializes the vector to zero, immediately followed by a set of the entire vector. This patch skips this zeroing instruction when the vector has only a single element. It also updates the code to indicate when we've cleared the vector, so that we don't need to initialize zero elements. Interestingly, this code is very similar to my patch from April 2006: https://gcc.gnu.org/pipermail/gcc-patches/2006-April/192861.html This patch has been tested on x86_64-pc-linux-gnu with a make bootstrap and make -k check, both with and without --target_board=unix{-m32}, with no new failures. Ok for mainline? 2023-06-11 Roger Sayle gcc/ChangeLog * expr.cc (store_constructor) : Don't bother clearing vectors with only a single element. Set CLEARED if the vector was initialized to zero. Thanks, Roger -- ------=_NextPart_000_00B0_01D99C88.4A6E7AE0 Content-Type: text/plain; name="patchvi.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchvi.txt" diff --git a/gcc/expr.cc b/gcc/expr.cc=0A= index 868fa6e..62cd8fa 100644=0A= --- a/gcc/expr.cc=0A= +++ b/gcc/expr.cc=0A= @@ -7531,8 +7531,11 @@ store_constructor (tree exp, rtx target, int = cleared, poly_int64 size,=0A= }=0A= =0A= /* Inform later passes that the old value is dead. */=0A= - if (!cleared && !vector && REG_P (target))=0A= - emit_move_insn (target, CONST0_RTX (mode));=0A= + if (!cleared && !vector && REG_P (target) && maybe_gt (n_elts, 1u))=0A= + {=0A= + emit_move_insn (target, CONST0_RTX (mode));=0A= + cleared =3D 1;=0A= + }=0A= =0A= if (MEM_P (target))=0A= alias =3D MEM_ALIAS_SET (target);=0A= ------=_NextPart_000_00B0_01D99C88.4A6E7AE0--