From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 76FED3858D35 for ; Wed, 21 Jun 2023 17:19:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 76FED3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687367969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TM2wm4ddK2r264hnTXOcjYRCXSIrsAs+piDUyggQOu8=; b=c39vXe5J/x0uLM7mpASMRApkMwnVDw5hfoiCaWX208atwIV3z8bvf1P45SdIQoAk496Xvh XmHhWUjCBKKskiwvX0txtVOHY257Z+YHpBS2fPFdyqb5zeoi9B4Lagpvx88CUiBxSumZQg x4Rs7AZBgQnSZrfoBcHCgKpJjpwTXgg= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-170-kcOYtG-fPPuqfT6iFvHtzg-1; Wed, 21 Jun 2023 13:19:24 -0400 X-MC-Unique: kcOYtG-fPPuqfT6iFvHtzg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-763ddc42580so75446985a.1 for ; Wed, 21 Jun 2023 10:19:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687367964; x=1689959964; 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=TM2wm4ddK2r264hnTXOcjYRCXSIrsAs+piDUyggQOu8=; b=TFHeCmpKbL/o2wEIphC2hjY5B+JLGhInOLrgd6hJvNKecKUquZDIL5OsmYzNVY/uWO rTudGomSqqRZPyEQ1vvcMZ+NfmR2D9smItepVMzwPFlFOYicSmehwkRZhtlpNjptyXKW izMjSKcIy0AgA9K1keMf/Zydzd9yfUXtazZGz/7mPpBc6rdXO8m3XaXMpbIuygTpRA8X rSpWFjDSElzARVmdvchw0GR/fNzZIfcn6iphbhl7nbwhnBbPj3zKe9oA/YTPWOByWrlF oIuHED2hvAaObjUBCjvXJWdDdhOZvygihnazqdcAiVAiU8OcvWqux9kabNaFDR1KBrD1 EgWw== X-Gm-Message-State: AC+VfDwQ5kEzbATTTV8GZrfG6Tew3tp+HFR2+NMHYtsG4nqxgDb1RYLw 1EaiOANu5TG4YBhjyIkgZESBOZ6Wv1F2/uz/k1EumLYRG4/tnNkTgDmJXhR1iQoz6tnR1bZjrxc JuPDYknH94uQurefMLjdhMIInkL5RpvD+QWPho2vIaKGG8zr8cOerS0t99I89wRmPZIC4vZDq3f o= X-Received: by 2002:a05:620a:3e8b:b0:760:7303:d199 with SMTP id tv11-20020a05620a3e8b00b007607303d199mr14945919qkn.21.1687367963966; Wed, 21 Jun 2023 10:19:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6BR/3aLnnf4XJ9hcGn1HRU7gCymIlcqe0yLTm8JuqEH9PzF7ohLFFhENkmldryTYthw0SkEA== X-Received: by 2002:a05:620a:3e8b:b0:760:7303:d199 with SMTP id tv11-20020a05620a3e8b00b007607303d199mr14945879qkn.21.1687367962979; Wed, 21 Jun 2023 10:19:22 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id b11-20020a05620a118b00b00762399719a5sm2414565qkk.119.2023.06.21.10.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 10:19:22 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: redundant targ coercion for var/alias tmpls Date: Wed, 21 Jun 2023 13:19:20 -0400 Message-ID: <20230621171920.1283054-1-ppalka@redhat.com> X-Mailer: git-send-email 2.41.0.113.g6640c2d06d MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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 List-Id: When stepping through the variable/alias template specialization code paths, I noticed we perform template argument coercion twice: first from instantiate_alias_template / finish_template_variable and again from tsubst_decl (during instantiate_template). It should suffice to perform coercion once. To that end patch elides this second coercion from tsubst_decl when possible. We can't get rid of it completely because we don't always specialize a variable template from finish_template_variable: we could also be doing so directly from instantiate_template during variable template partial specialization selection, in which case the coercion from tsubst_decl would be the first and only coercion. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? This reduces memory usage of range-v3's zip.cpp by ~0.5%. gcc/cp/ChangeLog: * pt.cc (tsubst_decl) : Call coercion_template_parms only if DECL_TEMPLATE_SPECIALIZATION is set. --- gcc/cp/pt.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index be86051abad..dd10409ce18 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -15232,10 +15232,17 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) argvec = tsubst (DECL_TI_ARGS (t), args, complain, in_decl); if (argvec != error_mark_node && PRIMARY_TEMPLATE_P (gen_tmpl) - && TMPL_ARGS_DEPTH (args) >= TMPL_ARGS_DEPTH (argvec)) - /* We're fully specializing a template declaration, so - we need to coerce the innermost arguments corresponding to - the template. */ + && TMPL_ARGS_DEPTH (args) >= TMPL_ARGS_DEPTH (argvec) + && DECL_TEMPLATE_SPECIALIZATION (t)) + /* We're fully specializing an alias or variable template, so + coerce the innermost arguments if necessary. We expect + instantiate_alias_template and finish_template_variable to + already have done this relative to the primary template, in + which case this coercion is unnecessary, but we can also + get here when substituting a partial variable template + specialization (directly from instantiate_template), in + which case DECL_TEMPLATE_SPECIALIZATION is set and coercion + is necessary. */ argvec = (coerce_template_parms (DECL_TEMPLATE_PARMS (gen_tmpl), argvec, tmpl, complain)); -- 2.41.0.113.g6640c2d06d