From patchwork Tue May 7 11:21:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1932427 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=vJy/ILmm; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=IIOFlKLA; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=vJy/ILmm; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=IIOFlKLA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VYbTh4mPZz1ydW for ; Tue, 7 May 2024 21:22:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DE2793846420 for ; Tue, 7 May 2024 11:22:14 +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.223.130]) by sourceware.org (Postfix) with ESMTPS id C2C143858C35 for ; Tue, 7 May 2024 11:21:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2C143858C35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C2C143858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715080878; cv=none; b=Sb+xnXdDZqvdGBZqNrUYEdqX2D8T2DYHR7ZgUR3AAIp0yBsgBE88TX518vaS3uqPPe9JTLKnFXzLuiqa519dzMCfw666wJl8VHFRYpRyMKwioGDUckB1ezqLWx6rx2PBXAE8ebVQ/aPngj85Ly9xzyHaWWVXiU8G8OZ6Ji3rVUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715080878; c=relaxed/simple; bh=DnkPDR+MK33Hs/syFCpfgTNLHK//XnesSyXhHYBrfOg=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=LmipFahvQWgWh56wmP2tbnqJHn2/X2MDUbVXClVPZdO14mcusM2DUXNX8poj8wu/ffx7QgKImMA/Zub2fQlE1XA7vci8nrhaCX+abHhbHuWGK8F2BAOuMg/3fUMrgbI/I3LC7K5Hjru2xvAmRtGjKWL4UwLZobeWNQX75YluKJY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.5.241] (unknown [10.168.5.241]) (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 smtp-out1.suse.de (Postfix) with ESMTPS id C9ABC33DA3 for ; Tue, 7 May 2024 11:21:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1715080875; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8w98z3bDKZ9lXDN2h5uczVz0VUpu9qMYmYUrnPgCUII=; b=vJy/ILmmXlgdBX6H8oNUjYr2YC57reWWA6r67YFXduvK1/p2q36u7eVcSd7iJT+h9tKqeL UhsKiuNlNaC6uS6cZdJfM7Nc/GCONBocqykM/b1EkvRguEB6/36ynpyWUlT+PGkZhDAanD kHn32AnlONn4ewP8gMcOPrJtKoLIzNs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1715080875; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8w98z3bDKZ9lXDN2h5uczVz0VUpu9qMYmYUrnPgCUII=; b=IIOFlKLAfGMSvJ2/cyqSOuuDLHZ+IMJ//O4QlM8N5+/yN3tIGCpc3DTWODEiz6OroUeOWh +OgUmrbY2Fv8eZAA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1715080875; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8w98z3bDKZ9lXDN2h5uczVz0VUpu9qMYmYUrnPgCUII=; b=vJy/ILmmXlgdBX6H8oNUjYr2YC57reWWA6r67YFXduvK1/p2q36u7eVcSd7iJT+h9tKqeL UhsKiuNlNaC6uS6cZdJfM7Nc/GCONBocqykM/b1EkvRguEB6/36ynpyWUlT+PGkZhDAanD kHn32AnlONn4ewP8gMcOPrJtKoLIzNs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1715080875; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8w98z3bDKZ9lXDN2h5uczVz0VUpu9qMYmYUrnPgCUII=; b=IIOFlKLAfGMSvJ2/cyqSOuuDLHZ+IMJ//O4QlM8N5+/yN3tIGCpc3DTWODEiz6OroUeOWh +OgUmrbY2Fv8eZAA== Date: Tue, 7 May 2024 13:21:15 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/27800 - avoid unnecessary temporary during gimplification MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-1.69 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-1.00)[-0.995]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_SHORT(-0.09)[-0.457]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; MISSING_XM_UA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; MIME_TRACE(0.00)[0:+] X-Spam-Score: -1.69 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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.30 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 Message-Id: <20240507112214.DE2793846420@sourceware.org> This avoids a tempoary when gimplifying reg = a ? b : c, re-using the LHS of an assignment if that's a register. Re-bootstrap and regtest running on x86_64-unknown-linux-gnu. PR middle-end/27800 * gimplify.cc (gimplify_modify_expr_rhs): For a COND_EXPR avoid a temporary from gimplify_cond_expr when the LHS is a register by pushing the assignment into the COND_EXPR arms. * gcc.dg/pr27800.c: New testcase. --- gcc/gimplify.cc | 7 +++++-- gcc/testsuite/gcc.dg/pr27800.c | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr27800.c diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 763843f45a7..26e96ada4c7 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -6082,8 +6082,11 @@ gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p, /* If we're assigning to a non-register type, push the assignment down into the branches. This is mandatory for ADDRESSABLE types, since we cannot generate temporaries for such, but it saves a - copy in other cases as well. */ - if (!is_gimple_reg_type (TREE_TYPE (*from_p))) + copy in other cases as well. + Also avoid an extra temporary and copy when assigning to + a register. */ + if (!is_gimple_reg_type (TREE_TYPE (*from_p)) + || (is_gimple_reg (*to_p) && !gimplify_ctxp->allow_rhs_cond_expr)) { /* This code should mirror the code in gimplify_cond_expr. */ enum tree_code code = TREE_CODE (*expr_p); diff --git a/gcc/testsuite/gcc.dg/pr27800.c b/gcc/testsuite/gcc.dg/pr27800.c new file mode 100644 index 00000000000..e92ebc22e6f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr27800.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-gimple" } */ + +int iii (int a, int b, int c) +{ + return a ? b : c; +} + +/* Verify we end up with two assignments and not an extra copy + resulting from another temporary generated from gimplify_cond_expr. */ +/* { dg-final { scan-tree-dump-times " = " 2 "gimple" } } */