From patchwork Wed Feb 21 11:13:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1902074 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 4Tftvd4rYcz23cl for ; Wed, 21 Feb 2024 22:14:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9859E3858407 for ; Wed, 21 Feb 2024 11:14:19 +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 1BB283858D34 for ; Wed, 21 Feb 2024 11:13:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BB283858D34 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 1BB283858D34 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=1708514036; cv=none; b=eQLLBX+M+HBkq4/voUki0Bas0i7WSEB4KjOyy3qCuGB+I9Mfyma+22xsXMjmsGI6JShi7oGA/0NREahnZI7J+GKk1LUz547OooTzpmsTTkOyQXIc06oERh4VmhEaVLyk2/6B9vy7nXMju83jRmeIKlmoUzzmzWgMYsT/PlXgjU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708514036; c=relaxed/simple; bh=i38GrgmY7HCKnxvtUdJcaFZ+QtcOjtasICg5xgQSO84=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=QbZroryHDsqBil/L0sxKXzX+eIGnwVMcr4CGvI5xVKqOQywDGGIH4WVtBobj1QWFV3wePmaaGyAE3CIdU5KCorCdUdmmg3eGiAOPyAsdn6Am9vpN7IQIhPuQn9687LZ4/e1heaRQB1EJAuXFbqVqMi15ojVO+MbVD+SyAFnj3rg= 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 24C49FEC for ; Wed, 21 Feb 2024 03:14:28 -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 45B253F73F for ; Wed, 21 Feb 2024 03:13: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: [pushed] aarch64: Stack-clash prologues and VG saves [PR113995] Date: Wed, 21 Feb 2024 11:13:48 +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 This patch fixes an ICE for a combination of: - -fstack-clash-protection - a frame that has SVE save slots - a frame that has no GPR save slots - a frame that has a VG save slot The allocation code was folding the SVE save slot allocation into the initial frame allocation, so that we had one allocation of size + 16. But the VG save code itself expected the allocations to remain separate, since it wants to store at a constant offset from SP or FP. The VG save isn't shrink-wrapped and so acts as a probe of the initial allocations. It should therefore be safe to keep separate allocations in this case. The scans in locally_streaming_1.c expect no stack clash protection, so the patch forces that and adds a separate compile-only test for when protection is enabled. Tested on aarch64-linux-gnu & pushed. Richard gcc/ PR target/113995 * config/aarch64/aarch64.cc (aarch64_expand_prologue): Don't fold the SVE allocation into the initial allocation if the initial allocation includes a VG save. gcc/testsuite/ PR target/113995 * gcc.target/aarch64/sme/locally_streaming_1.c: Require -fno-stack-clash-protection. * gcc.target/aarch64/sme/locally_streaming_1_scp.c: New test. --- gcc/config/aarch64/aarch64.cc | 9 +++++++-- .../gcc.target/aarch64/sme/locally_streaming_1.c | 2 +- .../gcc.target/aarch64/sme/locally_streaming_1_scp.c | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/locally_streaming_1_scp.c diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 104f7e1831e..6a39ed8eddf 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -9523,7 +9523,9 @@ aarch64_expand_prologue (void) if (aarch64_cfun_enables_pstate_sm ()) force_isa_mode = AARCH64_FL_SM_ON; - if (flag_stack_clash_protection && known_eq (callee_adjust, 0)) + if (flag_stack_clash_protection + && known_eq (callee_adjust, 0) + && known_lt (frame.reg_offset[VG_REGNUM], 0)) { /* Fold the SVE allocation into the initial allocation. We don't do this in aarch64_layout_arg to avoid pessimizing @@ -9651,7 +9653,10 @@ aarch64_expand_prologue (void) if (maybe_ne (sve_callee_adjust, 0)) { gcc_assert (!flag_stack_clash_protection - || known_eq (initial_adjust, 0)); + || known_eq (initial_adjust, 0) + /* The VG save isn't shrink-wrapped and so serves as + a probe of the initial allocation. */ + || known_eq (frame.reg_offset[VG_REGNUM], bytes_below_sp)); aarch64_allocate_and_probe_stack_space (tmp1_rtx, tmp0_rtx, sve_callee_adjust, force_isa_mode, diff --git a/gcc/testsuite/gcc.target/aarch64/sme/locally_streaming_1.c b/gcc/testsuite/gcc.target/aarch64/sme/locally_streaming_1.c index 4bb637f4781..cb235f5c832 100644 --- a/gcc/testsuite/gcc.target/aarch64/sme/locally_streaming_1.c +++ b/gcc/testsuite/gcc.target/aarch64/sme/locally_streaming_1.c @@ -1,4 +1,4 @@ -// { dg-options "-O -fomit-frame-pointer" } +// { dg-options "-O -fomit-frame-pointer -fno-stack-clash-protection" } // { dg-final { check-function-bodies "**" "" } } void consume_za () [[arm::streaming, arm::inout("za")]]; diff --git a/gcc/testsuite/gcc.target/aarch64/sme/locally_streaming_1_scp.c b/gcc/testsuite/gcc.target/aarch64/sme/locally_streaming_1_scp.c new file mode 100644 index 00000000000..6b7f47dce7a --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sme/locally_streaming_1_scp.c @@ -0,0 +1,3 @@ +// { dg-options "-O -fomit-frame-pointer -fstack-clash-protection" } + +#include "locally_streaming_1.c"