From patchwork Tue May 30 20:05:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 101093 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2430390vqr; Tue, 30 May 2023 13:06:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Ey8NmxUGOxlzfjtXb0+58i6/MiHlhUvkqy6tzBheiKVkKGCbsPHimwzDmVyR9MoseimMB X-Received: by 2002:a17:907:1b21:b0:974:76:dcdd with SMTP id mp33-20020a1709071b2100b009740076dcddmr3671916ejc.55.1685477208014; Tue, 30 May 2023 13:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685477208; cv=none; d=google.com; s=arc-20160816; b=KDqvetsAsOuZg6yfW02QMdDdaBY+H40OgrRJh6/tTqxFQdfQEurZveJf7HJ7HsE9Jf og4T3op2wFFM0rlCQlySq+yCTvdkLq9x0oLzXEesCKG/KanussOgYu1HVSfD1VjRhC00 AQ+mEI3IQ6dW4G+QuK3C7zcF5x4sZ1gpi30Upz7nXSDvOY+M5LBnb+tJVZW8Dca+5LSu 6xh+NhIf1a/VKvzWZ9QspdbsKckCOzOWEI41+UtDZckR5PYaPyRT1zn0AnAUOJvk4V4s PFpyTDcyNMvmy2SPxpA4auMQKFFFb/HJtwjTO4G9kz51LHF25vOSBR+O1jezPAZk4sG4 sraA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:content-language :subject:cc:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=d8Ri4Eb6F8IkNwSRTeWuwkGwv5X/Gd/SGGmV8zHx4pI=; b=vH8Pla2Szu2aBvOKskLYEKyoCZYwW5VqMj3N0bUrnFDE3ySsDjdKzsEMknHeHy0702 PZvoNQwlKHW7ncD1XrMQIu8eHzYlWFXmW+/JT0Nw/p/vm8E+WTq1CZsa0wf9q+ZW2MN+ ap57F3FSQmVAT7hpyjYht+xcZIDI+JAM9wOh+K91SocXDynYTfkKveXtkAOrgjT3YzzH Npk3ykU1dZyyf/JRLbC+HHfKwQFyWqkPd4MR0PgfzrUYQxr8XO7yMigcSh7EWWv9xAp1 n8tmWEIERj8yhvMLgkoSM/tZ8YD9CeIlbfmnAPk7lZjI+zwkkT+rDDLvLLEt756egosi ZYMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RMXG8Lrk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k22-20020a170906971600b00965ff948233si1233979ejx.1035.2023.05.30.13.06.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 13:06:47 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RMXG8Lrk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C6C1038558A4 for ; Tue, 30 May 2023 20:06:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C6C1038558A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685477178; bh=d8Ri4Eb6F8IkNwSRTeWuwkGwv5X/Gd/SGGmV8zHx4pI=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=RMXG8LrkRz+9W7LQlqjhDbB6KFmap+X6PH/V1Ev6W9Z6FzvNlLwiKOGsI/E0kZ09X l2TKYfAH4V/PuzabfMo8bb0WPlgBp+YO0+1Nx1PPdT1Upm7f+/LBlxIsC6Y8+FR2JP sxB9jPXI570+AYTyZtpD4rMM8EL1aMVg/vYRClz4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 678813856621 for ; Tue, 30 May 2023 20:05:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 678813856621 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-586-KUV0vukgM7ewvoJKSk9D4w-1; Tue, 30 May 2023 16:05:11 -0400 X-MC-Unique: KUV0vukgM7ewvoJKSk9D4w-1 Received: by mail-io1-f69.google.com with SMTP id ca18e2360f4ac-760c58747cdso656200339f.0 for ; Tue, 30 May 2023 13:05:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685477109; x=1688069109; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9jBn5vCliuzVNqQ8IxeDLr2UNZmmUqtdVnBZ3YoC/WU=; b=kNTCv1LcqFewWhQJ63RlLuJw/fJuCY36APgkXfrXtdoFsu/v5KNBBsO6nTxFepL9Q1 Wc4tUwY7cArqSSiZZ8hnGGQDBKpejWrjA+aHKs0+vss0QIkxlS/otItL8LBtfb12yjNY BnJ2QtE3AdSppw9d3TTVY2Uj67dp81qAlDfZczBoo+kOde0ZO6idFrlWpBL8KEvtgG4D 3S/mXuwxJqBHXgEpMfUOmXkh9S6DguK2gjInwN/t8AhFPFD2fDYyS5Nd9miw1Pdj2nr5 NKfHsQN54idSLEpxYhVEkQoQpkkS3U02orLEeEuvnB2yxOgpC7ynadhG6E+cmHr0JrPU oDug== X-Gm-Message-State: AC+VfDz9D94DwokVcywX9NEYilBS5ypxpXqJ7wSLzr7VWatX0VYUVcYC pvLdF6aGP2HGVa0ldOOASacEncajZ6U9GStklWOfc+76dJ8/g5DdUyUshhiBaO8aXjG5tBXHiZc MTncAor5drqydyi679qmHc6R15Cb+vtmKMk/0rBo4GFjN9wRgzIiBdKhtksrzTLlnvJGkjQgtE7 VOzA== X-Received: by 2002:a5d:9c96:0:b0:76c:53ab:22ab with SMTP id p22-20020a5d9c96000000b0076c53ab22abmr2413491iop.17.1685477108948; Tue, 30 May 2023 13:05:08 -0700 (PDT) X-Received: by 2002:a5d:9c96:0:b0:76c:53ab:22ab with SMTP id p22-20020a5d9c96000000b0076c53ab22abmr2413481iop.17.1685477108612; Tue, 30 May 2023 13:05:08 -0700 (PDT) Received: from [192.168.1.88] (192-0-143-139.cpe.teksavvy.com. [192.0.143.139]) by smtp.gmail.com with ESMTPSA id s6-20020a5eaa06000000b007079249a9d1sm3370837ioe.34.2023.05.30.13.05.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 May 2023 13:05:06 -0700 (PDT) Message-ID: Date: Tue, 30 May 2023 16:05:05 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: "gcc-patches@gcc.gnu.org" Cc: Jeff Law Subject: [pushed] LRA: Update insn sp offset if its input reload changes SP X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Vladimir Makarov via Gcc-patches From: Vladimir Makarov Reply-To: Vladimir Makarov Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767350948871470413?= X-GMAIL-MSGID: =?utf-8?q?1767350948871470413?= The following patch fixes an LRA bug triggered by switching H8300 target from reload to LRA.  The description of the problem is in the commit message. The patch was successfully bootstrapped and tested on x86-64, aarch64, and ppc64le. commit 30038a207c10a2783fa2695b62c7c8458ef05e73 Author: Vladimir N. Makarov Date: Tue May 30 15:54:28 2023 -0400 LRA: Update insn sp offset if its input reload changes SP The patch fixes a bug when there is input reload changing SP. The bug was triggered by switching H8300 target to LRA. The insn in question is (insn 21 20 22 2 (set (mem/f:SI (pre_dec:SI (reg/f:SI 7 sp)) [3 S4 A32]) (reg/f:SI 31)) "j.c":10:3 19 {*movsi} (expr_list:REG_DEAD (reg/f:SI 31) (expr_list:REG_ARGS_SIZE (const_int 4 [0x4]) (nil)))) The memory address is reloaded but the SP offset for the original insn was not updated. gcc/ChangeLog: * lra-int.h (lra_update_sp_offset): Add the prototype. * lra.cc (setup_sp_offset): Change the return type. Use lra_update_sp_offset. * lra-eliminations.cc (lra_update_sp_offset): New function. (lra_process_new_insns): Push the current insn to reprocess if the input reload changes sp offset. diff --git a/gcc/lra-eliminations.cc b/gcc/lra-eliminations.cc index 42206366669..68225339cb6 100644 --- a/gcc/lra-eliminations.cc +++ b/gcc/lra-eliminations.cc @@ -1308,6 +1308,16 @@ init_elimination (void) setup_elimination_map (); } +/* Update and return stack pointer OFFSET after processing X. */ +poly_int64 +lra_update_sp_offset (rtx x, poly_int64 offset) +{ + curr_sp_change = offset; + mark_not_eliminable (x, VOIDmode); + return curr_sp_change; +} + + /* Eliminate hard reg given by its location LOC. */ void lra_eliminate_reg_if_possible (rtx *loc) diff --git a/gcc/lra-int.h b/gcc/lra-int.h index a400a0f85e2..4dbe6672f3a 100644 --- a/gcc/lra-int.h +++ b/gcc/lra-int.h @@ -412,6 +412,7 @@ extern rtx lra_eliminate_regs_1 (rtx_insn *, rtx, machine_mode, extern void eliminate_regs_in_insn (rtx_insn *insn, bool, bool, poly_int64); extern void lra_eliminate (bool, bool); +extern poly_int64 lra_update_sp_offset (rtx, poly_int64); extern void lra_eliminate_reg_if_possible (rtx *); diff --git a/gcc/lra.cc b/gcc/lra.cc index eb3ee1f8b63..c8b3f139acd 100644 --- a/gcc/lra.cc +++ b/gcc/lra.cc @@ -1838,10 +1838,10 @@ push_insns (rtx_insn *from, rtx_insn *to) lra_push_insn (insn); } -/* Set up sp offset for insn in range [FROM, LAST]. The offset is +/* Set up and return sp offset for insns in range [FROM, LAST]. The offset is taken from the next BB insn after LAST or zero if there in such insn. */ -static void +static poly_int64 setup_sp_offset (rtx_insn *from, rtx_insn *last) { rtx_insn *before = next_nonnote_nondebug_insn_bb (last); @@ -1849,7 +1849,11 @@ setup_sp_offset (rtx_insn *from, rtx_insn *last) ? 0 : lra_get_insn_recog_data (before)->sp_offset); for (rtx_insn *insn = from; insn != NEXT_INSN (last); insn = NEXT_INSN (insn)) - lra_get_insn_recog_data (insn)->sp_offset = offset; + { + lra_get_insn_recog_data (insn)->sp_offset = offset; + offset = lra_update_sp_offset (PATTERN (insn), offset); + } + return offset; } /* Emit insns BEFORE before INSN and insns AFTER after INSN. Put the @@ -1875,8 +1879,25 @@ lra_process_new_insns (rtx_insn *insn, rtx_insn *before, rtx_insn *after, if (cfun->can_throw_non_call_exceptions) copy_reg_eh_region_note_forward (insn, before, NULL); emit_insn_before (before, insn); + poly_int64 old_sp_offset = lra_get_insn_recog_data (insn)->sp_offset; + poly_int64 new_sp_offset = setup_sp_offset (before, PREV_INSN (insn)); + if (maybe_ne (old_sp_offset, new_sp_offset)) + { + if (lra_dump_file != NULL) + { + fprintf (lra_dump_file, " Changing sp offset from "); + print_dec (old_sp_offset, lra_dump_file); + fprintf (lra_dump_file, " to "); + print_dec (new_sp_offset, lra_dump_file); + fprintf (lra_dump_file, " for insn"); + dump_rtl_slim (lra_dump_file, insn, NULL, -1, 0); + } + lra_get_insn_recog_data (insn)->sp_offset = new_sp_offset; + eliminate_regs_in_insn (insn, false, false, + old_sp_offset - new_sp_offset); + lra_push_insn (insn); + } push_insns (PREV_INSN (insn), PREV_INSN (before)); - setup_sp_offset (before, PREV_INSN (insn)); } if (after != NULL_RTX) {