From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 132243856DDA for ; Sun, 5 Nov 2023 18:47:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 132243856DDA 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 132243856DDA 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=1699210047; cv=none; b=nA0IUriAwJxRzEHOBTC1jWM3T7Pm5gFeTOi91eM2PM+btqT+tczt3L63mFx3SMaMp40JtrPbd/7lj6eqAgRrJs60jqVvijVLoVevnDOpe5OBQ/IgFIwPDW1mj3GCym91Cn5k1jmzITEdzhjtdCVqKfrzwFupzCAHkzlMItS8NY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699210047; c=relaxed/simple; bh=qX7WfmeLOFz9M+CPx//uY8b5+i8/WmTctH6/eTkiinE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Np0poYQcj4D7YeHWst0ha2NtQjXQeSSoLsWwiG1fkA+xrWvKKJCwRlyUEJk02qLIdYO5wXW4FRbaTEiHpTka3T/tSuaiDgedEH2HH+MpnTxd6f8LRdYRsKL9aitTjxnkQekRp459c6abjz5iSZuBTmzstPUBofyOjYeV8qJQpG8= 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 8B76FC15; Sun, 5 Nov 2023 10:48:09 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 486173F703; Sun, 5 Nov 2023 10:47:25 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org,jlaw@ventanamicro.com, richard.sandiford@arm.com Cc: jlaw@ventanamicro.com Subject: [PATCH 04/12] mode-switching: Fix the mode passed to the emit hook References: Date: Sun, 05 Nov 2023 18:47:24 +0000 In-Reply-To: (Richard Sandiford's message of "Sun, 05 Nov 2023 18:45:29 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-23.4 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 List-Id: optimize_mode_switching passes an entity's current mode (if known) to the emit hook. However, the mode that it passed ignored the effect of the after hook. Instead, the mode for the first emit call in a block was taken from the incoming mode, whereas the mode for each subsequent emit call was taken from the result of the previous call. The previous pass through the insns already calculated the correct mode, so this patch records it in the seginfo structure. (There was a 32-bit hole on 64-bit hosts, so this doesn't increase the size of the structure for them.) gcc/ * mode-switching.cc (seginfo): Add a prev_mode field. (new_seginfo): Take and initialize the prev_mode. (optimize_mode_switching): Update calls accordingly. Use the recorded modes during the emit phase, rather than computing one on the fly. --- gcc/mode-switching.cc | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/gcc/mode-switching.cc b/gcc/mode-switching.cc index bebe89d5fd2..12ddbd6adfa 100644 --- a/gcc/mode-switching.cc +++ b/gcc/mode-switching.cc @@ -68,6 +68,7 @@ along with GCC; see the file COPYING3. If not see NEXT is the next insn in the same basic block. */ struct seginfo { + int prev_mode; int mode; rtx_insn *insn_ptr; struct seginfo *next; @@ -140,20 +141,22 @@ commit_mode_sets (struct edge_list *edge_list, int e, struct bb_info *info) return need_commit; } -/* Allocate a new BBINFO structure, initialized with the MODE, INSN, - and REGS_LIVE parameters. +/* Allocate a new BBINFO structure, initialized with the PREV_MODE, MODE, + INSN, and REGS_LIVE parameters. INSN may not be a NOTE_INSN_BASIC_BLOCK, unless it is an empty basic block; that allows us later to insert instructions in a FIFO-like manner. */ static struct seginfo * -new_seginfo (int mode, rtx_insn *insn, const HARD_REG_SET ®s_live) +new_seginfo (int prev_mode, int mode, rtx_insn *insn, + const HARD_REG_SET ®s_live) { struct seginfo *ptr; gcc_assert (!NOTE_INSN_BASIC_BLOCK_P (insn) || insn == BB_END (NOTE_BASIC_BLOCK (insn))); ptr = XNEW (struct seginfo); + ptr->prev_mode = prev_mode; ptr->mode = mode; ptr->insn_ptr = insn; ptr->next = NULL; @@ -590,7 +593,7 @@ optimize_mode_switching (void) gcc_assert (NOTE_INSN_BASIC_BLOCK_P (ins_pos)); if (ins_pos != BB_END (bb)) ins_pos = NEXT_INSN (ins_pos); - ptr = new_seginfo (no_mode, ins_pos, live_now); + ptr = new_seginfo (no_mode, no_mode, ins_pos, live_now); add_seginfo (&tail_ptr, ptr); for (i = 0; i < no_mode; i++) clear_mode_bit (transp[bb->index], j, i); @@ -606,12 +609,12 @@ optimize_mode_switching (void) if (mode != no_mode && mode != last_mode) { - any_set_required = true; - last_mode = mode; - ptr = new_seginfo (mode, insn, live_now); + ptr = new_seginfo (last_mode, mode, insn, live_now); add_seginfo (&tail_ptr, ptr); for (i = 0; i < no_mode; i++) clear_mode_bit (transp[bb->index], j, i); + any_set_required = true; + last_mode = mode; } if (targetm.mode_switching.after) @@ -637,7 +640,7 @@ optimize_mode_switching (void) mark the block as nontransparent. */ if (!any_set_required) { - ptr = new_seginfo (no_mode, BB_END (bb), live_now); + ptr = new_seginfo (last_mode, no_mode, BB_END (bb), live_now); add_seginfo (&tail_ptr, ptr); if (last_mode != no_mode) for (i = 0; i < no_mode; i++) @@ -778,9 +781,9 @@ optimize_mode_switching (void) FOR_EACH_BB_FN (bb, cfun) { struct seginfo *ptr, *next; - int cur_mode = bb_info[j][bb->index].mode_in; + struct seginfo *first = bb_info[j][bb->index].seginfo; - for (ptr = bb_info[j][bb->index].seginfo; ptr; ptr = next) + for (ptr = first; ptr; ptr = next) { next = ptr->next; if (ptr->mode != no_mode) @@ -790,14 +793,15 @@ optimize_mode_switching (void) rtl_profile_for_bb (bb); start_sequence (); + int cur_mode = (ptr == first && ptr->prev_mode == no_mode + ? bb_info[j][bb->index].mode_in + : ptr->prev_mode); + targetm.mode_switching.emit (entity_map[j], ptr->mode, cur_mode, ptr->regs_live); mode_set = get_insns (); end_sequence (); - /* modes kill each other inside a basic block. */ - cur_mode = ptr->mode; - /* Insert MODE_SET only if it is nonempty. */ if (mode_set != NULL_RTX) { -- 2.25.1