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: 204153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp968525dyc; Wed, 21 Feb 2024 03:14:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUPKhL6PRrls85CcTJPhbKh5Z906JVHnQqLcsvF8vjrTaAEPulgEITJEUKa2z499NTLSK7c4i+HMzx73vIYoAbswAHptA== X-Google-Smtp-Source: AGHT+IFC3gqpzqSCzEUAFqx4xlZO3WuhEsvhbaYj4IGCqfPw7R+ER6r8qL8rRjBMnelrTO0ENwF4 X-Received: by 2002:a0d:cad7:0:b0:608:4ca9:6aa0 with SMTP id m206-20020a0dcad7000000b006084ca96aa0mr6012144ywd.20.1708514091556; Wed, 21 Feb 2024 03:14:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708514091; cv=pass; d=google.com; s=arc-20160816; b=BODNbHxS+/E6fbCbQ/1BV4VNyVPD86+CtOeVbinYNBeJhHM+yYqC6rW10uz6Wug3rv 0+FTWrgMWyWYS+I0sEILVHgn6SI9EfogP9tXM3R8wPH6BYUlhEUMEoSxhQs0LMQSLGUt k84lZQ1rdnfTyETl8fEpbNAomROoxcnqDRqL2l+Y5aKJKoCyxSEN895pmqY9+m2zm+Et Mk/6crNqEU8VWLhYkjuZPYeJEd3k5DcYgSh4pNmmtrH8yD4I3dxFH6NC3r3wkO/oPuXd bGKRa2oQcZijgTSrhcFX8wUfV+Kc29SQwPiJBYGOk5d0i2pP3ovIajobFJipAAiGO64k TDgQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:date:subject:mail-followup-to:to:from:arc-filter :dmarc-filter:delivered-to; bh=GaF2fr9a5CXKTbOB4ShutVfc3EqAbeVxIC8awdJugEk=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=06YeUHKOtHcVTmanb69ixzF1nJrGBmWLlfSH9xo0fjqvn6zU+kj12O1X290aWn4+E3 LI7Y9SHMLFWS5sfMQ4yj+543lv8YU77dWEY//2gIT9ISAtRrdrX4GQaHu43OYoYXC7bc 9kHLu3CQ1AQqISf73yJOq2albuksC0FD7MWyRAWVFedwlEwb7ZlPHWCqLGva3j96o0Ws x7P9YRM9eJCkEBuZAFLKZxXn1HSVWJ1s+CIy+VaQJhbTeRqhfb6oNhp1FXrukslcQAJf GE9XLLakInJn2TICAN68kncdosdHZxP+J1sntCiqG5Doc4nzfe1Q8pysFmNMnTse8J30 flmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j13-20020a05622a038d00b0042c574e2766si11416503qtx.727.2024.02.21.03.14.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 03:14:51 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3954B3858419 for ; Wed, 21 Feb 2024 11:14:51 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791506872180215977 X-GMAIL-MSGID: 1791506872180215977 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"