From patchwork Sun Jun 11 16:15:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 106126 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2114393vqr; Sun, 11 Jun 2023 09:15:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47N74qAVpKWA8krEgctJ4+GF8lvd+E1rU72bG+V5mUiIOYWHanQDHxm8+AaG5VkOcNT5oK X-Received: by 2002:a17:907:7f1e:b0:96f:f56a:e9be with SMTP id qf30-20020a1709077f1e00b0096ff56ae9bemr7919398ejc.8.1686500150504; Sun, 11 Jun 2023 09:15:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686500150; cv=none; d=google.com; s=arc-20160816; b=rIcoiThODmcQe291UVzmrNsnSntyLYvxNShSHSQlKDeSkLFswD8E0zfxa5hmDx3oLe o325aiMPv/E+6iCxaItv2JRf/aAdVnsJ1kER93vzHG4Bn1OtgHaoyqPrgBYwE7SUyv4d h4YoeUG65oUl6v4GQlq3UKsI1479dXkA/FQZ4bMRtJ9ptJUpXe0mfIJY5+MRnCuBKdWX dQp1gar2AkklBvQBr1w2M57v6jJZc6nC24RP9nxGjiErnSnwvAaIwXnCvmfITyIGTzeA HjnQ8wsW/oW/yJZKkwqSNfXr9L2oVBCB3L1abYxtGk2XYzMBvK8zT5LnVJZfu+wvJLja LPPQ== 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 :dmarc-filter:delivered-to; bh=ROoUEVAusFULULoM5hPU/5U/B37WZI/Sckz3uxDZyn0=; b=dgizgf2SoDm6adB+qXLgvoZIIqftCBU2p7+iaXp07r4y6USZfQbwgFdtw/+VS+MeJG Xg7DbBDQv0hIjULOM7Y67nW2l/ny4ihKxE/f/YSlQlmvkimvaH967iT0agtcOobA/nJ3 hBl6Ih/SIP+jz9n0UU3d3qAvSqTur5ktBOxzgYb5mHdH66JnG/mPBU4TESpdm6F5G4d9 d0Oxt5gq0TAGxYkqwWbETQ9JNyOgJqV2MVWP4cUjIsF8355fP9qpr6fyXaq8gYpX5jLt SjLSV84lhHGNZKmGNqw0Xzp4CRzIDmeyUS14NspR0a+82MvJchi+EkUtw22sF7MbDN1x YJ7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=UIf5LuxA; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i9-20020a170906114900b009741a0d8329si3909041eja.178.2023.06.11.09.15.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 09:15:50 -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=fail header.i=@nextmovesoftware.com header.s=default header.b=UIf5LuxA; 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 E513D3857709 for ; Sun, 11 Jun 2023 16:15:41 +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 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768423581968023118?= X-GMAIL-MSGID: =?utf-8?q?1768423581968023118?= 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 diff --git a/gcc/expr.cc b/gcc/expr.cc index 868fa6e..62cd8fa 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -7531,8 +7531,11 @@ store_constructor (tree exp, rtx target, int cleared, poly_int64 size, } /* Inform later passes that the old value is dead. */ - if (!cleared && !vector && REG_P (target)) - emit_move_insn (target, CONST0_RTX (mode)); + if (!cleared && !vector && REG_P (target) && maybe_gt (n_elts, 1u)) + { + emit_move_insn (target, CONST0_RTX (mode)); + cleared = 1; + } if (MEM_P (target)) alias = MEM_ALIAS_SET (target);