From patchwork Sat Feb 25 14:05:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 65647 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 80D813854835 for ; Sat, 25 Feb 2023 14:06:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80D813854835 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677333962; bh=Owv0h0rR7nVD/rklG/wC379YreUcs62D7ZwDJHcxNZM=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=SUCiWzXBaXUjrvqm0pZuw9rnqoznARw2Ql8S1YczH8WVpm//lMKo//Q043rEYef3F YEApJ/GeIaPJ1erwAWgvVQlshXZJM89kw8KVUdvstN0vhNuivRUqipumS183x60Ac2 8gxoLA7GUwbfaGYMh7UvCRl/lsrk4sreelgAg3YI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by sourceware.org (Postfix) with ESMTPS id E35A5385841A for ; Sat, 25 Feb 2023 14:05:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E35A5385841A Received: by mail-pj1-x102b.google.com with SMTP id y15-20020a17090aa40f00b00237ad8ee3a0so1998996pjp.2 for ; Sat, 25 Feb 2023 06:05:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Owv0h0rR7nVD/rklG/wC379YreUcs62D7ZwDJHcxNZM=; b=vWtYt3Kn89lxjNLR6/EtZ0Q4rmiD6ZuhUGX7uOA028eBcNoA785UWU0qD0TphpjOli ZwbArNKXzKZHvRU9O/wGBImQnvgUHAIEl5dHeE/ODd24k7GaXLMhaEVonHdoqdO5S+6R ReLKLS90ArBEQz5SFYol0zDKokYx/V/d+NXP4VqhKfujpc9Faarz5F28P6L/EiN8vsrz X03hixLZwrfQXKaHBy8aXlsuvFPXivaPVWWKGPS25B9Q8PN/S184+0yOWysoxh7bK4eq cKyymAmkNkiWP/Us/LPde4OFA3WdV2Pb3BVOvt1hzIvbdbLoGONphuvOxFI30ZJ6H5xu vMIQ== X-Gm-Message-State: AO0yUKVryWgcrkv/uWt/AnxaJp04oNFDrRRSKsta6CooJr4r4LzGBxxN 4XbIlPs1ou9uqyNJ8caTUUvoi+QQa+8= X-Google-Smtp-Source: AK7set/QEeIb4Tb7C7CO8fRv9J17Wi3JKF8+0edt83dy0WmrD6QUpXcDSB185hhXlRjn15eBzWcFmA== X-Received: by 2002:a17:90b:4a8d:b0:237:b702:4990 with SMTP id lp13-20020a17090b4a8d00b00237b7024990mr3163795pjb.26.1677333932562; Sat, 25 Feb 2023 06:05:32 -0800 (PST) Received: from octofox.hsd1.ca.comcast.net ([2601:641:401:1d20:ae3d:a30a:8e51:d16a]) by smtp.gmail.com with ESMTPSA id l22-20020a17090b079600b0023670dbb82fsm1339452pjz.25.2023.02.25.06.05.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 06:05:32 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Takayuki 'January June' Suwa , Max Filippov Subject: [COMMITTED] gcc: xtensa: fix PR target/108919 Date: Sat, 25 Feb 2023 06:05:23 -0800 Message-Id: <20230225140523.3493078-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, GIT_PATCH_0, HK_RANDOM_ENVFROM, HK_RANDOM_FROM, KAM_NUMSUBJECT, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Max Filippov via Gcc-patches From: Max Filippov Reply-To: Max Filippov Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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. --- 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(-) create mode 100644 gcc/testsuite/gcc.target/xtensa/pr108919.c diff --git a/gcc/config/xtensa/xtensa-protos.h b/gcc/config/xtensa/xtensa-protos.h index ecd0f0c8d108..c81cf94323ac 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 e52fba082550..5044bc25c2fe 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 cf25beb83d54..b60dec2447f3 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 000000000000..300b6fd10a99 --- /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; +}