From patchwork Fri Nov 17 17:30:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1865169 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=8.43.85.97; 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 [8.43.85.97]) (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 4SX3pd4KdBz1yRV for ; Sat, 18 Nov 2023 04:31:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BABAD3858418 for ; Fri, 17 Nov 2023 17:31:02 +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 0BDCF3858283 for ; Fri, 17 Nov 2023 17:30:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0BDCF3858283 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 0BDCF3858283 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=1700242252; cv=none; b=HgP2wX3jFLjSbsyQjJOw20tsR/mxe/LMHusbiq8Yw1en360BjXdP8hon6FUC4DMw8x+k3bWKYRQdzHeE42kb3+7XQASltGIJkv5k6lyHveeYzElR338WRzljKQwEJtprjXq7FBfiW0PjK6YtTS/KTHBy5vKLc10FRZ3bjyY/9iI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700242252; c=relaxed/simple; bh=5Iyk9tadpfQRkPaIAtGFBCZzGNefaf1rv+PzQRE5DZQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=oTuhlTEwSOLgyn6W7n4IDv8H65vWS4F4z0be7diX4SoeeBF29OJ34YkVsCvfILF5no4GyUKbWoiM3LVvTgVopTgE2bkhrVLpPrd7ZWoWBy++3LXa1NeyRF62XTS2xMSsWKScUyqhijhL5AGekDJg4q8fVgporkaUpA1ljcPiwW4= 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 BC4521477 for ; Fri, 17 Nov 2023 09:31:35 -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 4EB243F73F for ; Fri, 17 Nov 2023 09:30:49 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH 21/21] aarch64: Update sibcall handling for SME References: Date: Fri, 17 Nov 2023 17:30:48 +0000 In-Reply-To: (Richard Sandiford's message of "Fri, 17 Nov 2023 17:23:28 +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=-22.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 We only support tail calls between functions with the same PSTATE.ZA setting ("private-ZA" to "private-ZA" and "shared-ZA" to "shared-ZA"). Only a normal non-streaming function can tail-call another non-streaming function, and only a streaming function can tail-call another streaming function. Any function can tail-call a streaming-compatible function. gcc/ * config/aarch64/aarch64.cc (aarch64_function_ok_for_sibcall): Enforce PSTATE.SM and PSTATE.ZA restrictions. (aarch64_expand_epilogue): Save and restore the arguments to a sibcall around any change to PSTATE.SM. gcc/testsuite/ * gcc.target/aarch64/sme/sibcall_1.c: New test. * gcc.target/aarch64/sme/sibcall_2.c: Likewise. * gcc.target/aarch64/sme/sibcall_3.c: Likewise. * gcc.target/aarch64/sme/sibcall_4.c: Likewise. * gcc.target/aarch64/sme/sibcall_5.c: Likewise. * gcc.target/aarch64/sme/sibcall_6.c: Likewise. * gcc.target/aarch64/sme/sibcall_7.c: Likewise. * gcc.target/aarch64/sme/sibcall_8.c: Likewise. --- gcc/config/aarch64/aarch64.cc | 9 +++- .../gcc.target/aarch64/sme/sibcall_1.c | 45 +++++++++++++++++++ .../gcc.target/aarch64/sme/sibcall_2.c | 45 +++++++++++++++++++ .../gcc.target/aarch64/sme/sibcall_3.c | 45 +++++++++++++++++++ .../gcc.target/aarch64/sme/sibcall_4.c | 45 +++++++++++++++++++ .../gcc.target/aarch64/sme/sibcall_5.c | 45 +++++++++++++++++++ .../gcc.target/aarch64/sme/sibcall_6.c | 26 +++++++++++ .../gcc.target/aarch64/sme/sibcall_7.c | 26 +++++++++++ .../gcc.target/aarch64/sme/sibcall_8.c | 19 ++++++++ 9 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/sibcall_1.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/sibcall_2.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/sibcall_3.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/sibcall_4.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/sibcall_5.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/sibcall_6.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/sibcall_7.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/sibcall_8.c diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 6fa77d79dd7..c8f99d5c991 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -8498,6 +8498,11 @@ aarch64_function_ok_for_sibcall (tree, tree exp) if (crtl->abi->id () != expr_callee_abi (exp).id ()) return false; + 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; return true; } @@ -11950,7 +11955,9 @@ aarch64_expand_epilogue (rtx_call_insn *sibcall) guard_label = aarch64_guard_switch_pstate_sm (IP0_REGNUM, aarch64_isa_flags); aarch64_sme_mode_switch_regs return_switch; - if (crtl->return_rtx && REG_P (crtl->return_rtx)) + if (sibcall) + return_switch.add_call_args (sibcall); + else if (crtl->return_rtx && REG_P (crtl->return_rtx)) return_switch.add_reg (GET_MODE (crtl->return_rtx), REGNO (crtl->return_rtx)); return_switch.emit_prologue (); diff --git a/gcc/testsuite/gcc.target/aarch64/sme/sibcall_1.c b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_1.c new file mode 100644 index 00000000000..c7530de5c37 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_1.c @@ -0,0 +1,45 @@ +/* { dg-options "-O2" } */ + +void sc_callee () [[arm::streaming_compatible]]; +void s_callee () [[arm::streaming]]; +void n_callee (); + +[[arm::locally_streaming]] __attribute__((noipa)) void +sc_ls_callee () [[arm::streaming_compatible]] {} +[[arm::locally_streaming]] __attribute__((noipa)) void +n_ls_callee () {} + +void +sc_to_sc () [[arm::streaming_compatible]] +{ + sc_callee (); +} +/* { dg-final { scan-assembler {\tb\tsc_callee} } } */ + +void +sc_to_s () [[arm::streaming_compatible]] +{ + s_callee (); +} +/* { dg-final { scan-assembler {\tbl\ts_callee} } } */ + +void +sc_to_n () [[arm::streaming_compatible]] +{ + n_callee (); +} +/* { dg-final { scan-assembler {\tbl\tn_callee} } } */ + +void +sc_to_sc_ls () [[arm::streaming_compatible]] +{ + sc_ls_callee (); +} +/* { dg-final { scan-assembler {\tb\tsc_ls_callee} } } */ + +void +sc_to_n_ls () [[arm::streaming_compatible]] +{ + n_ls_callee (); +} +/* { dg-final { scan-assembler {\tbl\tn_ls_callee} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sme/sibcall_2.c b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_2.c new file mode 100644 index 00000000000..8d1c8a9f901 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_2.c @@ -0,0 +1,45 @@ +/* { dg-options "-O2" } */ + +void sc_callee () [[arm::streaming_compatible]]; +void s_callee () [[arm::streaming]]; +void n_callee (); + +[[arm::locally_streaming]] __attribute__((noipa)) void +sc_ls_callee () [[arm::streaming_compatible]] {} +[[arm::locally_streaming]] __attribute__((noipa)) void +n_ls_callee () {} + +void +s_to_sc () [[arm::streaming]] +{ + sc_callee (); +} +/* { dg-final { scan-assembler {\tb\tsc_callee} } } */ + +void +s_to_s () [[arm::streaming]] +{ + s_callee (); +} +/* { dg-final { scan-assembler {\tb\ts_callee} } } */ + +void +s_to_n () [[arm::streaming]] +{ + n_callee (); +} +/* { dg-final { scan-assembler {\tbl\tn_callee} } } */ + +void +s_to_sc_ls () [[arm::streaming]] +{ + sc_ls_callee (); +} +/* { dg-final { scan-assembler {\tb\tsc_ls_callee} } } */ + +void +s_to_n_ls () [[arm::streaming]] +{ + n_ls_callee (); +} +/* { dg-final { scan-assembler {\tbl\tn_ls_callee} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sme/sibcall_3.c b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_3.c new file mode 100644 index 00000000000..2ae937fc5dc --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_3.c @@ -0,0 +1,45 @@ +/* { dg-options "-O2" } */ + +void sc_callee () [[arm::streaming_compatible]]; +void s_callee () [[arm::streaming]]; +void n_callee (); + +[[arm::locally_streaming]] __attribute__((noipa)) void +sc_ls_callee () [[arm::streaming_compatible]] {} +[[arm::locally_streaming]] __attribute__((noipa)) void +n_ls_callee () {} + +void +n_to_sc () +{ + sc_callee (); +} +/* { dg-final { scan-assembler {\tb\tsc_callee} } } */ + +void +n_to_s () +{ + s_callee (); +} +/* { dg-final { scan-assembler {\tbl\ts_callee} } } */ + +void +n_to_n () +{ + n_callee (); +} +/* { dg-final { scan-assembler {\tb\tn_callee} } } */ + +void +n_to_sc_ls () +{ + sc_ls_callee (); +} +/* { dg-final { scan-assembler {\tb\tsc_ls_callee} } } */ + +void +n_to_n_ls () +{ + n_ls_callee (); +} +/* { dg-final { scan-assembler {\tb\tn_ls_callee} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sme/sibcall_4.c b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_4.c new file mode 100644 index 00000000000..6935a1bd740 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_4.c @@ -0,0 +1,45 @@ +/* { dg-options "-O2" } */ + +void sc_callee () [[arm::streaming_compatible]]; +void s_callee () [[arm::streaming]]; +void n_callee (); + +[[arm::locally_streaming]] __attribute__((noipa)) void +sc_ls_callee () [[arm::streaming_compatible]] {} +[[arm::locally_streaming]] __attribute__((noipa)) void +n_ls_callee () {} + +[[arm::locally_streaming]] void +sc_to_sc () [[arm::streaming_compatible]] +{ + sc_callee (); +} +/* { dg-final { scan-assembler {\tb\tsc_callee} } } */ + +[[arm::locally_streaming]] void +sc_to_s () [[arm::streaming_compatible]] +{ + s_callee (); +} +/* { dg-final { scan-assembler {\tbl\ts_callee} } } */ + +[[arm::locally_streaming]] void +sc_to_n () [[arm::streaming_compatible]] +{ + n_callee (); +} +/* { dg-final { scan-assembler {\tbl\tn_callee} } } */ + +[[arm::locally_streaming]] void +sc_to_sc_ls () [[arm::streaming_compatible]] +{ + sc_ls_callee (); +} +/* { dg-final { scan-assembler {\tb\tsc_ls_callee} } } */ + +[[arm::locally_streaming]] void +sc_to_n_ls () [[arm::streaming_compatible]] +{ + n_ls_callee (); +} +/* { dg-final { scan-assembler {\tbl\tn_ls_callee} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sme/sibcall_5.c b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_5.c new file mode 100644 index 00000000000..7aaf58dfa22 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_5.c @@ -0,0 +1,45 @@ +/* { dg-options "-O2" } */ + +void sc_callee () [[arm::streaming_compatible]]; +void s_callee () [[arm::streaming]]; +void n_callee (); + +[[arm::locally_streaming]] __attribute__((noipa)) void +sc_ls_callee () [[arm::streaming_compatible]] {} +[[arm::locally_streaming]] __attribute__((noipa)) void +n_ls_callee () {} + +[[arm::locally_streaming]] void +n_to_sc () +{ + sc_callee (); +} +/* { dg-final { scan-assembler {\tb\tsc_callee} } } */ + +[[arm::locally_streaming]] void +n_to_s () +{ + s_callee (); +} +/* { dg-final { scan-assembler {\tbl\ts_callee} } } */ + +[[arm::locally_streaming]] void +n_to_n () +{ + n_callee (); +} +/* { dg-final { scan-assembler {\tb\tn_callee} } } */ + +[[arm::locally_streaming]] void +n_to_sc_ls () +{ + sc_ls_callee (); +} +/* { dg-final { scan-assembler {\tb\tsc_ls_callee} } } */ + +[[arm::locally_streaming]] void +n_to_n_ls () +{ + n_ls_callee (); +} +/* { dg-final { scan-assembler {\tb\tn_ls_callee} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sme/sibcall_6.c b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_6.c new file mode 100644 index 00000000000..e568edb17dd --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_6.c @@ -0,0 +1,26 @@ +/* { dg-options "-O2" } */ + +void shared_callee () [[arm::inout("za")]]; +[[arm::new("za")]] __attribute__((noipa)) void new_callee () {} +void normal_callee (); + +void +shared_to_shared () [[arm::inout("za")]] +{ + shared_callee (); +} +/* { dg-final { scan-assembler {\tb\tshared_callee} } } */ + +void +shared_to_new () [[arm::inout("za")]] +{ + new_callee (); +} +/* { dg-final { scan-assembler {\tbl\tnew_callee} } } */ + +void +shared_to_normal () [[arm::inout("za")]] +{ + normal_callee (); +} +/* { dg-final { scan-assembler {\tbl\tnormal_callee} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sme/sibcall_7.c b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_7.c new file mode 100644 index 00000000000..a5f576d2044 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_7.c @@ -0,0 +1,26 @@ +/* { dg-options "-O2" } */ + +void shared_callee () [[arm::inout("za")]]; +[[arm::new("za")]] __attribute__((noipa)) void new_callee () {} +void normal_callee (); + +[[arm::new("za")]] void +new_to_shared () +{ + shared_callee (); +} +/* { dg-final { scan-assembler {\tbl\tshared_callee} } } */ + +[[arm::new("za")]] void +new_to_new () +{ + new_callee (); +} +/* { dg-final { scan-assembler {\tb\tnew_callee} } } */ + +[[arm::new("za")]] void +new_to_normal () +{ + normal_callee (); +} +/* { dg-final { scan-assembler {\tb\tnormal_callee} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sme/sibcall_8.c b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_8.c new file mode 100644 index 00000000000..33370f7a87f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sme/sibcall_8.c @@ -0,0 +1,19 @@ +/* { dg-options "-O2" } */ + +void shared_callee () [[arm::inout("za")]]; +[[arm::new("za")]] __attribute__((noipa)) void new_callee () {} +void normal_callee (); + +void +normal_to_new () +{ + new_callee (); +} +/* { dg-final { scan-assembler {\tb\tnew_callee} } } */ + +void +normal_to_normal () +{ + normal_callee (); +} +/* { dg-final { scan-assembler {\tb\tnormal_callee} } } */