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: 209330 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1010492dyc; Sun, 3 Mar 2024 09:15:55 -0800 (PST) X-Forwarded-Encrypted: i=4; AJvYcCUZxo8ChrgJxN0xYBM1AYY5yyvNh4N+HoCIBvD9YSKlV1Q0R0Z2q9YnxkK2AQ9aeiXpbCqOQEmVJG9cVvXHNI/U5wfHtw== X-Google-Smtp-Source: AGHT+IFVEV9XHjTdExHEJ/DI93cj+Rme0SIEkfGPzOKg5ssyf89P1qVnK5KkER4RlsMN7auXqO+a X-Received: by 2002:a05:6102:5f75:b0:472:c7d9:dfcd with SMTP id ix21-20020a0561025f7500b00472c7d9dfcdmr296759vsb.9.1709486155482; Sun, 03 Mar 2024 09:15:55 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1709486155; cv=pass; d=google.com; s=arc-20160816; b=za7pnJzu6ojnx7Z+6oIz1V+6N8nmYL4Di+zCBaga7IMwy6ad87zXuzcVY6gEgGHZmz IL2EOJ4k4HFcT++AsYjxn7vJltpq2LX1VF0Z0USGU6fkX2TIpUL1SkLJT+G9edLRSrON dEwLjd8cTmevhVQIcCTjpd8vQhWlKbsm2JXK/TjB3oAJYYUYepPQw8g6DPHVUtd+bHiy 6rh8OxRnIQjxi21uRoFNjBbGfc+/4yn6Ig+J1Myh7hCX5AlVqZlTeWAG3lOu34bYzHin vpAPYzPe3lYk28NkJ96S13Nb9eDGGvajRP8vbWGnOaTpO1cPnrp1X/8o/5VcLnnD4CMI 9h0w== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :subject:to:from:content-language:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature:arc-filter:dmarc-filter :delivered-to; bh=xrAkEJIpDD9XzV0bmITdx1NSiX4sPd+LEjLxftJnIxc=; fh=XNn3asQvIblazGK92GBt13dVv+YmGV3pBS0JC29ZQco=; b=kp5D0XWi4lZ0D9jwZHQMGuyQJR5cHRGvCVELKtSl2fvbzvT2zYlM3pp3Spj4SYX8Gp bF9MVsCOBLfivKzMYI61tRikU/RX0JgV0rFwua5J7X1IV8COloL7JlDF5JkD1x2r9FQ7 Btiyw18UOa84iRwOlFYgnubvg9Hwtm4N7UyQ44KMCgkjQPpxrdRY50ZIXBPVZPTmcG6x DGIbRF1rGrVE0muOak8oOodRlEGrhaRDXCzDwLCXGqhGdLQkGkO3hnzTv7X41T+8qcd6 jFckFJFwSsIKbaQwYNlP5L8FvZvQOoiAxhsMJkQ+gv9prPXp4KpIh/c55NXHJeOtbPX1 Jw5Q==; dara=google.com ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@gjlay.de header.s=strato-dkim-0002 header.b=YDSv85+o; dkim=neutral (no key) header.i=@gjlay.de header.s=strato-dkim-0003; arc=pass (i=2); 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id by5-20020a056102504500b00470735c7ecesi1024510vsb.250.2024.03.03.09.15.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 09:15:54 -0800 (PST) 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=@gjlay.de header.s=strato-dkim-0002 header.b=YDSv85+o; dkim=neutral (no key) header.i=@gjlay.de header.s=strato-dkim-0003; arc=pass (i=2); 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 39A89385842B for ; Sun, 3 Mar 2024 17:15:54 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792526153731586052 X-GMAIL-MSGID: 1792526153731586052 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