From patchwork Thu Jun 20 13:34:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1950176 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W4hMC4bj7z20Wb for ; Thu, 20 Jun 2024 23:35:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9EDD0389366E for ; Thu, 20 Jun 2024 13:35:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 9E98F3892474 for ; Thu, 20 Jun 2024 13:35:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E98F3892474 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9E98F3892474 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718890506; cv=none; b=Q43mOkkqX5VF5VpAX59ufJdJ3l5RxZ14QRYO6pPHNMB2XWVLSipIvXmpCBD6hoWR0Vmb2acFL9/2IQg1ogs//7HV61uR/6/rR66ACNsdwunsDDWQeELMNNN9RLlypAWlKfzvuVMB1n9CvwaFdGCrNPtAnig1aLvIhkXaDD9BC5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718890506; c=relaxed/simple; bh=ChLQkzUk0ycFP6/xsZu0LBo0oPMUt5ixGhFtbh2AcIQ=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=inM1FPL7oTMRiZbCGky4v9n0gIijxEEsGhO+4uHG2AGcKYXR6oLU5vWHUigrUsEjFiC344Cpw+gRSSHDXhO63SaNxDU1/q1QW4Ih3JtXRbb5DKT7/TyYZ130bXyq1fWB3G+96kbIvbm+++9LzZfrlbZ2r1u5UqtzAzu0tWJcCr4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 197741684; Thu, 20 Jun 2024 06:35:29 -0700 (PDT) Received: from e121540-lin.manchester.arm.com (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C7EB13F73B; Thu, 20 Jun 2024 06:35:03 -0700 (PDT) From: Richard Sandiford To: jlaw@ventanamicro.com, gcc-patches@gcc.gnu.org Cc: Richard Sandiford Subject: [PATCH 2/6] rtl-ssa: Don't cost no-op moves Date: Thu, 20 Jun 2024 14:34:14 +0100 Message-Id: <20240620133418.350772-3-richard.sandiford@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240620133418.350772-1-richard.sandiford@arm.com> References: <20240620133418.350772-1-richard.sandiford@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-20.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 No-op moves are given the code NOOP_MOVE_INSN_CODE if we plan to delete them later. Such insns shouldn't be costed, partly because they're going to disappear, and partly because targets won't recognise the insn code. gcc/ * rtl-ssa/changes.cc (rtl_ssa::changes_are_worthwhile): Don't cost no-op moves. * rtl-ssa/insns.cc (insn_info::calculate_cost): Likewise. --- gcc/rtl-ssa/changes.cc | 6 +++++- gcc/rtl-ssa/insns.cc | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gcc/rtl-ssa/changes.cc b/gcc/rtl-ssa/changes.cc index c5ac4956a19..bc80d7da829 100644 --- a/gcc/rtl-ssa/changes.cc +++ b/gcc/rtl-ssa/changes.cc @@ -177,13 +177,17 @@ rtl_ssa::changes_are_worthwhile (array_slice changes, auto entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; for (insn_change *change : changes) { + // Count zero for the old cost if the old instruction was a no-op + // move or had an unknown cost. This should reduce the chances of + // making an unprofitable change. old_cost += change->old_cost (); basic_block cfg_bb = change->bb ()->cfg_bb (); bool for_speed = optimize_bb_for_speed_p (cfg_bb); if (for_speed) weighted_old_cost += (cfg_bb->count.to_sreal_scale (entry_count) * change->old_cost ()); - if (!change->is_deletion ()) + if (!change->is_deletion () + && INSN_CODE (change->rtl ()) != NOOP_MOVE_INSN_CODE) { change->new_cost = insn_cost (change->rtl (), for_speed); /* If the cost is unknown, replacement is not worthwhile. */ diff --git a/gcc/rtl-ssa/insns.cc b/gcc/rtl-ssa/insns.cc index 0171d93c357..68365e323ec 100644 --- a/gcc/rtl-ssa/insns.cc +++ b/gcc/rtl-ssa/insns.cc @@ -48,7 +48,12 @@ insn_info::calculate_cost () const { basic_block cfg_bb = BLOCK_FOR_INSN (m_rtl); temporarily_undo_changes (0); - m_cost_or_uid = insn_cost (m_rtl, optimize_bb_for_speed_p (cfg_bb)); + if (INSN_CODE (m_rtl) == NOOP_MOVE_INSN_CODE) + // insn_cost also uses 0 to mean "don't know". Callers that + // want to distinguish the cases will need to check INSN_CODE. + m_cost_or_uid = 0; + else + m_cost_or_uid = insn_cost (m_rtl, optimize_bb_for_speed_p (cfg_bb)); redo_changes (0); }