From patchwork Thu Jan 6 14:46:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 49622 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8E3333858010 for ; Thu, 6 Jan 2022 14:48:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E3333858010 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641480512; bh=M523rHtXHaaPOZJBdQBzEeZ33HXC2Ozbx6DmhDU7jgc=; h=To:Subject:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=h58pvME/L9c4hth2lyIQNOffqXF8bPQ7qX059q6SYymXZMs1KvYktOaMLHlAeyWt4 92jltD9lFjkrfNcXPsl7LzZFfHZL+5yODRJX0HvZHab/FqdrM0Qw6j6OMGmjgIwAwX Fm0Yo/fIlMp7cFz/LWFjs4+JFY1uhuDt8oc1+LgE= 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 8A0A83858410 for ; Thu, 6 Jan 2022 14:46:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8A0A83858410 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 30CD7142F; Thu, 6 Jan 2022 06:46:49 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AFD383F5A1; Thu, 6 Jan 2022 06:46:48 -0800 (PST) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, vmakarov@redhat.com, richard.sandiford@arm.com Subject: [PATCH 2/6] ira: Add comments and fix move_spill_restore calculation References: Date: Thu, 06 Jan 2022 14:46:47 +0000 In-Reply-To: (Richard Sandiford's message of "Thu, 06 Jan 2022 14:45:45 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-Patchwork-Original-From: Richard Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch adds comments to describe each use of ira_loop_border_costs. I think this highlights that move_spill_restore was using the wrong cost in one case, which came from tranposing [0] and [1] in the original (pre-ira_loop_border_costs) ira_memory_move_cost expressions. The difference would only be noticeable on targets that distinguish between load and store costs. gcc/ PR rtl-optimization/98782 * ira-color.c (color_pass): Add comments to describe the spill costs. (move_spill_restore): Likewise. Fix reversed calculation. --- gcc/ira-color.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/gcc/ira-color.c b/gcc/ira-color.c index 66c11710b97..e7433312675 100644 --- a/gcc/ira-color.c +++ b/gcc/ira-color.c @@ -3479,6 +3479,13 @@ color_pass (ira_loop_tree_node_t loop_tree_node) } else if (hard_regno < 0) { + /* If we allocate a register to SUBLOOP_ALLOCNO, we'll need + to load the register on entry to the subloop and store + the register back on exit from the subloop. This incurs + a fixed cost for all registers. Since UPDATED_MEMORY_COST + is (and should only be) used relative to the register costs + for the same allocno, we can subtract this shared register + cost from the memory cost. */ ira_loop_border_costs border_costs (subloop_allocno); ALLOCNO_UPDATED_MEMORY_COST (subloop_allocno) -= border_costs.spill_outside_loop_cost (); @@ -3503,6 +3510,9 @@ color_pass (ira_loop_tree_node_t loop_tree_node) > ALLOCNO_UPDATED_HARD_REG_COSTS (subloop_allocno)[index]) ALLOCNO_UPDATED_CLASS_COST (subloop_allocno) = ALLOCNO_UPDATED_HARD_REG_COSTS (subloop_allocno)[index]; + /* If we spill SUBLOOP_ALLOCNO, we'll need to store HARD_REGNO + on entry to the subloop and restore HARD_REGNO on exit from + the subloop. */ ALLOCNO_UPDATED_MEMORY_COST (subloop_allocno) += border_costs.spill_inside_loop_cost (); } @@ -3601,9 +3611,17 @@ move_spill_restore (void) : ALLOCNO_HARD_REG_COSTS (subloop_allocno)[index])); ira_loop_border_costs border_costs (subloop_allocno); if ((hard_regno2 = ALLOCNO_HARD_REGNO (subloop_allocno)) < 0) - cost -= border_costs.spill_outside_loop_cost (); + /* The register was spilled in the subloop. If we spill + it in the outer loop too then we'll no longer need to + save the register on entry to the subloop and restore + the register on exit from the subloop. */ + cost -= border_costs.spill_inside_loop_cost (); else { + /* The register was also allocated in the subloop. If we + spill it in the outer loop then we'll need to load the + register on entry to the subloop and store the register + back on exit from the subloop. */ cost += border_costs.spill_outside_loop_cost (); if (hard_regno2 != hard_regno) cost -= border_costs.move_between_loops_cost (); @@ -3615,9 +3633,17 @@ move_spill_restore (void) ira_assert (rclass == ALLOCNO_CLASS (parent_allocno)); ira_loop_border_costs border_costs (a); if ((hard_regno2 = ALLOCNO_HARD_REGNO (parent_allocno)) < 0) + /* The register was spilled in the parent loop. If we spill + it in this loop too then we'll no longer need to load the + register on entry to this loop and save the register back + on exit from this loop. */ cost -= border_costs.spill_outside_loop_cost (); else { + /* The register was also allocated in the parent loop. + If we spill it in this loop then we'll need to save + the register on entry to this loop and restore the + register on exit from this loop. */ cost += border_costs.spill_inside_loop_cost (); if (hard_regno2 != hard_regno) cost -= border_costs.move_between_loops_cost ();