From patchwork Fri Aug 11 15:32:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 134561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1176853vqi; Fri, 11 Aug 2023 08:33:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnr7eX+WC365S9y7NUmn1+Qe/sfrIwvjfi6I9RFGnK9ry3ukGopqxDL97CrIJdKjaFvvax X-Received: by 2002:a05:6402:293:b0:523:bfec:4915 with SMTP id l19-20020a056402029300b00523bfec4915mr2092605edv.0.1691767991290; Fri, 11 Aug 2023 08:33:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691767991; cv=none; d=google.com; s=arc-20160816; b=URmpZUhSIN5pSsfqyepBWmdNFwIoeRW0g+jXHPF/f/CCIaFyz9Bx/XsOC+9X+bsztz plt0v3fdER0IwWcs1hjmhIR7+8VSgvPEqdghuCXzSW/Xfxp8rb5yZ6aILpi4gQmW8a+r CiHeIySKhhhePgNJROFnneuavDEQnqgPhUKYueemzkAKEjGFM3e8sKcsmCh8Hp2Bne3/ Tp8w/lk+5TM29DNQYqIUdKjNjem/QpQFUwdgodmwHY90ipdMnksw5nbPmnuKHm89WF8s eAxnLi0fCowxxFuDtfOpziP2ASF58N5bbbg3pCFA4Q1Bee6Th66xn6SdjdDbI6sRyl4Y zhtg== 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 :in-reply-to:to:references:subject:user-agent:mime-version:date :message-id:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=MCuyqH2EQtLYyTelVAexvqtNZtF2VJTPm1P8a46ptCU=; fh=0aQsLc0V92kpB4FRNib+nLWTzzLLCxCyMbdt3EjzZBE=; b=oQjuIG/Cmnf1BvgAeraVJjRVNwDxkRB9xE798WaxWxG5fUbQnin+W5m6E/jDk3Y8Me 3zijkKYyB3vyu1e2pUeaTsyVtoslLFCwlvDLHlW2oKYb+PbRJP66qpqHsQbVkY9VoQDG s9qMg/ryO+zUJ/Hw3e6c0wWmbWHZkV/UZLUyKZ1GMT9lIlfBzyCFycJ7xJLMfy6lgG4l nmz2PMSu+KsQ5anKQKsIV4pdYTj+qjKQ/JU2HWbcbMdpQPu7G1/WCZeGJ6GIwaZWDeTJ Mdvq+t2M8nI8/jX3qPQqBfFHwPjYDNB+0u8/+w1IWM5IPit99PaMsp/8bbXY91ljrskJ ATwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VXH88Vgi; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n10-20020a05640206ca00b005232ea6a33fsi3441464edy.18.2023.08.11.08.33.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:33:11 -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=VXH88Vgi; 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 F1BDC3858415 for ; Fri, 11 Aug 2023 15:33:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1BDC3858415 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691767990; bh=MCuyqH2EQtLYyTelVAexvqtNZtF2VJTPm1P8a46ptCU=; h=Date:Subject:References:To:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=VXH88VgiRXi8CjahLkw0ZyUGk6nqJeB8o3lfwILi93UNKUhYqt36flzm96RVley9x 0JVj30t58jU608gikunNdppps0kCOaSLDPpzdBtpYEUwHHqSsxjomskXbMELe7opH+ whKoPU4xQQMPuCU/hfywhWoA3OzVuB5Vufl03tRw= 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 949393858415 for ; Fri, 11 Aug 2023 15:32:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 949393858415 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-532-JO760tR5PYeitEax4No_fQ-1; Fri, 11 Aug 2023 11:32:24 -0400 X-MC-Unique: JO760tR5PYeitEax4No_fQ-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-63d1bd6dfebso27574326d6.1 for ; Fri, 11 Aug 2023 08:32:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691767941; x=1692372741; h=in-reply-to:from:to:references:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=adMWJf2zZfG9DnQjo9LLX77TYRhSaEf/f4a6L2CjL6A=; b=YffR4653jG6YxFTGJZC04ikofr1eUG7uX9vFWldJTFI94RicVMDtVOl+ukD44o+q+0 1rFy7jU/U0CKutsuLxvuShNa+tykbbVMZ28DmLPhTapTzkcJnKFu1vt8mLVdLC+8HX/f urNVsp3wADBadgCLquAs9UP7izqEcIZLcJKNMoeXLJYca1MKd/C4A2noqz0IzeCy47rT +jrD/Fbd4U5Jb0etRasDy6NO4HK9KdIX8zBxGDYtCm/es1Pt/X/MqoWqpBIJ9Nz8fPFh BkdecWhI6coHzBiHpcNTiYt6TacPWyMPwCBuUiKRB1k+ueN5GBkGpxvnPqX8SfMPreRT BRXw== X-Gm-Message-State: AOJu0YxNbsDB7zDClpAmOWfUt0cybafxAUsjZxiNQjlQvArOaaFkwyG5 solbedQm7KK3HgunI8BbUhJSi4iiPDPwemHFPPBK+E3egt+mMIuCYowNNMnLRSX8lkRaSmuOpgo YGqIqyeObKVYZGXtTt+/D2pm1kqn+V8ixtsI19N8NcBsaSJVvBdC97vAS//NwSepxE51qdkZSun 2nqg== X-Received: by 2002:a05:620a:394a:b0:76c:a8a2:aad2 with SMTP id qs10-20020a05620a394a00b0076ca8a2aad2mr2249433qkn.34.1691767941339; Fri, 11 Aug 2023 08:32:21 -0700 (PDT) X-Received: by 2002:a05:620a:394a:b0:76c:a8a2:aad2 with SMTP id qs10-20020a05620a394a00b0076ca8a2aad2mr2249412qkn.34.1691767940999; Fri, 11 Aug 2023 08:32:20 -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 h3-20020a37c443000000b0076825e43d98sm1249124qkm.125.2023.08.11.08.32.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Aug 2023 08:32:20 -0700 (PDT) Message-ID: <8eda93dc-9cf8-c221-0f37-4cd604cc8808@redhat.com> Date: Fri, 11 Aug 2023 11:32:19 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: [pushed][LRA]: Implement output stack pointer reloads References: To: "gcc-patches@gcc.gnu.org" In-Reply-To: X-Forwarded-Message-Id: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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: INBOX X-GMAIL-THRID: 1773946267057357244 X-GMAIL-MSGID: 1773947312786037584 Sorry, I had some problems with email.  Therefore there are email duplication and they were sent to gcc@gcc.gnu.org instead of gcc-patches@gcc.gnu.org On 8/9/23 16:54, Vladimir Makarov wrote: > > On 8/9/23 07:15, SenthilKumar.Selvaraj@microchip.com wrote: >> Hi, >> >>    After turning on FP -> SP elimination after Vlad fixed >>    an elimination issue in >> https://gcc.gnu.org/git?p=gcc.git;a=commit;h=2971ff7b1d564ac04b537d907c70e6093af70832, >>    I'm now running into reload failure if arithmetic is done on SP. >> > I think we can permit to stack pointer output reloads.  The only thing > we need to update sp offset accurately for the original and reload > insns.  I'll try to make the patch on this week. > > The following patch fixes the problem.  The patch was successfully bootstrapped and tested on x86_64, aarch64, and ppc64le. The test case is actually one from GCC test suite. commit c0121083d07ffd4a8424f4be50de769d9ad0386d Author: Vladimir N. Makarov Date: Fri Aug 11 07:57:37 2023 -0400 [LRA]: Implement output stack pointer reloads LRA prohibited output stack pointer reloads but it resulted in LRA failure for AVR target which has no arithmetic insns working with the stack pointer register. Given patch implements the output stack pointer reloads. gcc/ChangeLog: * lra-constraints.cc (goal_alt_out_sp_reload_p): New flag. (process_alt_operands): Set the flag. (curr_insn_transform): Modify stack pointer offsets if output stack pointer reload is generated. diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc index 09ff6de1657..26239908747 100644 --- a/gcc/lra-constraints.cc +++ b/gcc/lra-constraints.cc @@ -1466,6 +1466,8 @@ static int goal_alt_dont_inherit_ops[MAX_RECOG_OPERANDS]; static bool goal_alt_swapped; /* The chosen insn alternative. */ static int goal_alt_number; +/* True if output reload of the stack pointer should be generated. */ +static bool goal_alt_out_sp_reload_p; /* True if the corresponding operand is the result of an equivalence substitution. */ @@ -2128,6 +2130,9 @@ process_alt_operands (int only_alternative) int curr_alt_dont_inherit_ops_num; /* Numbers of operands whose reload pseudos should not be inherited. */ int curr_alt_dont_inherit_ops[MAX_RECOG_OPERANDS]; + /* True if output stack pointer reload should be generated for the current + alternative. */ + bool curr_alt_out_sp_reload_p; rtx op; /* The register when the operand is a subreg of register, otherwise the operand itself. */ @@ -2211,7 +2216,8 @@ process_alt_operands (int only_alternative) } reject += static_reject; early_clobbered_regs_num = 0; - + curr_alt_out_sp_reload_p = false; + for (nop = 0; nop < n_operands; nop++) { const char *p; @@ -2682,12 +2688,10 @@ process_alt_operands (int only_alternative) bool no_regs_p; reject += op_reject; - /* Never do output reload of stack pointer. It makes - impossible to do elimination when SP is changed in - RTL. */ - if (op == stack_pointer_rtx && ! frame_pointer_needed + /* Mark output reload of the stack pointer. */ + if (op == stack_pointer_rtx && curr_static_id->operand[nop].type != OP_IN) - goto fail; + curr_alt_out_sp_reload_p = true; /* If this alternative asks for a specific reg class, see if there is at least one allocatable register in that class. */ @@ -3317,6 +3321,7 @@ process_alt_operands (int only_alternative) for (nop = 0; nop < curr_alt_dont_inherit_ops_num; nop++) goal_alt_dont_inherit_ops[nop] = curr_alt_dont_inherit_ops[nop]; goal_alt_swapped = curr_swapped; + goal_alt_out_sp_reload_p = curr_alt_out_sp_reload_p; best_overall = overall; best_losers = losers; best_reload_nregs = reload_nregs; @@ -4836,6 +4841,27 @@ curr_insn_transform (bool check_only_p) lra_asm_insn_error (curr_insn); } lra_process_new_insns (curr_insn, before, after, "Inserting insn reload"); + if (goal_alt_out_sp_reload_p) + { + /* We have an output stack pointer reload -- update sp offset: */ + rtx set; + bool done_p = false; + poly_int64 sp_offset = curr_id->sp_offset; + for (rtx_insn *insn = after; insn != NULL_RTX; insn = NEXT_INSN (insn)) + if ((set = single_set (insn)) != NULL_RTX + && SET_DEST (set) == stack_pointer_rtx) + { + lra_assert (!done_p); + curr_id->sp_offset = 0; + lra_insn_recog_data_t id = lra_get_insn_recog_data (insn); + id->sp_offset = sp_offset; + if (lra_dump_file != NULL) + fprintf (lra_dump_file, + " Moving sp offset from insn %u to %u\n", + INSN_UID (curr_insn), INSN_UID (insn)); + } + lra_assert (!done_p); + } return change_p; }