From patchwork Sun Mar 3 17:15:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 1907299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gjlay.de header.i=@gjlay.de header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=YDSv85+o; dkim=pass header.d=gjlay.de header.i=@gjlay.de header.a=ed25519-sha256 header.s=strato-dkim-0003 header.b=kZ9ZRaWk; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TnpPP2ytCz23fC for ; Mon, 4 Mar 2024 04:15:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C17F53858282 for ; Sun, 3 Mar 2024 17:15:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.216]) by sourceware.org (Postfix) with ESMTPS id 31EA33858420 for ; Sun, 3 Mar 2024 17:15:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 31EA33858420 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gjlay.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gjlay.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 31EA33858420 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=81.169.146.216 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1709486115; cv=pass; b=H9D2qyl29oT/E+ITPwjGOCFTJHRuPc7RItDDurrrnX++ackd5A9tpXislhpvnuKgVCGLkMqI6YeoGeC4LnZzq5gQ/1jRTX7RVoJpc3TxWdv+q8OJYszmSnYLC7rs627+IO9RTkfWb5iG4bgS0q1v4flMgHwfVjTpXGFH+nDDbkI= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1709486115; c=relaxed/simple; bh=a9IruSdUD17geEUFnZUlwldEBvvEx1mCo4USbu2sl+0=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:From: To:Subject; b=CIl+kbEakWq4QsAazi0io8MMPHYLe09BlP3yfpqZKkhfc45/cj1q9jWkKp4HLNnhp+x5bAG20ZmakSjk5bWeUGq5ZtMOwqnJbDaHgkr24ns2banN0Z4ipbI/irZAtH/6nBPYedXqxkBE9oBSNGATLgqhEBXOfeCeOXlSIizufCc= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1709486111; cv=none; d=strato.com; s=strato-dkim-0002; b=UCU+7QwxrEaRB/3SK4OY+b2tQ2URvNrc8/k/BTQ6AniP15S//pwcjlf2ssL3/6H67m ezlt/LQEk9YzXSJPjeVlCWeU9KvJbylvMMoHNWr8ANiwlygQwjWi07lhWJeleLxiGw5X iYmKO698DfvWhRZh8P5MeKhztNtpwuW/T7DtLuC3m0nzmcr99jFpWoQXbm6fH/1niUzU 5RcTuIMebqIu1wT/E9IrxQC36fVUy6sA5S5C/uaL/BqUgB+OMh+p600bP3EcHk5Ug11p 5OW6Hu567ws3QK2H2JqPQ5EW1eotJRfcmZopygfpJ11/Q98JiNjQBn6Jv2ytycxUMYFy +UYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1709486111; s=strato-dkim-0002; d=strato.com; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=xrAkEJIpDD9XzV0bmITdx1NSiX4sPd+LEjLxftJnIxc=; b=hmgi8y9crIYOp4jyQno2n0D3gwIga1y1DQIBuzz088pXic+Xu1/ZVoFzSbIC9R9hb5 B2jXwvmEfD1nfbl+TxxBrkgvxNY6xRh+5v1mQ2ScfHdmCoIUAJdVw7GIDmjNHOBvTS05 ZwYTVCrmlSQaK2NDPjSYS3VNNhRQ5cEIAEwtaTpKw3AmnUW/e1jmnGSp6XpoVGDjaHom 9yPzByGhp47I5tp2fSRhWYhtsb20dygeS5jlgUrYT1xcSP2VvWSpO8Qf+VYqBtO/ILqs Lbyltz82GJlXNsilMBWcjJJMwdElB6YxrGomQX+FEBkUfB7k3PjGqqzu9z30Mr4n1Y49 cdqg== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1709486111; s=strato-dkim-0002; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=xrAkEJIpDD9XzV0bmITdx1NSiX4sPd+LEjLxftJnIxc=; b=YDSv85+ocltQoBUO1+xyGqstqRPo4V99f4rxz310s1CcjAvBViJP9m4FB9LwsU5fvQ nYqKAHNl5T1qGAX7J+xH1uwudrC3W7gveoIfWcy9nPkTX03yZvQjKwMlwTM1vtCQjGBE lLLx3zrYdzFUxUoXTzeWi7d4VguJ8u3s+oNqC5gcFpCtMdFpkltwxJyvXJp5wqYbBEmd a/jCMyuNbULtm6elN1uhwN/n6WhENdef3DdPBBhzLnHkLnaKSPdmQ0z1gUn4bLNhdamP I8/RsGS6ImRhWkdNewx5FJ04Ds4Jjq02WoOvBI7z16GYPLUCaOrCAUCPhJcYVtQQrtvN vn0Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1709486111; s=strato-dkim-0003; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=xrAkEJIpDD9XzV0bmITdx1NSiX4sPd+LEjLxftJnIxc=; b=kZ9ZRaWk86tk9jrD8hnudi4cvci7R1EVx4145hQ8esLWa1CQuFXXkER6c21HV4diwQ 3Tbr9/3crrIJVNM1NZBQ== X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkSgcSjpmy9KwoMJ/K0VA==" Received: from [192.168.2.102] by smtp.strato.de (RZmta 50.2.0 DYNA|AUTH) with ESMTPSA id Jdfd10023HFB6tk (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Sun, 3 Mar 2024 18:15:11 +0100 (CET) Message-ID: Date: Sun, 3 Mar 2024 18:15:10 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Georg-Johann Lay To: "gcc-patches@gcc.gnu.org" Subject: [avr,patch,applied] ad target/114100 - Don't print unused frame pointer adjustments. X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This addendum ports a corner case optimization from -mno-fuse-add to -mfuse-add: When a base register needs temporal adjustment, and the base is the frame pointer, then there are cases where the post-adjustment is not needed. Passes without new regressions on ATtiny40. Johann --- AVR: ad target/114100 - Don't print unused frame pointer adjustments. Without -mfuse-add, when fake reg+offset addressing is used, the output routines are saving some instructions when the base reg is unused after. This patch adds that optimization for the case when the base is the frame pointer and the frame pointer adjustments are split away from the move insn by -mfuse-add in .split2. Direct usage of reg_unused_after is not possible because that function looks at the destination of the current insn, which won't work for offsetting the frame pointer in printing PLUS code. It can use an extended version of _reg_unused_after though. gcc/ PR target/114100 * config/avr/avr-protos.h (_reg_unused_after): Remove proto. * config/avr/avr.cc (_reg_unused_after): Make static. And add 3rd argument to skip the current insn. (reg_unused_after): Adjust call of reg_unused_after. (avr_out_plus_1) [AVR_TINY && -mfuse-add >= 2]: Don't output unneeded frame pointer adjustments. diff --git a/gcc/config/avr/avr-protos.h b/gcc/config/avr/avr-protos.h index f4f3ffd8f28..3e19409d636 100644 --- a/gcc/config/avr/avr-protos.h +++ b/gcc/config/avr/avr-protos.h @@ -110,7 +110,6 @@ extern const char* avr_out_reload_inpsi (rtx*, rtx, int*); extern const char* avr_out_lpm (rtx_insn *, rtx*, int*); extern void avr_notice_update_cc (rtx body, rtx_insn *insn); extern int reg_unused_after (rtx_insn *insn, rtx reg); -extern int _reg_unused_after (rtx_insn *insn, rtx reg); extern int avr_jump_mode (rtx x, rtx_insn *insn); extern int test_hard_reg_class (enum reg_class rclass, rtx x); extern int jump_over_one_insn_p (rtx_insn *insn, rtx dest); diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc index 44d6e141b62..7df21432dda 100644 --- a/gcc/config/avr/avr.cc +++ b/gcc/config/avr/avr.cc @@ -163,6 +163,7 @@ static int avr_operand_rtx_cost (rtx, machine_mode, enum rtx_code, int, bool); static void output_reload_in_const (rtx *, rtx, int *, bool); static struct machine_function *avr_init_machine_status (void); +static int _reg_unused_after (rtx_insn *insn, rtx reg, bool look_at_insn); /* Prototypes for hook implementors if needed before their implementation. */ @@ -8825,7 +8826,7 @@ lshrsi3_out (rtx_insn *insn, rtx operands[], int *len) fixed-point rounding, cf. `avr_out_round'. */ static void -avr_out_plus_1 (rtx /*insn*/, rtx *xop, int *plen, enum rtx_code code, +avr_out_plus_1 (rtx insn, rtx *xop, int *plen, enum rtx_code code, enum rtx_code code_sat, int sign, bool out_label) { /* MODE of the operation. */ @@ -8973,6 +8974,10 @@ avr_out_plus_1 (rtx /*insn*/, rtx *xop, int *plen, enum rtx_code code, && frame_pointer_needed && REGNO (xop[0]) == FRAME_POINTER_REGNUM) { + if (INSN_P (insn) + && _reg_unused_after (as_a (insn), xop[0], false)) + return; + if (AVR_HAVE_8BIT_SP) { avr_asm_len ("subi %A0,%n2", xop, plen, 1); @@ -10818,31 +10823,32 @@ int reg_unused_after (rtx_insn *insn, rtx reg) { return (dead_or_set_p (insn, reg) - || (REG_P (reg) && _reg_unused_after (insn, reg))); + || (REG_P (reg) && _reg_unused_after (insn, reg, true))); } -/* Return nonzero if REG is not used after INSN. +/* A helper for the previous function. + Return nonzero if REG is not used after INSN. We assume REG is a reload reg, and therefore does not live past labels. It may live past calls or jumps though. */ int -_reg_unused_after (rtx_insn *insn, rtx reg) +_reg_unused_after (rtx_insn *insn, rtx reg, bool look_at_insn) { - enum rtx_code code; - rtx set; - - /* If the reg is set by this instruction, then it is safe for our - case. Disregard the case where this is a store to memory, since - we are checking a register used in the store address. */ - set = single_set (insn); - if (set && !MEM_P (SET_DEST (set)) - && reg_overlap_mentioned_p (reg, SET_DEST (set))) - return 1; + if (look_at_insn) + { + /* If the reg is set by this instruction, then it is safe for our + case. Disregard the case where this is a store to memory, since + we are checking a register used in the store address. */ + rtx set = single_set (insn); + if (set && !MEM_P (SET_DEST (set)) + && reg_overlap_mentioned_p (reg, SET_DEST (set))) + return 1; + } while ((insn = NEXT_INSN (insn))) { rtx set; - code = GET_CODE (insn); + enum rtx_code code = GET_CODE (insn); #if 0 /* If this is a label that existed before reload, then the register