On Wed, Jun 15, 2022 at 5:23 AM Takayuki 'January June' Suwa
<jjsuwa_sys3...@yahoo.co.jp> wrote:
>
> On 2022/06/15 5:17, Max Filippov wrote:
> > Hi Suwa-san,
> hi!
>
> > This change results in a bunch of new regression test failures:
> > The code generated for e.g. gcc.c-torture/execute/921208-2.c looks like 
> > this:
> oh, PICed...
>
> indirect (incl. via function pointer, virtual functions and of course PIC 
> ones in Xtensa ISA) sibcalls must be avoided if pointer to the target cannot 
> be retained during function epilogue.
> otherwise, it will be look like this:
> >       callx0  a14
> >       l32i.n  a0, sp, 12
> >       l32i.n  a14, sp, 0      // restored by the epilogue because A14 is 
> > callee-saved
> >       mov.n   a4, a12
> >       mov.n   a5, a13
> >       l32i.n  a12, sp, 8
> >       l32i.n  a13, sp, 4
> >       l32r    a3, .LC4
> >       movi.n  a2, 0
> >       addi    sp, sp, 16
> >       jx      a14             // but A14 pointed to g@PLT in this 
> > function...
>
> luckily, no role is assigned from A9 to A11 in call0 ABI (A9 is already used 
> inside of the pro/epilogue), and the "split2" stage is prior to 
> "pro_and_epilogue"...
>
> ===
> This patch introduces support for sibling call optimization, when call0
> ABI is in effect.
>
> gcc/ChangeLog:
>
>         * config/xtensa/xtensa-protos.h (xtensa_prepare_expand_call,
>         xtensa_emit_sibcall): New prototypes.
>         (xtensa_expand_epilogue): Add new argument that specifies whether
>         or not sibling call.
>         * config/xtensa/xtensa.cc (TARGET_FUNCTION_OK_FOR_SIBCALL):
>         New macro definition.
>         (xtensa_prepare_expand_call): New function in order to share
>         the common code.
>         (xtensa_emit_sibcall, xtensa_function_ok_for_sibcall):
>         New functions.
>         (xtensa_expand_epilogue): Add new argument sibcall_p and use it
>         for sibling call handling.
>         * config/xtensa/xtensa.md (call, call_value):
>         Use xtensa_prepare_expand_call.
>         (call_internal, call_value_internal):
>         Add the condition in order to be disabled if sibling call.
>         (sibcall, sibcall_value, sibcall_epilogue): New expansions.
>         (sibcall_internal, sibcall_value_internal): New insn patterns,
>         and split ones in order to take care of the indirect sibcalls.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/xtensa/sibcalls.c: New.
> ---
>  gcc/config/xtensa/xtensa-protos.h          |  4 +-
>  gcc/config/xtensa/xtensa.cc                | 58 +++++++++++++-
>  gcc/config/xtensa/xtensa.md                | 93 ++++++++++++++++++----
>  gcc/testsuite/gcc.target/xtensa/sibcalls.c | 20 +++++
>  4 files changed, 155 insertions(+), 20 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/xtensa/sibcalls.c

Regtested for target=xtensa-linux-uclibc, no new regressions.
Committed to master.

-- 
Thanks.
-- Max

Reply via email to