From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1880) id 3A9DF3858C53; Sat, 22 Oct 2022 07:23:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A9DF3858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666423411; bh=1pzAAdlo35fhDsHhfGHwWc22P9wn8IKpbhDcsmItZrc=; h=From:To:Subject:Date:From; b=RmTTsg/W5T/XmbL3dkn3w4ct4u0lyOpN27GaLukFIe6j8wvJtCS6fKAMOoPQfg1K0 zDLuP7RsWtx67JOGo9mz8no9c4HYlBOZSmlzwapjoatOHn7Hxzz1SQIpEe9de0GvgJ /VBJUUOA2PL/UbziRK45EujjKW2sJKnJ6/aopgQU= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Max Filippov To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3442] xtensa: Make register A0 allocable for the CALL0 ABI X-Act-Checkin: gcc X-Git-Author: Takayuki 'January June' Suwa X-Git-Refname: refs/heads/master X-Git-Oldrev: 1043971957af092e265cc4553b2382398d7308ae X-Git-Newrev: e0927d7ddca154b1a5151da698e205593cb8912e Message-Id: <20221022072331.3A9DF3858C53@sourceware.org> Date: Sat, 22 Oct 2022 07:23:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e0927d7ddca154b1a5151da698e205593cb8912e commit r13-3442-ge0927d7ddca154b1a5151da698e205593cb8912e Author: Takayuki 'January June' Suwa Date: Sat Oct 22 07:46:13 2022 +0900 xtensa: Make register A0 allocable for the CALL0 ABI This patch offers an additional allocable register by RA for the CALL0 ABI. > Register a0 holds the return address upon entry to a function, but > unlike the windowed register ABI, it is not reserved for this purpose > and may hold other values after the return address has been saved. - Xtensa ISA Reference Manual, 8.1.2 "CALL0 Register Usage and Stack Layout" [p.589] gcc/ChangeLog: * config/xtensa/xtensa.cc (xtensa_conditional_register_usage): Remove register A0 from FIXED_REGS if the CALL0 ABI. (xtensa_expand_epilogue): Change to emit '(use (reg:SI A0_REG))' unconditionally after restoring callee-saved registers for sibling-call functions, in order to prevent misleading that register A0 is free to use. Diff: --- gcc/config/xtensa/xtensa.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc index 950eb5a59be..94a98c25f8c 100644 --- a/gcc/config/xtensa/xtensa.cc +++ b/gcc/config/xtensa/xtensa.cc @@ -3471,15 +3471,14 @@ xtensa_expand_epilogue (bool sibcall_p) if (xtensa_call_save_reg(regno)) { rtx x = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset)); - rtx reg; offset -= UNITS_PER_WORD; - emit_move_insn (reg = gen_rtx_REG (SImode, regno), + emit_move_insn (gen_rtx_REG (SImode, regno), gen_frame_mem (SImode, x)); - if (regno == A0_REG && sibcall_p) - emit_use (reg); } } + if (sibcall_p) + emit_use (gen_rtx_REG (SImode, A0_REG)); if (cfun->machine->current_frame_size > 0) { @@ -4970,6 +4969,13 @@ xtensa_conditional_register_usage (void) /* Remove hard FP register from the preferred reload registers set. */ CLEAR_HARD_REG_BIT (reg_class_contents[(int)RL_REGS], HARD_FRAME_POINTER_REGNUM); + + /* Register A0 holds the return address upon entry to a function + for the CALL0 ABI, but unlike the windowed register ABI, it is + not reserved for this purpose and may hold other values after + the return address has been saved. */ + if (!TARGET_WINDOWED_ABI) + fixed_regs[A0_REG] = 0; } /* Map hard register number to register class */