From patchwork Sun Aug 18 13:28:19 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: 1973567 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=qtwVAQV1; dkim=pass header.d=gjlay.de header.i=@gjlay.de header.a=ed25519-sha256 header.s=strato-dkim-0003 header.b=jDllcatg; 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 4WmxQD2DKSz1yXf for ; Sun, 18 Aug 2024 23:28:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1450B386181E for ; Sun, 18 Aug 2024 13:28:45 +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 [85.215.255.21]) by sourceware.org (Postfix) with ESMTPS id 2B273385840C for ; Sun, 18 Aug 2024 13:28:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B273385840C 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 2B273385840C Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=85.215.255.21 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1723987706; cv=pass; b=PJDhglJF9qYnObAVsl+KOSDnV45l0+GTosDk9h4AjsPFgvo75Zw5A6mu+z7OmEz8/qlV5uG0ZbkM7DQT5rOFwwYeT0Op04/kWPWuYq+4yn3hELlrNOWELPVo5p90EOc9RRZd5uumLtIecPdzdNSg6r5QFnWN4TfR/hB597jSTdQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1723987706; c=relaxed/simple; bh=8uT1jRRhlF3N9gIhZFqfyUV+B8Qi4amvUGKQv18sPGA=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:From: To:Subject; b=vkbNKDlu7ujx8ldkv/M4e3XDpT6HicauQILS/1c2TopS5PoFwxqOf/gHO5G8lEcv9ELDlq2XYIRlrWeRXHwjIG9QcwYyLSpky7VYA+Za+DBa7YNsMTK6vCkK4V19S8F/jT5ir8oKfl86MU1L6UQQvk/q8ILpZEn2gK4R6Xi70i8= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1723987701; cv=none; d=strato.com; s=strato-dkim-0002; b=ByFvlsplPVex3LvERq/mNL8gCdeLIzSc0FT/vrt9tlhbw9Rx7S4vzd0L/e7hlp1Xw0 kpB7iuhUcLtKfYb2pW9hPj9JAMtEzGsBjnMN6mtoFBPkGsCqT0DRbDpLi/qe6VR2kEWa gqe/YzaCsbkNq+nf+MM1ztMBTxJ4mBEY/fYK5m83V61GiI652Ruddg5DNBI0N6wcO0b9 3ZIfkTPxKMJSIP/BpJ1D6+iWbDjvphTLvxFU7t7xtQBkOJyWYGjE2g3dGlc2epaI+oWH oKjglRifDBAV8MBq8t+UIsx2+u+fmmNnQFlCbH4Xu4la0W/SbIJKkPquJDY9u+F8vW+T /YxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1723987701; s=strato-dkim-0002; d=strato.com; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=8uT1jRRhlF3N9gIhZFqfyUV+B8Qi4amvUGKQv18sPGA=; b=BrFuuf5IXKzUTFdaHprN6IpPiBsqixSMEQwGMWrzNQBrGE3EPfENb+0ZP6KtkSHEKx btnAH+KSWYyktb6bhcvj1BW2gn1TE87n6J258f4oVM0+0/D0wItUGKn0Cfsr/s8eyhnt g+EGi/Gm6czQeb9z2h1ikCi5fO4seE4GijVNNtnQiOw/uGHMj35WA3ElZVtSJ5Xhcwa1 MjIZJpesTwqWWQOHBSBqCUrSnuH8JbxdAalxgqI5btrkxTmwpTwueMnlaDMzuisCWLTb WAbibo8nTa+7m+4B1htqERiH5L1uVdneCMNGB4qRGapJN4XnFQCRkaOgJ7hGXrya2QJR 0cdQ== 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=1723987701; s=strato-dkim-0002; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=8uT1jRRhlF3N9gIhZFqfyUV+B8Qi4amvUGKQv18sPGA=; b=qtwVAQV14I1ql/Y2Bg6DiEBqcCQ66AXLNF5S2ua426IUiVSbn0wLL1CjXZnpzUum/m mEmeGmP284UjTt3/tlq7FNbl3Bdho6KULh+jgZbEKT6j07km0umlVYhUNQRJCCRw/Yc1 nCJhVCiTfC4tg8ZUBG/SAHfSOmp5HfrhgnSVknXvC2CPAo9ob0yJjxUJDzM80mkzZnUJ a1eMOuGxcOMO0RmYcq+GiFgxK7p6Bc8neD0P3LSVms+Uc5SHouQxV9gNR0R3SPw5GtwN JCLEjDZulv9opyQ4jtV9VmMr6yNPRcP1IFjg5cxxQfQANgjp2IFTlN3T/mFnk503yFu1 H/Vw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1723987701; s=strato-dkim-0003; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=8uT1jRRhlF3N9gIhZFqfyUV+B8Qi4amvUGKQv18sPGA=; b=jDllcatgKUnNcTBtks9bXvamHEL3WE56Tve3DXt2sCIwTKNOvuINQDtcb2+c1X1G9G 3VYanskDVRXckSvNYGCw== X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKXKoq0dKoR0vetzhr/2IDlGFRklUq" Received: from [192.168.2.102] by smtp.strato.de (RZmta 51.2.3 DYNA|AUTH) with ESMTPSA id xccbe707IDSKBBl (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Sun, 18 Aug 2024 15:28:20 +0200 (CEST) Message-ID: Date: Sun, 18 Aug 2024 15:28:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Georg-Johann Lay Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Subject: [patch,avr,applied] Fix PR116407 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 fixes "relocation truncated to fit" errors from the linker due to bogus (too small) jump offsets. Johann AVR: target/116407 - Fix linker error "relocation truncated to fit". Some text peepholes output extra instructions prior to a branch instruction and that increase the jump offset of backward branches. PR target/116407 gcc/ * config/avr/avr-protos.h (avr_jump_mode): Add an int argument. * config/avr/avr.cc (avr_jump_mode): Add an int argument to increase the computed jump offset of backwards branches. * config/avr/avr.md (*dec-and-branchhi!=-1, *dec-and-branchsi!=-1): Increase the jump offset used by avr_jump_mode() as needed. gcc/testsuite/ * gcc.target/avr/torture/pr116407-2.c: New test. * gcc.target/avr/torture/pr116407-4.c: New test. diff --git a/gcc/config/avr/avr-protos.h b/gcc/config/avr/avr-protos.h index 7b666f17718..34298b976a7 100644 --- a/gcc/config/avr/avr-protos.h +++ b/gcc/config/avr/avr-protos.h @@ -115,7 +115,7 @@ 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 avr_jump_mode (rtx x, rtx_insn *insn); +extern int avr_jump_mode (rtx x, rtx_insn *insn, int = 0); 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 8c19bcb34a6..c520b98a178 100644 --- a/gcc/config/avr/avr.cc +++ b/gcc/config/avr/avr.cc @@ -4133,19 +4133,22 @@ avr_use_by_pieces_infrastructure_p (unsigned HOST_WIDE_INT size, /* Choose mode for jump insn: 1 - relative jump in range -63 <= x <= 62 ; 2 - relative jump in range -2046 <= x <= 2045 ; - 3 - absolute jump (only for ATmega[16]03). */ + 3 - absolute jump (only when we have JMP / CALL). + + When jumping backwards, assume the jump offset is EXTRA words + bigger than inferred from insn addresses. */ int -avr_jump_mode (rtx x, rtx_insn *insn) +avr_jump_mode (rtx x, rtx_insn *insn, int extra) { int dest_addr = INSN_ADDRESSES (INSN_UID (GET_CODE (x) == LABEL_REF ? XEXP (x, 0) : x)); int cur_addr = INSN_ADDRESSES (INSN_UID (insn)); int jump_distance = cur_addr - dest_addr; - if (IN_RANGE (jump_distance, -63, 62)) + if (IN_RANGE (jump_distance, -63, 62 - extra)) return 1; - else if (IN_RANGE (jump_distance, -2046, 2045)) + else if (IN_RANGE (jump_distance, -2046, 2045 - extra)) return 2; else if (AVR_HAVE_JMP_CALL) return 3; diff --git a/gcc/config/avr/avr.md b/gcc/config/avr/avr.md index 28841e40db1..8c4819a901f 100644 --- a/gcc/config/avr/avr.md +++ b/gcc/config/avr/avr.md @@ -7605,7 +7605,7 @@ (define_peephole ; "*dec-and-branchsi!=-1.d.clobber" "sbc %C0,__zero_reg__" CR_TAB "sbc %D0,__zero_reg__", operands); - int jump_mode = avr_jump_mode (operands[2], insn); + int jump_mode = avr_jump_mode (operands[2], insn, 3 - avr_adiw_reg_p (operands[0])); const char *op = ((EQ == ) ^ (jump_mode == 1)) ? "brcc" : "brcs"; operands[1] = gen_rtx_CONST_STRING (VOIDmode, op); @@ -7642,7 +7642,7 @@ (define_peephole ; "*dec-and-branchhi!=-1" output_asm_insn ("subi %A0,1" CR_TAB "sbc %B0,__zero_reg__", operands); - int jump_mode = avr_jump_mode (operands[2], insn); + int jump_mode = avr_jump_mode (operands[2], insn, 1 - avr_adiw_reg_p (operands[0])); const char *op = ((EQ == ) ^ (jump_mode == 1)) ? "brcc" : "brcs"; operands[1] = gen_rtx_CONST_STRING (VOIDmode, op); @@ -7681,7 +7681,7 @@ (define_peephole ; "*dec-and-branchhi!=-1.d.clobber" output_asm_insn ("subi %A0,1" CR_TAB "sbc %B0,__zero_reg__", operands); - int jump_mode = avr_jump_mode (operands[2], insn); + int jump_mode = avr_jump_mode (operands[2], insn, 1 - avr_adiw_reg_p (operands[0])); const char *op = ((EQ == ) ^ (jump_mode == 1)) ? "brcc" : "brcs"; operands[1] = gen_rtx_CONST_STRING (VOIDmode, op); @@ -7718,7 +7718,7 @@ (define_peephole ; "*dec-and-branchhi!=-1.l.clobber" "sub %A0,%3" CR_TAB "sbc %B0,__zero_reg__", operands); - int jump_mode = avr_jump_mode (operands[2], insn); + int jump_mode = avr_jump_mode (operands[2], insn, 1 - avr_adiw_reg_p (operands[0])); const char *op = ((EQ == ) ^ (jump_mode == 1)) ? "brcc" : "brcs"; operands[1] = gen_rtx_CONST_STRING (VOIDmode, op); diff --git a/gcc/testsuite/gcc.target/avr/torture/pr116407-2.c b/gcc/testsuite/gcc.target/avr/torture/pr116407-2.c new file mode 100644 index 00000000000..f580d129b5b --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/torture/pr116407-2.c @@ -0,0 +1,34 @@ +/* { dg-do link } */ + +typedef __UINT16_TYPE__ u16; +typedef __INT16_TYPE__ T; + +#ifdef __OPTIMIZE__ + +static __inline__ __attribute__((always_inline)) +void delay (T x, u16 nops) +{ + do + __builtin_avr_nops (nops); + while (--x != -1); +} + +#ifdef __AVR_HAVE_JMP_CALL__ + +void delay_2043 (T x) { delay (x, 2043); } +void delay_2044 (T x) { delay (x, 2044); } +void delay_2045 (T x) { delay (x, 2045); } +void delay_2046 (T x) { delay (x, 2046); } + +#endif /* have JUMP, CALL */ + +void delay_61 (T x) { delay (x, 61); } +void delay_62 (T x) { delay (x, 62); } +void delay_63 (T x) { delay (x, 63); } + +#endif /* optimize */ + +int main (void) +{ + return 0; +} diff --git a/gcc/testsuite/gcc.target/avr/torture/pr116407-4.c b/gcc/testsuite/gcc.target/avr/torture/pr116407-4.c new file mode 100644 index 00000000000..4347d85e552 --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/torture/pr116407-4.c @@ -0,0 +1,34 @@ +/* { dg-do link } */ + +typedef __UINT16_TYPE__ u16; +typedef __INT32_TYPE__ T; + +#ifdef __OPTIMIZE__ + +static __inline__ __attribute__((always_inline)) +void delay (T x, u16 nops) +{ + do + __builtin_avr_nops (nops); + while (--x != -1); +} + +#ifdef __AVR_HAVE_JMP_CALL__ + +void delay_2043 (T x) { delay (x, 2043); } +void delay_2044 (T x) { delay (x, 2044); } +void delay_2045 (T x) { delay (x, 2045); } +void delay_2046 (T x) { delay (x, 2046); } + +#endif /* have JUMP, CALL */ + +void delay_61 (T x) { delay (x, 61); } +void delay_62 (T x) { delay (x, 62); } +void delay_63 (T x) { delay (x, 63); } + +#endif /* optimize */ + +int main (void) +{ + return 0; +}