From patchwork Wed May 4 20:01:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1626518 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=vhdbHk9m; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Ktnmq4NmXz9sFx for ; Thu, 5 May 2022 06:02:34 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9919E3857354 for ; Wed, 4 May 2022 20:02:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9919E3857354 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1651694551; bh=RvWG258cwClpv+ehedNL/AwJnjgmAIAEuLvf6CFA6F8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=vhdbHk9mIr4EeB0sCgKeJj2wHYWnFNDJMtw9bSsritetU6aPK6xv9iJ82gZbaZ/Pz Qifx3DmUxZJEMBf6QtJ9CJdnHwoKyb/hH4Gty41hKG4iuLdbi0LXvl2H/vlM+RWz26 8vIRPrkVMefyTaQ2doCvIYJKWrBuL4FtwFC7Fcl4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2CE343858C53 for ; Wed, 4 May 2022 20:01:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2CE343858C53 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-378-r6OalH1eNLSrZVG7k7WBWw-1; Wed, 04 May 2022 16:01:48 -0400 X-MC-Unique: r6OalH1eNLSrZVG7k7WBWw-1 Received: by mail-qt1-f198.google.com with SMTP id w2-20020ac87e82000000b002f3a6e81a56so1842860qtj.14 for ; Wed, 04 May 2022 13:01:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=RvWG258cwClpv+ehedNL/AwJnjgmAIAEuLvf6CFA6F8=; b=Jk+HeTQn8I9SDKfo1cNWiC3lKQcmZ0DkWU8r1tmKjRlsz65zVkFNfzMO+VFfd5yc29 uYfpG7BnHvIwD1ahfirODFpRePZnpN5/s2WdtqUJBWqoH9aqe+oHimsPZignGk7OJlcc fHmGwwEEK/i7EfZn3SiRt4fel5HQUWsBg+vVHlLjuw4KyfPoRrR2XcwhZXMDquIrSDTO KEwxS07vT7gIJrd892eQ1YE+bq5Q17qGXHbiFC+4abeL3ayv4XAa3cIN2T60+6cWxK4g RyZXvdWAR2M/R2uQfHHY/C/68R5cJSRYZkOx9szQzBPp2bop9Y3g/kMmDRWLsR8lSg4M yvHw== X-Gm-Message-State: AOAM533VP+4/oY4Orf06aSgMmv9/Fjk3GcEULcLgXMjpG96jJlC5ha4b 9NYqTTuJbRRfgAX7T5Q944E0StZbmj4FTrn9zJTodTxD40nXtNgauDaeLyt4TZiCpUVRz929AJu orZoDFan1Ry5LrBKmMY8CebL5ndXF8GIYU5FcfayMJuyQTxNjcyrkbLT0cTjgxPr2Zw== X-Received: by 2002:a05:622a:4c7:b0:2f3:64bd:d8be with SMTP id q7-20020a05622a04c700b002f364bdd8bemr21132001qtx.0.1651694507952; Wed, 04 May 2022 13:01:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyioEvB4Q4iFLdfOc9FKwzqCGp13cg+gVEp/CjnclaogvEjXLRg3EXhljEIzgWbXhOaLyUwMA== X-Received: by 2002:a05:622a:4c7:b0:2f3:64bd:d8be with SMTP id q7-20020a05622a04c700b002f364bdd8bemr21131964qtx.0.1651694507516; Wed, 04 May 2022 13:01:47 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id s15-20020a05620a030f00b0069fc13ce254sm7664715qkm.133.2022.05.04.13.01.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 13:01:46 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: optimize reshape_init Date: Wed, 4 May 2022 16:01:44 -0400 Message-Id: <20220504200144.2678058-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" If the index of a constructor_elt is a FIELD_DECL, the CONSTRUCTOR is already reshaped, so we can save time and memory by returning immediately. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog: * decl.cc (reshape_init): Shortcut already-reshaped init. (reshape_init_class): Assert not getting one here. --- gcc/cp/decl.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) base-commit: c2e846b539bb932d7f68f7e6b3e401c361cc3bf3 diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index c9110db796a..0fa758ff214 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -6631,7 +6631,9 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p, if (TREE_CODE (d->cur->index) == FIELD_DECL) { - /* We already reshaped this. */ + /* We already reshaped this; we should have returned early from + reshape_init. */ + gcc_checking_assert (false); if (field != d->cur->index) { if (tree id = DECL_NAME (d->cur->index)) @@ -7068,6 +7070,10 @@ reshape_init (tree type, tree init, tsubst_flags_t complain) if (vec_safe_is_empty (v)) return init; + if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL) + /* Already reshaped. */ + return init; + /* Brace elision is not performed for a CONSTRUCTOR representing parenthesized aggregate initialization. */ if (CONSTRUCTOR_IS_PAREN_INIT (init))