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 5F9C03858C20 for ; Fri, 30 Sep 2022 01:28:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5F9C03858C20 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=1664501308; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bulaeI3x+lap/h8WqJl0BxDpYR4bcJ++HQRb7e5N2VM=; b=KgIUrQ04dhqUri67+uWYafTcepmwZZoLQUO9t2YLgefBcLfR1knfRhxUBy6oxZyAsuOVMy oQtebU6jMPzIFWS+elbx08qLHcNwqSH3Z7j8mK9wf/T4QgjKUT+xC8VX3uWbhVyNzNm8AV LScAv/mjGJzRlW5PR0RW3wGhJ1uVXEk= 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-Google-Smtp-Source: AMsMyM53cntxeQJV3XHw7YJi94lQU+3ePZpfKoqcnZ4S3JKjB4c4e2nIfk1pJkNC2zBcR8YotDYh5w== 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) From: Jason Merrill 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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(-) 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: base-commit: bbdcdf5cc73e1b3385d9a25bdab4df70c4bd8c2e -- 2.31.1