From patchwork Wed Feb 21 11:15:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1902077 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tfty14W0wz20RF for ; Wed, 21 Feb 2024 22:16:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 977843858C32 for ; Wed, 21 Feb 2024 11:16:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 6431E385840E for ; Wed, 21 Feb 2024 11:15:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6431E385840E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6431E385840E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708514126; cv=none; b=OMcDw/qPLbl3XQDNT/ED741VPFF4wC4Y7PTGTGoUupJhHtobvKrO28K0A2Gdh3DVk+R8PfYc4hThW7Yh3YOo8kCikdW2eNPiV8yQMF/Q6NVNI6+nIX/HzJLijBQ/zrhlJMdT03Qy0x9pBr4fIPj0VvsZFbdgpUsRoRT7pSMebJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708514126; c=relaxed/simple; bh=bmZf17AAA+BY0iPYpGhJdBKp2RugGoOiC0I5ebXcFd0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=U2Q5G2wFHcPpLcE2lrNLgSfHQEmIntOcpS20YfFFJwZbaX01efXtX8cGDk7UJse3M5I5bxOkrBRMh3Bk3MttbELWUw75p/q/nZomHve3m9DYwYtfLOds+asdf1Xq8HOK+TkbniCGBMKT7W2/7XKdrK1RS3LmappFuCFR9BlRTpc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8CDA1FEC for ; Wed, 21 Feb 2024 03:16:01 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A70CE3F73F for ; Wed, 21 Feb 2024 03:15:22 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [pushed] aarch64: Fix sibcalls involving shared-ZT0 functions Date: Wed, 21 Feb 2024 11:15:21 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-20.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org In: void bar() __arm_inout("za"); void foo() __arm_inout("za", "zt0") { bar(); } foo cannot tail-call bar because foo needs to restore ZT0 after the call. I'd forgotten to update the ok_for_sibcall rules to handle this when adding SME2. Thanks to Sander de Smalen for the spot. Tested on aarch64-linux-gnu & pushed. Richard gcc/ * config/aarch64/aarch64.cc (aarch64_function_ok_for_sibcall): Check that each individual piece of state is shared in the same way, rather than using an aggregate check for PSTATE.ZA. gcc/testsuite/ * gcc.target/aarch64/sme/sibcall_9.c: New test. --- gcc/config/aarch64/aarch64.cc | 6 ++- .../gcc.target/aarch64/sme/sibcall_9.c | 51 +++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/sibcall_9.c diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index de746e28ca5..f9cedd31bc1 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -6334,8 +6334,10 @@ aarch64_function_ok_for_sibcall (tree, tree exp) tree fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp))); if (aarch64_fntype_pstate_sm (fntype) & ~aarch64_cfun_incoming_pstate_sm ()) return false; - if (aarch64_fntype_pstate_za (fntype) != aarch64_cfun_incoming_pstate_za ()) - return false; + for (auto state : { "za", "zt0" }) + if (bool (aarch64_cfun_shared_flags (state)) + != bool (aarch64_fntype_shared_flags (fntype, state))) + return false; return true; } diff --git a/gcc/testsuite/gcc.target/aarch64/sme/sibcall_9.c b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_9.c new file mode 100644 index 00000000000..2e133c881a8 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_9.c @@ -0,0 +1,51 @@ +// { dg-options "-O2 -fno-schedule-insns -fno-schedule-insns2" } +// { dg-final { check-function-bodies "**" "" } } + +#pragma GCC target "+sme2" + +void gen_zt0() __arm_preserves("za") __arm_out("zt0"); +void callee() __arm_inout("za"); + +/* +** caller_inout: +** ... +** str zt0, \[[^\n]+\] +** bl callee +** ldr zt0, \[[^\n]+\] +** ... +** ret +*/ +void caller_inout() __arm_inout("za", "zt0") { callee(); } + +/* +** caller_in: +** ... +** str zt0, \[[^\n]+\] +** bl callee +** ldr zt0, \[[^\n]+\] +** ... +** ret +*/ +void caller_in() __arm_inout("za") __arm_in("zt0") { callee(); } + +/* +** caller_out: +** ... +** str zt0, \[[^\n]+\] +** bl callee +** ldr zt0, \[[^\n]+\] +** ... +** ret +*/ +void caller_out() __arm_inout("za") __arm_in("zt0") { gen_zt0(); callee(); } + +/* +** caller_preserves: +** ... +** str zt0, \[[^\n]+\] +** bl callee +** ldr zt0, \[[^\n]+\] +** ... +** ret +*/ +void caller_preserves() __arm_inout("za") __arm_preserves("zt0") { callee(); }