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: 1820331 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=oXEk+nKV; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMnqN4fn7z1yYC for ; Sat, 12 Aug 2023 01:32:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A26AE3858004 for ; Fri, 11 Aug 2023 15:32:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A26AE3858004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691767966; 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=oXEk+nKVuZq5FrOQW3FKGtvSYA+33eWhenH/b0mdTEJmGupcSBtlF25nYq5cVJU7y biIh4QasB8WjP68DbZKnxcXDdop5D/EXTvrc4DZAe2/dd2yO0fga2ilStOjwUNBj69 WFoh1u3ceMSYDHGgHKX7uWt+zi8GtjuahNOsnZiI= 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-Google-Smtp-Source: AGHT+IGn+AP1TfDSldmZYiN099knGnd0PTC742hAESdQ2H/O/T2FN9KBEMzPAz3WTZhgZbCzHmEAAw== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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; }