From patchwork Tue Feb 21 14:23:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 60107 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp36452wrd; Tue, 21 Feb 2023 06:24:46 -0800 (PST) X-Google-Smtp-Source: AK7set9daDTIVAXATMA8CU5SLLAqIoYnukWVDTKUzPVP2niflqCC9bjBQUYj5DaoJAYzqetuor3s X-Received: by 2002:a50:ff0e:0:b0:4ab:f6c:1a47 with SMTP id a14-20020a50ff0e000000b004ab0f6c1a47mr3794791edu.31.1676989485929; Tue, 21 Feb 2023 06:24:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676989485; cv=none; d=google.com; s=arc-20160816; b=Z9og7gQlUMcgi6kcLq351z9yJVVQTP3nZGJruBPSWyRVANQ/c8WyNgJmOX1UM1fyxz qpOc6bdEPmsfevFQwUDXg/bc7sEW+ZhLAQSV7C8qoiDsRbfLFxOUYySg3eeR0A6AJmHM KasKoF5UXMEhIczra6bNZ8m7XNfOasVqKnpU7Op1zkC0SDAYuMsU02Cxqk5/lQmYjgGW QF3bo/tSdg4Wmh+sYmYbaAXV21rFHswx/OUpdZiX5bYa5Yee+8o7bkNL/PqrgCivJNO1 vN6RDlJPwynH8+4LHlUHzkSIuFdO29+AMcv4SurWvZYR9PeIreTm1eO6o1iK1aeBqeiK b5IQ== 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:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=s6Kvi/vRfqPOcXlAEgH322O6lN/GSoZ+5NfFn9OSklk=; b=uJdwvnOQ78J1pZEeVq032KMJHBO68XG0K22PJRRFpKTjNn9nPsbDGoFQScemC7mq+8 1uQ0mzZXjQUWyh+vbdoL8hUmJW4SgqhlHmvgE3eoyEY5WymWp6+9QBJMGR6a+PTzJwMx OSApitPswIPSiK2UBPqPMtfgoAByyKwYkR22HzaYTSCP20GQDjcipKixYORghA0b8Iof alvBJu9ZdbndZYSHY/Wa3f88CLJr/cZKHBkIH/UuLWLngbmImwhAirppJzq0jd+Zi7tN d8LY1frukQ2LE3wZGk8Pu6fP6wfIaqSdQ1mOs0sQDzZhsBuDQ7L72tguxoZx3fysE+uz Ptjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VafpdmqR; 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" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j21-20020aa7ca55000000b004a20d8b233esi4221258edt.317.2023.02.21.06.24.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 06:24:44 -0800 (PST) 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=VafpdmqR; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CA4933857C45 for ; Tue, 21 Feb 2023 14:24:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA4933857C45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676989477; bh=s6Kvi/vRfqPOcXlAEgH322O6lN/GSoZ+5NfFn9OSklk=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=VafpdmqRjS/6Ib69YFOnxkVph+V7TasEytH94ZPZngpBjJjedgxuln9BxP3VuqogI On7Xbkwi1WHw4hlb+TASK+E9TD8NSq3/TBgcTtO47UZAbSyYWa0BEmYiwOlOWOil0k GjmLvqQhSajBvPdYPO9r8+QBK+H4PX7UMSaHKZZY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by sourceware.org (Postfix) with ESMTPS id 5CF4A3858410 for ; Tue, 21 Feb 2023 14:23:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5CF4A3858410 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4PLhNm0hDnz9sTL; Tue, 21 Feb 2023 15:23:52 +0100 (CET) To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [committed] d: Only handle the left-to-right evaluation of a call expression during gimplify Date: Tue, 21 Feb 2023 15:23:50 +0100 Message-Id: <20230221142350.1806182-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, 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: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw 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?1758450927109928845?= X-GMAIL-MSGID: =?utf-8?q?1758450927109928845?= This patch removes an unnecessary rewriting of the front-end AST during lowering. As all functions regardless of their linkage are evaluated strictly left-to-right now, there's no point trying to handle all temp saving during the code generation pass. Bootstrapped and regression tested on x86_64-linux-gnu, and committed to mainline. Regards, Iain. --- gcc/d/ChangeLog: * d-codegen.cc (d_build_call): Remove front-end expansion of side-effects in a call expression. * d-gimplify.cc (d_gimplify_call_expr): Gimplify the callee before its arguments. --- gcc/d/d-codegen.cc | 29 +++-------------------------- gcc/d/d-gimplify.cc | 9 +++++++++ 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 920b45d0480..0e8e07366ee 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -2172,7 +2172,6 @@ d_build_call (TypeFunction *tf, tree callable, tree object, /* Build the argument list for the call. */ vec *args = NULL; - tree saved_args = NULL_TREE; bool noreturn_call = false; /* If this is a delegate call or a nested function being called as @@ -2182,23 +2181,6 @@ d_build_call (TypeFunction *tf, tree callable, tree object, if (arguments) { - /* First pass, evaluated expanded tuples in function arguments. */ - for (size_t i = 0; i < arguments->length; ++i) - { - Lagain: - Expression *arg = (*arguments)[i]; - gcc_assert (arg->op != EXP::tuple); - - if (arg->op == EXP::comma) - { - CommaExp *ce = arg->isCommaExp (); - tree tce = build_expr (ce->e1); - saved_args = compound_expr (saved_args, tce); - (*arguments)[i] = ce->e2; - goto Lagain; - } - } - const size_t nparams = tf->parameterList.length (); /* if _arguments[] is the first argument. */ const size_t varargs = tf->isDstyleVariadic (); @@ -2257,17 +2239,12 @@ d_build_call (TypeFunction *tf, tree callable, tree object, } } - /* Evaluate the callee before calling it. */ - if (TREE_SIDE_EFFECTS (callee)) - { - callee = d_save_expr (callee); - saved_args = compound_expr (callee, saved_args); - } - /* If we saw a `noreturn` parameter, any unreachable argument evaluations after it are discarded, as well as the function call itself. */ if (noreturn_call) { + tree saved_args = NULL_TREE; + if (TREE_SIDE_EFFECTS (callee)) saved_args = compound_expr (callee, saved_args); @@ -2297,7 +2274,7 @@ d_build_call (TypeFunction *tf, tree callable, tree object, result = force_target_expr (result); } - return compound_expr (saved_args, result); + return result; } /* Build and return the correct call to fmod depending on TYPE. diff --git a/gcc/d/d-gimplify.cc b/gcc/d/d-gimplify.cc index 4072a3d92cf..04cb631244c 100644 --- a/gcc/d/d-gimplify.cc +++ b/gcc/d/d-gimplify.cc @@ -162,6 +162,15 @@ d_gimplify_call_expr (tree *expr_p, gimple_seq *pre_p) if (!has_side_effects) return GS_UNHANDLED; + /* Evaluate the callee before calling it. */ + tree new_call_fn = CALL_EXPR_FN (*expr_p); + + if (gimplify_expr (&new_call_fn, pre_p, NULL, + is_gimple_call_addr, fb_rvalue) == GS_ERROR) + return GS_ERROR; + + CALL_EXPR_FN (*expr_p) = new_call_fn; + /* Leave the last argument for gimplify_call_expr. */ for (int i = 0; i < nargs - 1; i++) {