From patchwork Sat Feb 25 10:01:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1747951 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Dz34KEnj; dkim-atps=neutral Received: from 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PP2NW5Gssz240f for ; Sat, 25 Feb 2023 21:01:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B7197385DC3C for ; Sat, 25 Feb 2023 10:01:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7197385DC3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677319304; bh=Ycy9MhKicZ3o82o14hU/KEG6Ft4WjUW8fdj4tCQDZ5I=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Dz34KEnjH9OxJdapevHK1/ltnQnTGOuNLi4MZpJ1Z9aHyEN+Ix0L7QpwfNH+JjML2 DU52T+A+udAPn55iE/5F+erXKoOpIBeD/pu0J2gwW5/Ls3CXplprPnWuy2rHEisRP8 izgWKT1ac6fHWdVDrUcsR2Z6ksenfB3+gDU8081U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 999E43857C45 for ; Sat, 25 Feb 2023 10:01:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 999E43857C45 Received: by mail-pf1-x434.google.com with SMTP id y10so869478pfi.8 for ; Sat, 25 Feb 2023 02:01:23 -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=Ycy9MhKicZ3o82o14hU/KEG6Ft4WjUW8fdj4tCQDZ5I=; b=YWMJpDmY/ZXimT0CU2HFhc1oFd3nadCunffIghfe0TnykJdwjHyyHRUNBrBNHIlWJY Iri2HckAmkPMutdhZ7xapkPp4VndlKTgkBxbGxZ9OQPFmlfvVtoxfRVntz300MecqvLK fCNmVbQOvhAwJ7TZHXxk0NcR47SjuMEZG2Uw1cM8A5Iwagcx25ks7kV6cZV9eJxNMJxg lbA7P0jvyzYQs4KijyzlfPWs/wGehX9EYq84RfjRTVlhD5UoTNbS64LnHvUg8n6cWlhb n8xNlVFhu0nEP9UL1NobQFe3X4psr2xXhINpaGPcVYGajxvc1jz3TU2SM/KDg82mPQ7a Ub5w== X-Gm-Message-State: AO0yUKXgq7IkI7D7VB6XGFbifOfHoSZ6wK53kms8s5sb2e9KJEbgX/U7 lm/AU213XuoRP3EwFSszUIx/Ezu9NMk= X-Google-Smtp-Source: AK7set/rhWBf0Zt0pwpzWigVFo2kHkgRp6EysstQh6qmmWEKd512ZDjAq9jX4jDT4bO4sgUsFztdkg== X-Received: by 2002:a62:1cc8:0:b0:5a9:c1f9:dc70 with SMTP id c191-20020a621cc8000000b005a9c1f9dc70mr17577644pfc.30.1677319282255; Sat, 25 Feb 2023 02:01:22 -0800 (PST) Received: from octofox.hsd1.ca.comcast.net ([2601:641:401:1d20:ae3d:a30a:8e51:d16a]) by smtp.gmail.com with ESMTPSA id m26-20020a056a00165a00b0058dbb5c5038sm884129pfc.182.2023.02.25.02.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 02:01:21 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Takayuki 'January June' Suwa , Max Filippov Subject: [PATCH] gcc: xtensa: fix PR target/108919 Date: Sat, 25 Feb 2023 02:01:05 -0800 Message-Id: <20230225100105.3477550-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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+incoming=patchwork.ozlabs.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/testduite/ * 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..babe7f0ebd68 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 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_insn = emit_call_insn (gen_rtx_SET (operands[0], call)); + else + 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 stack pointer, which means that the callee + * will likely 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; +}