From patchwork Thu May 18 18:01:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1783473 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=) Authentication-Results: legolas.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=PgmqF6zu; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QMd8R0Jp4z20dX for ; Fri, 19 May 2023 04:01:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C83453864C5F for ; Thu, 18 May 2023 18:01:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C83453864C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684432900; bh=4CHCulL7tC4ToO7pFEwYYmDWiIjqyqyd7XMmh5Qcf5Q=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=PgmqF6zuWUR7xyI4uleD0RKd6TDlkmPEl/YM6RilCs2IOFZOJ1sZogmDxxnTvUve6 zZWswxHPIJ+ijWvnkUboc+6G9sqaG++ukJhAeETMbu2WIYIpiL9PjBjPvBkrLmIkp6 9rrp9v62iVcoWSS6S5tEcv4dMUOXFOlzIzfmrGD0= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 1A90D3858CDB for ; Thu, 18 May 2023 18:01:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1A90D3858CDB Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-463-Pek0cUCGOFic6UXo6I-r1g-1; Thu, 18 May 2023 14:01:18 -0400 X-MC-Unique: Pek0cUCGOFic6UXo6I-r1g-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-616731c798dso10755346d6.1 for ; Thu, 18 May 2023 11:01:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684432877; x=1687024877; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4CHCulL7tC4ToO7pFEwYYmDWiIjqyqyd7XMmh5Qcf5Q=; b=SiZJvb2IyPzWTcerp8+u6A8iv8V7LiVkCaNrf3VnO1S90y+kAgtbQyRmjqCFXSAiBF hPhJvkeM1HuH63gz2g8LDA7W6v3BdP3czCCpVZ1GCQZs8SmB7sFGSKPeRH/mW0lVXe8b LpxWf+Nxi1aWDjSPosBQ1lEdD72D1EaUzWOL2Z72Az566pG2kHXVnwMi11qQWufsbcxs oFD/3WkEBTZZsClJm60sWTtcI8aoUvO16uizMvW+8La5mehAiFQjQY1gIXBaR+CAXomO 1uHBCrvsbBKoFTjObgFa8TCfEbgEi4v6eWnY+x3K03X9WdLxL9xp36ESt8qX2RIR5K4c L+OQ== X-Gm-Message-State: AC+VfDwo3IZ8niPpNdAucglzyZScoPhoFKNnuy96GVW/4jfqyKzxG8iG ZvZxIyeXrsWsMRXPfNLIz9TJ1+Xw7FywtVnJP/mTDTOAXOflmN1LWdzQbSiR5Meri1kHBWSTkkM PbbZZGVEXfKSpw/xJGF74LiN7oh7pvvxEc7AkAl353iPGgj8f0V7IKHwP7wqUx64m2mSEUBKZU9 0= X-Received: by 2002:a05:6214:626:b0:56c:2344:a58b with SMTP id a6-20020a056214062600b0056c2344a58bmr967771qvx.12.1684432877031; Thu, 18 May 2023 11:01:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ78MEuESVSkWCRZ7MRniyHuE/FznR0foAywwonFahCm/YDW4dwpHY3EHFZfEH0aiM4egKIPFQ== X-Received: by 2002:a05:6214:626:b0:56c:2344:a58b with SMTP id a6-20020a056214062600b0056c2344a58bmr967732qvx.12.1684432876688; Thu, 18 May 2023 11:01:16 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id s10-20020ae9f70a000000b0075935a24760sm533150qkg.136.2023.05.18.11.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 11:01:16 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: simplify norm_cache manipulation Date: Thu, 18 May 2023 14:01:14 -0400 Message-ID: <20230518180114.4158415-1-ppalka@redhat.com> X-Mailer: git-send-email 2.41.0.rc0.4.g004e0f790f MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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_NONE, SPF_HELO_NONE, SPF_NONE, 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: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Avoid performing two norm_cache lookups during normalization of a concept-id by allocating inserting a norm_entry* before rather than after the fact, which is simpler and faster. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? gcc/cp/ChangeLog: * constraint.cc (normalize_concept_check): Avoid having to do two norm_cache lookups. Remove unnecessary early exit for an ill-formed concept definition. --- gcc/cp/constraint.cc | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c81e024e0e2..8cf0f2d0974 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -774,38 +774,25 @@ normalize_concept_check (tree check, tree args, norm_info info) if (!norm_cache) norm_cache = hash_table::create_ggc (31); - norm_entry entry = {tmpl, targs, NULL_TREE}; - norm_entry **slot = nullptr; - hashval_t hash = 0; - bool insert = false; + norm_entry *entry = nullptr; if (!info.generate_diagnostics ()) { /* Cache the normal form of the substituted concept-id (when not diagnosing). */ - hash = norm_hasher::hash (&entry); - slot = norm_cache->find_slot_with_hash (&entry, hash, NO_INSERT); - if (slot) + norm_entry elt = {tmpl, targs, NULL_TREE}; + norm_entry **slot = norm_cache->find_slot (&elt, INSERT); + if (*slot) return (*slot)->norm; - insert = true; + entry = ggc_alloc (); + *entry = elt; + *slot = entry; } - /* The concept may have been ill-formed. */ tree def = get_concept_definition (DECL_TEMPLATE_RESULT (tmpl)); - if (def == error_mark_node) - return error_mark_node; - info.update_context (check, args); tree norm = normalize_expression (def, targs, info); - if (insert) - { - /* Recompute SLOT since norm_cache may have been expanded during - the recursive call. */ - slot = norm_cache->find_slot_with_hash (&entry, hash, INSERT); - gcc_checking_assert (!*slot); - entry.norm = norm; - *slot = ggc_alloc (); - **slot = entry; - } + if (entry) + entry->norm = norm; return norm; }