public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Max Filippov <jcmvbkbc@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6342] gcc: xtensa: fix PR target/108919 Date: Sat, 25 Feb 2023 14:04:13 +0000 (GMT) [thread overview] Message-ID: <20230225140413.F2236385841A@sourceware.org> (raw) https://gcc.gnu.org/g:461d3c84a0e5ad045ee54631901cc953d6befa20 commit r13-6342-g461d3c84a0e5ad045ee54631901cc953d6befa20 Author: Max Filippov <jcmvbkbc@gmail.com> Date: Wed Feb 22 14:17:11 2023 -0800 gcc: xtensa: fix PR target/108919 gcc/ PR target/108919 * config/xtensa/xtensa-protos.h (xtensa_prepare_expand_call): Rename to xtensa_expand_call. * config/xtensa/xtensa.cc (xtensa_prepare_expand_call): Rename to xtensa_expand_call. (xtensa_expand_call): Emit the call and add a clobber expression for the static chain to it in case of windowed ABI. * config/xtensa/xtensa.md (call, call_value, sibcall) (sibcall_value): Call xtensa_expand_call and complete expansion right after that call. gcc/testsuite/ * gcc.target/xtensa/pr108919.c: New test. Diff: --- gcc/config/xtensa/xtensa-protos.h | 2 +- gcc/config/xtensa/xtensa.cc | 25 +++++++++++++++- gcc/config/xtensa/xtensa.md | 12 +++++--- gcc/testsuite/gcc.target/xtensa/pr108919.c | 46 ++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 6 deletions(-) diff --git a/gcc/config/xtensa/xtensa-protos.h b/gcc/config/xtensa/xtensa-protos.h index ecd0f0c8d10..c81cf94323a 100644 --- a/gcc/config/xtensa/xtensa-protos.h +++ b/gcc/config/xtensa/xtensa-protos.h @@ -53,7 +53,7 @@ extern void xtensa_expand_atomic (enum rtx_code, rtx, rtx, rtx, bool); extern void xtensa_emit_loop_end (rtx_insn *, rtx *); extern char *xtensa_emit_branch (bool, rtx *); extern char *xtensa_emit_movcc (bool, bool, bool, rtx *); -extern void xtensa_prepare_expand_call (int, rtx *); +extern void xtensa_expand_call (int, rtx *); extern char *xtensa_emit_call (int, rtx *); extern char *xtensa_emit_sibcall (int, rtx *); extern bool xtensa_tls_referenced_p (rtx); diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc index e52fba08255..5044bc25c2f 100644 --- a/gcc/config/xtensa/xtensa.cc +++ b/gcc/config/xtensa/xtensa.cc @@ -2183,8 +2183,10 @@ xtensa_emit_movcc (bool inverted, bool isfp, bool isbool, rtx *operands) void -xtensa_prepare_expand_call (int callop, rtx *operands) +xtensa_expand_call (int callop, rtx *operands) { + rtx call; + rtx_insn *call_insn; rtx addr = XEXP (operands[callop], 0); if (flag_pic && SYMBOL_REF_P (addr) @@ -2202,6 +2204,27 @@ xtensa_prepare_expand_call (int callop, rtx *operands) Pmode); XEXP (operands[callop], 0) = reg; } + + call = gen_rtx_CALL (VOIDmode, operands[callop], operands[callop + 1]); + + if (callop) + call = gen_rtx_SET (operands[0], call); + + call_insn = emit_call_insn (call); + + if (TARGET_WINDOWED_ABI) + { + /* + * Windowed xtensa ABI specifies that static chain pointer is passed + * in memory below the caller's stack pointer, which means that the + * callee may clobber it if it's a non-leaf function. + * Add the clobber expression for the static chain to the function call + * expression list so that it is not assumed to be live across the call. + */ + rtx clob = gen_rtx_CLOBBER (Pmode, xtensa_static_chain (NULL, false)); + CALL_INSN_FUNCTION_USAGE (call_insn) = + gen_rtx_EXPR_LIST (Pmode, clob, CALL_INSN_FUNCTION_USAGE (call_insn)); + } } diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index cf25beb83d5..b60dec2447f 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -2333,7 +2333,8 @@ (match_operand 1 "" ""))] "" { - xtensa_prepare_expand_call (0, operands); + xtensa_expand_call (0, operands); + DONE; }) (define_insn "call_internal" @@ -2353,7 +2354,8 @@ (match_operand 2 "" "")))] "" { - xtensa_prepare_expand_call (1, operands); + xtensa_expand_call (1, operands); + DONE; }) (define_insn "call_value_internal" @@ -2373,7 +2375,8 @@ (match_operand 1 "" ""))] "!TARGET_WINDOWED_ABI" { - xtensa_prepare_expand_call (0, operands); + xtensa_expand_call (0, operands); + DONE; }) (define_insn "sibcall_internal" @@ -2393,7 +2396,8 @@ (match_operand 2 "" "")))] "!TARGET_WINDOWED_ABI" { - xtensa_prepare_expand_call (1, operands); + xtensa_expand_call (1, operands); + DONE; }) (define_insn "sibcall_value_internal" diff --git a/gcc/testsuite/gcc.target/xtensa/pr108919.c b/gcc/testsuite/gcc.target/xtensa/pr108919.c new file mode 100644 index 00000000000..300b6fd10a9 --- /dev/null +++ b/gcc/testsuite/gcc.target/xtensa/pr108919.c @@ -0,0 +1,46 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + + +#ifdef __XTENSA_CALL0_ABI__ +void __xtensa_libgcc_window_spill (void) +{ +} +#else +void __xtensa_libgcc_window_spill (void); +#endif + +__attribute__((noinline)) void h (void) +{ + __xtensa_libgcc_window_spill (); +} + +int f (int u, int v) +{ + int a = u; + int s; + + __attribute__((noinline,pure)) int nested1 (int b) + { + h(); + return a + b; + } + + __attribute__((noinline,pure)) int nested2 (int b) + { + h(); + return a - b; + } + + s = nested1 (v); + s += nested2 (v); + return s; +} + +int main (void) +{ + int u = 0x12345678; + int v = 1; + + return f (u, v) == 2 * u ? 0 : 1; +}
reply other threads:[~2023-02-25 14:04 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230225140413.F2236385841A@sourceware.org \ --to=jcmvbkbc@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).