From patchwork Mon May 27 17:52:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 1940065 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=axis.com header.i=@axis.com header.a=rsa-sha256 header.s=selector1 header.b=fCb3Qg1f; 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 4Vp3Cq2kN2z20Pb for ; Tue, 28 May 2024 03:53:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CEDA93881806 for ; Mon, 27 May 2024 17:53:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2047.outbound.protection.outlook.com [40.107.22.47]) by sourceware.org (Postfix) with ESMTPS id 13386384514A for ; Mon, 27 May 2024 17:53:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13386384514A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=axis.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=axis.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 13386384514A Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.22.47 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1716832382; cv=pass; b=GuELER5x3zUpxSLN6O014Y4bSz8y1g+UUB80ZcRzH5Rvk6XKdbKSb/+EbeIg1NiK+ggIdLA/V3K+q3EVXoz2mtW6St9dKwXYS4s4ybmS8omVOBNYKCI9FsWuKpdx+GpQefYnpPEhlJgX6DGFuKiwLit2JX1E3ep8jvg8Lok9Kw4= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1716832382; c=relaxed/simple; bh=uI0My56GvsALvdyBIj9a9GxE3BImwaAsemmXzC97Oxo=; h=DKIM-Signature:From:To:Subject:MIME-Version:Message-ID:Date; b=Pm5XZKOBfMyNODMmOB1gdrM3yrw8sNm7sQzprWlVFIf5NlI6bsT6jRMvUcTBEe93+XV0g/dDuytpsG+nIyHJn1fjHYkv76z3UB5vokqa7a+1KEE2ivXubprI53wm2F35KtjEHAVCxXFSm/XnNl6R4BX4rdPTm00NjmX7KsUKuUk= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cEUjW5JU/SKuNjHKrCLjY6o1t5b84y8hLaJmrqTKR4Eg8P79MG+BhV19oE8n+0+NDvn6oul0v1ZtCFC7iaTbuq67zw26fsqx5f5Uscv2P53vY6PTeRSuKDryPvPQdjPSDKcdhB6Eq/GpR02zn/Iwocj0nAqdTVGhCq6Ox0vWhLxUQVokqb7bi1rV0BPPNNMHXXq7UrlZSIEX+VC+v6A6w56Zb8t6m9PdiFrt0PSoNeDDZtQ86zBuRma5XJHnNGK9OnrDyqFxOZZ/QKlC/8SwWsbWhsAROQk86Y2RrAYtRMhWSBOFaqXBhIwgzLI81AlSENxJSu9Ehh4b2Igg32/McA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iuD449ovNQlouxytJug7VRHQZd64qRgMXVPo/jeuZhY=; b=dhHEh5FQ/XiwAa5/3I7rplMeBLjm5IeUTY8CPCgIQ7/421S0EI69xbz1gaCQlM6IM7w9F9mc2HrDdj2142ye2Gjsg22rqEAvna206gSd5sm8YK7UfnMrZAfS1ahjtTcoPzN5v60/XM2SJJNmYNVOy01pHTbbzDC8ny7Hap+3ONP2isV2v+9A8iInCAOuGKp3NWr9DGOw6VAoqiBPiPLCx8YnQ5ceIPsQ0pwLhQjDnSJ2fOdtHf2Pk9FqxWj4+jJelY3dV0SgvDfgCLHkUrBzZRloPjgFP/W5julpXqXx5b3oyzncEf51radoTxKChhOO2hmdBrpuazxDBmbsf4Rmug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 195.60.68.100) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=axis.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=axis.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iuD449ovNQlouxytJug7VRHQZd64qRgMXVPo/jeuZhY=; b=fCb3Qg1fpiQvxGu+zXsmos1JsMejE3pJzcnifavIFvtl+OoslghjoRi7vyrYUptDzHNs2pQXiaGiZxbCY01WfUqC04cO0pQKHQZaRGgv+UAITR3dSyKzEp5yRJjEPXFbZ5/bZR7Oh519KwVwcPlHWsW2ebuefOt1Oano1eLKsKE= Received: from AM0PR05CA0090.eurprd05.prod.outlook.com (2603:10a6:208:136::30) by DB9PR02MB7260.eurprd02.prod.outlook.com (2603:10a6:10:25c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Mon, 27 May 2024 17:52:57 +0000 Received: from AM3PEPF0000A794.eurprd04.prod.outlook.com (2603:10a6:208:136:cafe::49) by AM0PR05CA0090.outlook.office365.com (2603:10a6:208:136::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.30 via Frontend Transport; Mon, 27 May 2024 17:52:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 195.60.68.100) smtp.mailfrom=axis.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=axis.com; Received-SPF: Pass (protection.outlook.com: domain of axis.com designates 195.60.68.100 as permitted sender) receiver=protection.outlook.com; client-ip=195.60.68.100; helo=mail.axis.com; pr=C Received: from mail.axis.com (195.60.68.100) by AM3PEPF0000A794.mail.protection.outlook.com (10.167.16.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Mon, 27 May 2024 17:52:55 +0000 Received: from se-mail02w.axis.com (10.20.40.8) by se-mail02w.axis.com (10.20.40.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 27 May 2024 19:52:54 +0200 Received: from se-intmail01x.se.axis.com (10.0.5.60) by se-mail02w.axis.com (10.20.40.8) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Mon, 27 May 2024 19:52:54 +0200 Received: from pchp3.se.axis.com (pchp3.se.axis.com [10.88.21.53]) by se-intmail01x.se.axis.com (Postfix) with ESMTP id 99F509B6; Mon, 27 May 2024 19:52:54 +0200 (CEST) Received: by pchp3.se.axis.com (Postfix, from userid 171) id 9676820439; Mon, 27 May 2024 19:52:54 +0200 (CEST) From: Hans-Peter Nilsson To: Subject: [PATCH 2/4] resource.cc: Replace calls to find_basic_block with cfgrtl BLOCK_FOR_INSN MIME-Version: 1.0 Message-ID: <20240527175254.9676820439@pchp3.se.axis.com> Date: Mon, 27 May 2024 19:52:54 +0200 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM3PEPF0000A794:EE_|DB9PR02MB7260:EE_ X-MS-Office365-Filtering-Correlation-Id: f9d4ea08-093d-4dbe-5627-08dc7e75d651 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|36860700004|1800799015|376005|82310400017; X-Microsoft-Antispam-Message-Info: =?iso-8859-1?q?oT+4l/AeWmDM3LEnzBuZ64tOeh?= =?iso-8859-1?q?iOSkAnOJfMoC7gZDhRUfOEezsXGxqdz6w39zPt4IA9PBvvZ35xRL0wye/mxo?= =?iso-8859-1?q?6knnXZtjIPTUtmKQ2J6IXze/4w4rAOLNA37pC3yRq40Ze27bb4qkng8ZrA2V?= =?iso-8859-1?q?vWHXt4bg/nGs+a/UPN2Y06CyhT9xTd2KFRpBXEgS9hcUuXtJvde8g5RKlZBT?= =?iso-8859-1?q?vilbXiucM7Xe6sJhY7A3uYTuY3VQaHcb4LuDTOxWxUMTmSNPFgUfTEAX5q6I?= =?iso-8859-1?q?lUvSFxR1/uzQAr1kHojM5cD04Cp8SdIGd0fPDiLn10e2lliAjoDA6aHImwNI?= =?iso-8859-1?q?8CXFpqJHR9VxdYUk3hi5QQ0aSAkxXA1KxOpF47KltJBHdvY4xd9X1YA1PW2P?= =?iso-8859-1?q?cHnUuMDa+YoaC7IRtRemumdgvGGD0FZX8aPe5oqLvtoVtBR5wT79Tk5FRYWX?= =?iso-8859-1?q?jh7MSPIu1p4om2V2pex4fvUIQYvguq2mM0Wqa2yG5Y/cjD/ngWj5bJZw06S9?= =?iso-8859-1?q?9ZoUNOAqvrlMlC3eE5Dpmv5pJZoxY6DE539KiyNFcFdqv8OJXwjaquMUIYit?= =?iso-8859-1?q?WKJSB5yQiPOq0rOBlCtVlSGlA6I3Zz3ITHXcz9FIR9DldqkE0ze6wJIYwIv5?= =?iso-8859-1?q?jjdpBc0PfRtAy9QiPu4AAy2a0OkzghMoXTtLnwqf4WkxE4QYHmybd9tppPnR?= =?iso-8859-1?q?hN8O2xcPHY9+8C6Ki4MJPEg9cpbSf+0emfNYiM72bEUay7CxiR51pa71VgOk?= =?iso-8859-1?q?7viiCdRrcde373gVyZt8RZoXvo7FyGnY/If+S5R0Pd1xcTkCK+4aL53M5vMx?= =?iso-8859-1?q?+fbkv8KIq0CbrPCUywLritY4Xr7BOZTNFsosZkrGn/ao8TmPzCqBmMyS52id?= =?iso-8859-1?q?nrvREcnE8k9anM6b46tC10w/D7A5y2pI84MpsSPKaG0Rz0ZeltQyDjc7VRSm?= =?iso-8859-1?q?6w+0Hr4Dg24Um0Qp3i4A1tsZB6/yvXzoC1QxEk9jLeFdZIKDinu8StjPG3wM?= =?iso-8859-1?q?P4wD9hAYOCqgegaQ43offz/Gne2xtxDqq9bQOW4JGLRuH87i9H5hfDDm9e9Z?= =?iso-8859-1?q?/0feRlmWmFSfm2jGxJBt2BjG+P3dl/rWnRfG2ik8VXcdakjZ0X3UKn4Avxg0?= =?iso-8859-1?q?JHHucwh2g2yU1FSYktigI5eKaVuXWA6+rQyWkQ5gN2iHXz7N3blUSVBRH/zP?= =?iso-8859-1?q?++CluKzugVoSilcOk2hkXqWDJAUaZm1WzaFrcXErnofG28h3r3qFrsejkILq?= =?iso-8859-1?q?jdIvCET20z8gIvNdo4uuV6EG6vcyTsLDeVe3gsXEIj132h0eqoTWIE5aIMKa?= =?iso-8859-1?q?UH9QG2TsdGjMMNOlSlO96lHkwVSRc0GryvXD2uwd1+OyZrJko/b/HshDRb8b?= =?iso-8859-1?q?mAuIEnkKZ4z4kLUfwAdPiR6GlE0v6RuaXc9d3C+CkJBacYyFx6BLcjDigXUH?= =?iso-8859-1?q?n5?= X-Forefront-Antispam-Report: CIP:195.60.68.100; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.axis.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(36860700004)(1800799015)(376005)(82310400017); DIR:OUT; SFP:1101; X-OriginatorOrg: axis.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2024 17:52:55.1227 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f9d4ea08-093d-4dbe-5627-08dc7e75d651 X-MS-Exchange-CrossTenant-Id: 78703d3c-b907-432f-b066-88f7af9ca3af X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=78703d3c-b907-432f-b066-88f7af9ca3af; Ip=[195.60.68.100]; Helo=[mail.axis.com] X-MS-Exchange-CrossTenant-AuthSource: AM3PEPF0000A794.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR02MB7260 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, 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 Regtested cris-elf. Ok to commit? -- >8 -- ...and call compute_bb_for_insn in init_resource_info and free_bb_for_insn in free_resource_info. I put a gcc_unreachable in that else-clause for a failing find_basic_block in mark_target_live_regs after the comment that says: /* We didn't find the start of a basic block. Assume everything in use. This should happen only extremely rarely. */ SET_HARD_REG_SET (res->regs); and found that it fails not extremely rarely but extremely early in the build (compiling libgcc). That kind of pessimization leads to suboptimal delay-slot-filling. Instead, do like many machine_dependent_reorg passes and call compute_bb_for_insn as part of resource.cc initialization. After this patch, there's a whole "if (b != -1)" conditional that's dominated by a gcc_assert (b != -1). I separated that, as it's a NFC whitespace patch that hampers patch readability. Altogether this improved coremark performance for CRIS at -O2 -march=v10 by 0.36%. * resource.cc: Include cfgrtl.h. Use BLOCK_FOR_INSN (insn)->index instead of calling find_basic_block (insn). Assert for not -1. (find_basic_block): Remove function. (init_resource_info): Call compute_bb_for_insn. (free_resource_info): Call free_bb_for_insn. --- gcc/resource.cc | 66 ++++++++----------------------------------------- 1 file changed, 10 insertions(+), 56 deletions(-) diff --git a/gcc/resource.cc b/gcc/resource.cc index 06fcfd3e44c7..0d8cde93570e 100644 --- a/gcc/resource.cc +++ b/gcc/resource.cc @@ -28,6 +28,7 @@ along with GCC; see the file COPYING3. If not see #include "tm_p.h" #include "regs.h" #include "emit-rtl.h" +#include "cfgrtl.h" #include "resource.h" #include "insn-attr.h" #include "function-abi.h" @@ -75,7 +76,6 @@ static HARD_REG_SET current_live_regs; static HARD_REG_SET pending_dead_regs; static void update_live_status (rtx, const_rtx, void *); -static int find_basic_block (rtx_insn *, int); static rtx_insn *next_insn_no_annul (rtx_insn *); /* Utility function called from mark_target_live_regs via note_stores. @@ -113,46 +113,6 @@ update_live_status (rtx dest, const_rtx x, void *data ATTRIBUTE_UNUSED) CLEAR_HARD_REG_BIT (pending_dead_regs, i); } } - -/* Find the number of the basic block with correct live register - information that starts closest to INSN. Return -1 if we couldn't - find such a basic block or the beginning is more than - SEARCH_LIMIT instructions before INSN. Use SEARCH_LIMIT = -1 for - an unlimited search. - - The delay slot filling code destroys the control-flow graph so, - instead of finding the basic block containing INSN, we search - backwards toward a BARRIER where the live register information is - correct. */ - -static int -find_basic_block (rtx_insn *insn, int search_limit) -{ - /* Scan backwards to the previous BARRIER. Then see if we can find a - label that starts a basic block. Return the basic block number. */ - for (insn = prev_nonnote_insn (insn); - insn && !BARRIER_P (insn) && search_limit != 0; - insn = prev_nonnote_insn (insn), --search_limit) - ; - - /* The closest BARRIER is too far away. */ - if (search_limit == 0) - return -1; - - /* The start of the function. */ - else if (insn == 0) - return ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb->index; - - /* See if any of the upcoming CODE_LABELs start a basic block. If we reach - anything other than a CODE_LABEL or note, we can't find this code. */ - for (insn = next_nonnote_insn (insn); - insn && LABEL_P (insn); - insn = next_nonnote_insn (insn)) - if (BLOCK_FOR_INSN (insn)) - return BLOCK_FOR_INSN (insn)->index; - - return -1; -} /* Similar to next_insn, but ignores insns in the delay slots of an annulled branch. */ @@ -714,7 +674,8 @@ mark_target_live_regs (rtx_insn *insns, rtx target_maybe_return, struct resource } if (b == -1) - b = find_basic_block (target, param_max_delay_slot_live_search); + b = BLOCK_FOR_INSN (target)->index; + gcc_assert (b != -1); if (target_hash_table != NULL) { @@ -722,7 +683,7 @@ mark_target_live_regs (rtx_insn *insns, rtx target_maybe_return, struct resource { /* If the information is up-to-date, use it. Otherwise, we will update it below. */ - if (b == tinfo->block && b != -1 && tinfo->bb_tick == bb_ticks[b]) + if (b == tinfo->block && tinfo->bb_tick == bb_ticks[b]) { res->regs = tinfo->live_regs; return; @@ -905,7 +866,6 @@ void init_resource_info (rtx_insn *epilogue_insn) { int i; - basic_block bb; /* Indicate what resources are required to be valid at the end of the current function. The condition code never is and memory always is. @@ -975,10 +935,8 @@ init_resource_info (rtx_insn *epilogue_insn) target_hash_table = XCNEWVEC (struct target_info *, TARGET_HASH_PRIME); bb_ticks = XCNEWVEC (int, last_basic_block_for_fn (cfun)); - /* Set the BLOCK_FOR_INSN of each label that starts a basic block. */ - FOR_EACH_BB_FN (bb, cfun) - if (LABEL_P (BB_HEAD (bb))) - BLOCK_FOR_INSN (BB_HEAD (bb)) = bb; + /* Set the BLOCK_FOR_INSN for each insn. */ + compute_bb_for_insn (); } /* Free up the resources allocated to mark_target_live_regs (). This @@ -987,8 +945,6 @@ init_resource_info (rtx_insn *epilogue_insn) void free_resource_info (void) { - basic_block bb; - if (target_hash_table != NULL) { int i; @@ -1015,9 +971,7 @@ free_resource_info (void) bb_ticks = NULL; } - FOR_EACH_BB_FN (bb, cfun) - if (LABEL_P (BB_HEAD (bb))) - BLOCK_FOR_INSN (BB_HEAD (bb)) = NULL; + free_bb_for_insn (); } /* Clear any hashed information that we have stored for INSN. */ @@ -1063,10 +1017,10 @@ clear_hashed_info_until_next_barrier (rtx_insn *insn) void incr_ticks_for_insn (rtx_insn *insn) { - int b = find_basic_block (insn, param_max_delay_slot_live_search); + int b = BLOCK_FOR_INSN (insn)->index; + gcc_assert (b != -1); - if (b != -1) - bb_ticks[b]++; + bb_ticks[b]++; } /* Add TRIAL to the set of resources used at the end of the current