From patchwork Tue Jun 22 10:57:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1495538 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=MkQNyuFU; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=nVIwx0He; 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G8Nff52lZz9sj1 for ; Tue, 22 Jun 2021 20:58:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F41D7388A02B for ; Tue, 22 Jun 2021 10:58:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 274E53857816 for ; Tue, 22 Jun 2021 10:57:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 274E53857816 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 09DD2218D6 for ; Tue, 22 Jun 2021 10:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1624359471; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=Sx0qS1DUYG/B8chdlDyo2dTLTvs/Fkk18RWjyEpn3E0=; b=MkQNyuFUt+tMSWGyUHiZzUo/oV5ND1Am0tw3CPyipB7euycQivhdAL+FVADggbLIq0WQA0 JGywwgAtjKiim7kIulab7jugw1EuTNDCMHOduB02o5V2DAodxSJGnnUGONehH5tIOxuWyK tWGE9xvcuysco0FjCmhubFyH7PIqpss= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1624359471; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=Sx0qS1DUYG/B8chdlDyo2dTLTvs/Fkk18RWjyEpn3E0=; b=nVIwx0HeZjjkhfTqdMl9iOK5mJnRhz7SGQqmzINr4/vZp7FKHc8GsinaCkWCheaN5Ww8AA cUCPYzs5BJKsisCA== Received: from [10.163.28.26] (unknown [10.163.28.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id EEC09A3B8B for ; Tue, 22 Jun 2021 10:57:50 +0000 (UTC) Date: Tue, 22 Jun 2021 12:57:50 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/101156 - remove not working optimization in gimplification Message-ID: <8ppo1rq-366o-p155-r2no-ps692p70q6oq@fhfr.qr> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This removes a premature and not working optimization from the gimplifier. When gimplification is requested not to produce a SSA name we try to avoid generating a copy when we did so anyway but instead replace the LHS of its definition. But that only works in case there are no uses of the SSA name already which is something we cannot easily check, so the following removes said optimization. Statistics on the whole bootstrap shows we hit this optimization only for libiberty/cp-demangle.c and overall we have 21652112 gimplifications where just 240 copies are elided. Preserving the optimization would require scanning the original expression and the pre and post sequences for SSA names and uses, that seems excessive to avoid these 240 copies. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2021-06-22 Richard Biener PR middle-end/101156 * gimplify.c (gimplify_expr): Remove premature incorrect optimization. * gcc.dg/pr101156.c: New testcase. --- gcc/gimplify.c | 15 +-------------- gcc/testsuite/gcc.dg/pr101156.c | 8 ++++++++ 2 files changed, 9 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr101156.c diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 41bae9c188f..21e7a6cc959 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -15128,24 +15128,11 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, bool (*gimple_test_f) (tree), fallback_t fallback, bool allow_ssa) { - bool was_ssa_name_p = TREE_CODE (*expr_p) == SSA_NAME; enum gimplify_status ret = gimplify_expr (expr_p, pre_p, post_p, gimple_test_f, fallback); if (! allow_ssa && TREE_CODE (*expr_p) == SSA_NAME) - { - tree name = *expr_p; - if (was_ssa_name_p) - *expr_p = get_initialized_tmp_var (*expr_p, pre_p, NULL, false); - else - { - /* Avoid the extra copy if possible. */ - *expr_p = create_tmp_reg (TREE_TYPE (name)); - if (!gimple_nop_p (SSA_NAME_DEF_STMT (name))) - gimple_set_lhs (SSA_NAME_DEF_STMT (name), *expr_p); - release_ssa_name (name); - } - } + *expr_p = get_initialized_tmp_var (*expr_p, pre_p, NULL, false); return ret; } diff --git a/gcc/testsuite/gcc.dg/pr101156.c b/gcc/testsuite/gcc.dg/pr101156.c new file mode 100644 index 00000000000..5c25bd78a02 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr101156.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-fchecking" } */ + +struct S { int i; }; +void baz(struct S *p) +{ + __builtin_setjmp(p--); +}