From patchwork Fri Sep 30 01:28:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp260700wrs; Thu, 29 Sep 2022 18:29:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5MTUUVilNTsm2GzBp0bUL3TJUwrgdja39LW6hgSIES81oC0wvhaI7AZJ40e/YHpGu8sVj0 X-Received: by 2002:a17:907:8a1a:b0:783:182e:aa00 with SMTP id sc26-20020a1709078a1a00b00783182eaa00mr4882627ejc.65.1664501365086; Thu, 29 Sep 2022 18:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664501365; cv=none; d=google.com; s=arc-20160816; b=cXuavSOCqQpOZTap8d8H3Sq53HhR+kEC335QB27OSiB0lrEnleubG4egr6Mo0MiVq0 PKkVMNy4BMMLiPXHZu79GR9S/N91snJTJAkltemzrpa1GnGY9X+z6S64UUuLP7ZJeEhy BQMHKF6e8fDcKzp3N2wItLG3qRMZ/VDV8or8pk+oE5ulw9aaoh4a2ihR4CTeR+Zs6iM3 gcAraJGQELUCghCnv1ab0TCNUvdc3DM8fFrneDmkkpviwui1nMITBLp6XvdRvQ/z5Jo5 3e1q5wJ79NKmk9j+vkr56Gi8YsZWK9Xg1odZPVZ2tmiJMeVmnjMwKrmQ9Nbv+FcBNqhC 9FMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=bulaeI3x+lap/h8WqJl0BxDpYR4bcJ++HQRb7e5N2VM=; b=C2q1o4mhK3qqo3ifUhDpMTnmmYZKngyCVYcsfeChdCcNy9QzDlqWEg0qiRaIBZ9t6f W3npEhi2nV/e12183QvMXo4En8/Xi7vAYZYuwsxhyH5EiCD21GB8kewLcyjA6aDWEV4+ 7SAoNS0DLqqRcc9czx4dR9r7KGcfOHbt0uxSNudz8rMrFVnV27OgN5sNdNU6zm4LOevA dlne6ltWWmdrUy/DP/sETPw6H4AUU2txoS5qmyixwPNxAxDdqvIxPWHLveHL78JPV0bg gu5m+7r6jkWbI9SFBLJsJRyNeh5zbtDONlmIN5YjOvTIAkCLECbweiIj1litq0vNuRfw toEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=e6w8zxTP; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gt18-20020a1709072d9200b007823754ecd5si921984ejc.43.2022.09.29.18.29.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 18:29:25 -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=pass header.i=@gcc.gnu.org header.s=default header.b=e6w8zxTP; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 32F2A3853802 for ; Fri, 30 Sep 2022 01:29:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32F2A3853802 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664501360; bh=bulaeI3x+lap/h8WqJl0BxDpYR4bcJ++HQRb7e5N2VM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=e6w8zxTPe+a3ryIInfnonrqvHtYkE8kAlxsTcs8eYChgdiQYRnsB40bYtfG4c27F1 FKVwxDOnvIw4+sTKJY3l6NjLHUMxqRHS/I7qlq+0geX9xNhuoQ+D5WtkYtYypCZwfQ q+cShZsaG/eTSFEMo26iMnaWULcdtxQpdqD5D5rY= 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 5F9C03858C20 for ; Fri, 30 Sep 2022 01:28:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5F9C03858C20 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-316-ETgxKMwQPxG8eIMnxCu5rg-1; Thu, 29 Sep 2022 21:28:26 -0400 X-MC-Unique: ETgxKMwQPxG8eIMnxCu5rg-1 Received: by mail-qv1-f71.google.com with SMTP id y7-20020ad45307000000b004ac7fd46495so2047266qvr.23 for ; Thu, 29 Sep 2022 18:28:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=bulaeI3x+lap/h8WqJl0BxDpYR4bcJ++HQRb7e5N2VM=; b=RUE+xz4hXT9de5WqsYVFw8gao5h3EuO6CUs1DikgiAQ6L9nFhLTB3W+/qPmIa+lkvR 0sO8hpZXp+TGzbvkNISqz1Xm7AP5QdMzB1gXbQ2PhS80lcqodDL2cn3QR4uI5UnhhcZQ T6EtwtLGyH9Zf6N7KRQa/Xj46Oimkill2Gqt3JWojkDHtBuOuFkeITwMSuVhTZhMgDuR D2sHp1kAM0/SnRsWeKXr7WsFK1ZUbt8oPB55O0GCRBDYErpidf3ejrgyugx3D4rOpeIe IrOw388aoS6QeseSKc3HZ/5sdROvC2QYxZXHuveVRpqZKGjCV8xsQKzEnwCShpzN3ym8 ACYQ== X-Gm-Message-State: ACrzQf2vnGCmTw4zCSaVQesQvKVaJhimKGXnwsfW0nAfW09tfI2nPdRG IBhSZkZ+GEBy6jygaq3udUVlKuteVkJQ9CEqBdl/qW5mNEwsgjfFQynP9rrKp470nPSwBsNt7Up 9gMvcBteWjuM4lpvD5sJ1jfbp2aQNuhLPphtLDGwxt95TkHLcTmOh/xyLDIFSFz/cXA== X-Received: by 2002:a05:6214:23ca:b0:474:8c8:4fdf with SMTP id hr10-20020a05621423ca00b0047408c84fdfmr4963450qvb.89.1664501305809; Thu, 29 Sep 2022 18:28:25 -0700 (PDT) X-Received: by 2002:a05:6214:23ca:b0:474:8c8:4fdf with SMTP id hr10-20020a05621423ca00b0047408c84fdfmr4963432qvb.89.1664501305312; Thu, 29 Sep 2022 18:28:25 -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 h17-20020a05620a245100b006ccc96c78easm1052033qkn.134.2022.09.29.18.28.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 18:28:24 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: reduce redundant TARGET_EXPR Date: Thu, 29 Sep 2022 21:28:22 -0400 Message-Id: <20220930012822.1994426-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 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 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill 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?1745356183244422502?= X-GMAIL-MSGID: =?utf-8?q?1745356183244422502?= Tested x86_64-pc-linux-gnu, applying to trunk. -- >8 -- An experiment led me to notice that in some cases we were ending up with TARGET_EXPR initialized by TARGET_EXPR, which isn't useful. The target_expr_needs_replace change won't make a difference in most cases, since cp_genericize_init will have already expanded VEC_INIT_EXPR by the time we consider it, but it is correct. gcc/cp/ChangeLog: * cp-gimplify.cc (cp_fold_r) [TARGET_EXPR]: Collapse TARGET_EXPR within TARGET_EXPR. * constexpr.cc (cxx_eval_outermost_constant_expr): Avoid adding redundant TARGET_EXPR. * cp-tree.h (target_expr_needs_replace): VEC_INIT_EXPR doesn't. --- gcc/cp/cp-tree.h | 3 ++- gcc/cp/constexpr.cc | 4 ++-- gcc/cp/cp-gimplify.cc | 16 +++++++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) base-commit: bbdcdf5cc73e1b3385d9a25bdab4df70c4bd8c2e diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 3cbcdf726ca..d696fd54a7a 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5426,7 +5426,8 @@ target_expr_needs_replace (tree t) return false; while (TREE_CODE (init) == COMPOUND_EXPR) init = TREE_OPERAND (init, 1); - return TREE_CODE (init) != AGGR_INIT_EXPR; + return (TREE_CODE (init) != AGGR_INIT_EXPR + && TREE_CODE (init) != VEC_INIT_EXPR); } /* True if EXPR expresses direct-initialization of a TYPE. */ diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index ed41d755269..db7571d7d71 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -8065,8 +8065,8 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant, if (TREE_CODE (t) == TARGET_EXPR && TARGET_EXPR_INITIAL (t) == r) return t; - else if (TREE_CODE (t) == CONSTRUCTOR) - ; + else if (TREE_CODE (t) == CONSTRUCTOR || TREE_CODE (t) == CALL_EXPR) + /* Don't add a TARGET_EXPR if our argument didn't have one. */; else if (TREE_CODE (t) == TARGET_EXPR && TARGET_EXPR_CLEANUP (t)) r = get_target_expr (r); else diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index c05be833357..73548888783 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -1084,9 +1084,9 @@ cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_) } break; - /* These are only for genericize time; they're here rather than in - cp_genericize to avoid problems with the invisible reference - transition. */ + /* cp_genericize_{init,target}_expr are only for genericize time; they're + here rather than in cp_genericize to avoid problems with the invisible + reference transition. */ case INIT_EXPR: if (data->genericize) cp_genericize_init_expr (stmt_p); @@ -1095,6 +1095,16 @@ cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_) case TARGET_EXPR: if (data->genericize) cp_genericize_target_expr (stmt_p); + + /* Folding might replace e.g. a COND_EXPR with a TARGET_EXPR; in + that case, use it in place of this one. */ + if (tree &init = TARGET_EXPR_INITIAL (stmt)) + { + cp_walk_tree (&init, cp_fold_r, data, NULL); + *walk_subtrees = 0; + if (TREE_CODE (init) == TARGET_EXPR) + *stmt_p = init; + } break; default: