[{"id":3678963,"web_url":"http://patchwork.ozlabs.org/comment/3678963/","msgid":"<87cxzwsbrx.fsf@googlemail.com>","list_archive_url":null,"date":"2026-04-18T12:17:38","subject":"Re: [PATCH 2/7] aarch64: Fix za/zt0 zeroing on function entry","submitter":{"id":4363,"url":"http://patchwork.ozlabs.org/api/people/4363/","name":"Richard Sandiford","email":"rdsandiford@googlemail.com"},"content":"Alice Carlotti <alice.carlotti@arm.com> writes:\n> Usually if za and zt0 are used privately within a function, then they\n> are zeroed either by toggling PSTATE.ZA or after committing the lazy\n> save.  However, if one of za and zt0 is shared, and the other is used\n> privately, then we need to explicitly zero the private state.\n>\n> gcc/ChangeLog:\n>\n> \t* config/aarch64/aarch64.cc (aarch64_expand_prologue): Add\n> \tzeroing of za and zt0 when required.\n\nIs this early enough?  The state transition logic won't see the new\nwrites, so it seems like there's a risk that (say) the zeroing of ZA\nmight not survive some calls.\n\nI wonder whether we could instead add new initial states to represent\nunmet zeroing requirements and add the zeroing when transitioning to\nthe normal internal states?\n\nThanks,\nRichard\n\n> gcc/testsuite/ChangeLog:\n>\n> \t* gcc.target/aarch64/sme/zt0_state_7.c: New test.\n>\n>\n> diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc\n> index 62194b96450840d3bae69636fb04f3d62e516c8d..7b239554daebfbfa145c3a3c7034fa2d8dd7b4e0 100644\n> --- a/gcc/config/aarch64/aarch64.cc\n> +++ b/gcc/config/aarch64/aarch64.cc\n> @@ -10797,6 +10797,18 @@ aarch64_expand_prologue (void)\n>        if (guard_label)\n>  \temit_label (guard_label);\n>      }\n> +\n> +  /* If both za and zt0 are used, but only one is shared on entry, then we need\n> +     to zero the other one.  */\n> +  if (aarch64_cfun_incoming_pstate_za ())\n> +    {\n> +      if (!aarch64_cfun_shared_flags (\"za\")\n> +\t  && aarch64_cfun_has_state (\"za\"))\n> +\temit_insn (gen_aarch64_initial_zero_za ());\n> +      if (!aarch64_cfun_shared_flags (\"zt0\")\n> +\t  && aarch64_cfun_has_state (\"zt0\"))\n> +\temit_insn (gen_aarch64_sme_zero_zt0 ());\n> +    }\n>  }\n>  \n>  /* Return TRUE if we can use a simple_return insn.\n> diff --git a/gcc/testsuite/gcc.target/aarch64/sme/zt0_state_7.c b/gcc/testsuite/gcc.target/aarch64/sme/zt0_state_7.c\n> new file mode 100644\n> index 0000000000000000000000000000000000000000..7a4f00adf7ec26d6acda5200fa9aad3eba17af75\n> --- /dev/null\n> +++ b/gcc/testsuite/gcc.target/aarch64/sme/zt0_state_7.c\n> @@ -0,0 +1,34 @@\n> +// { dg-options \"-O3 -fomit-frame-pointer -fno-optimize-sibling-calls\" }\n> +// { dg-final { check-function-bodies \"**\" \"\" } }\n> +\n> +#include <arm_sme.h>\n> +\n> +#pragma GCC target \"+sme2+sme-lutv2\"\n> +\n> +/*\n> +** foo:\n> +**\t...\n> +**\tzero\t{ zt0 }\n> +**\t...\n> +*/\n> +__arm_streaming __arm_inout(\"za\") __arm_new(\"zt0\")\n> +void foo(void *ptr, float32_t *fp, svfloat32_t z, svuint8_t idx)\n> +{\n> +  svstr_za (0, ptr);\n> +  svst1_f32 (svptrue_b32(), fp, svluti2_lane_zt_f32 (0, idx, 0));\n> +}\n> +\n> +/*\n> +** bar:\n> +**\t...\n> +**\tzero\t{ za }\n> +**\t...\n> +*/\n> +__arm_streaming __arm_new(\"za\") __arm_inout(\"zt0\")\n> +void bar(void *ptr, float32_t *fp, svfloat32_t z)\n> +{\n> +  svstr_zt (0, ptr);\n> +  svmopa_za32_f32_m (0, svptrue_b32(), svptrue_b32(), z, z);\n> +  svstr_za (0, fp);\n> +}\n> +","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=googlemail.com header.i=@googlemail.com\n header.a=rsa-sha256 header.s=20251104 header.b=AXE2Wa9O;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=googlemail.com header.i=@googlemail.com\n header.a=rsa-sha256 header.s=20251104 header.b=AXE2Wa9O","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=googlemail.com","sourceware.org; spf=pass smtp.mailfrom=googlemail.com","server2.sourceware.org;\n arc=none smtp.remote-ip=209.85.128.45"],"Received":["from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fyW4H0dyKz1yDF\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 22:18:21 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 453DA4AA51FB\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 12:18:17 +0000 (GMT)","from mail-wm1-f45.google.com (mail-wm1-f45.google.com\n [209.85.128.45])\n by sourceware.org (Postfix) with ESMTPS id 039E24C900D8\n for <gcc-patches@gcc.gnu.org>; Sat, 18 Apr 2026 12:17:48 +0000 (GMT)","by mail-wm1-f45.google.com with SMTP id\n 5b1f17b1804b1-488e1a8ac40so21358235e9.2\n for <gcc-patches@gcc.gnu.org>; Sat, 18 Apr 2026 05:17:47 -0700 (PDT)","from localhost ([103.214.45.63])\n by smtp.googlemail.com with ESMTPSA id\n 5b1f17b1804b1-488fb7a051dsm40533955e9.18.2026.04.18.05.17.45\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Sat, 18 Apr 2026 05:17:45 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 453DA4AA51FB","OpenDKIM Filter v2.11.0 sourceware.org 039E24C900D8"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 039E24C900D8","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 039E24C900D8","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776514668; cv=none;\n b=uMTlKkn5JXN5UvWSEoGzPTq180C7e2y8vhr2LgtbmRp+l3EzqmPUWvpOAO9utxaw7D5CZCb92kd/GyB6GySyGokRiYJWgEGunlJ8r2sEYg7Be6XaPHw4TfmPOxeSHzPYOP54dEYH+UxoeUESY5DTsxXo/TGBhih6kxbvh+2Jc7c=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776514668; c=relaxed/simple;\n bh=xPPAELc3NwDoEN7xSFwnN+BKG4lIO5hYePDKEAFtsgM=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=TAZUPV5IR+QgUm1A1uuOkLKhy6C2sSXNwkRB1jQn7tZrLkF4oWpl2jBC8HrE19DLyb6FCYtIdwSRYX6cXduWBHTEbVvsz0UN4bxFTRIF1YBCi5QfRHYPtszNGz1AtiaNISjLCdB6WyDZXO5M614dC681KdhEhqigw2eq9+DliFA=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=googlemail.com; s=20251104; t=1776514667; x=1777119467; darn=gcc.gnu.org;\n h=mime-version:user-agent:message-id:date:references:in-reply-to\n :subject:cc:mail-followup-to:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=j/Fy9aafoclHxfZ1Tg+DYHvPEz7QMtXmr+YOLYL8aC8=;\n b=AXE2Wa9OFpaYdAqNIdHxN4MOdvQN++xcdsE8yhD0y/PSuBMqGTp4DsJsXjBKn650Ya\n 3tHeEo0ap3Qc95IP/K+t9AKVH4I+DCyqIilxsjElpEtxsov3Z/kJFCsKtMeycgkzdaHa\n QhNVyxqEg1Ek1xie+HVfc0G1MKeCj3ZbCAwgiah/RcbLcl2rajYS83Kf0hf0tUWsKhqB\n nSYHwG3TmMRakDFwTv8STQ+Oa3y3Bcc5gBQIEyKHHB41BzbowJRZGjFpoFTIHdsNa30C\n hAoEPs/PReefskvWI5h0ASXUhWpQcSaAoZ7NGiNiys7rMYxVBlbMaAYv9t+n8xiTO9aX\n Qn8A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776514667; x=1777119467;\n h=mime-version:user-agent:message-id:date:references:in-reply-to\n :subject:cc:mail-followup-to:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=j/Fy9aafoclHxfZ1Tg+DYHvPEz7QMtXmr+YOLYL8aC8=;\n b=Ku8EMW2uq767JT2iCR5n20A99sf3qhsAaNTo+REhfGRPo9/h8s8nvipPSIPq5Q4Oev\n rggSECeMNui2IILvt2ITv4OIwIKlNc4zVEQ7wryFQeAuZuBkrx9VZdg4AXyOEHpGsVI5\n WGX/v1AFeh7Lwg6/S1cDffI6+oUb7xgVjMMPALa79jDdB1qpuJ4Fj+rXYH9To7sV8YFl\n qMLTl2nm81aN20K1KVANi7lTrfaHWV1AStW2fBDCLgS2zEw6LqYIRuDOuBJdDWNNwITn\n xmypqttcI2FFb/M9VLHqw3hBF3MOGMCzX1+iLqlMaEKxmmfquVi0MoGDlNY73w5ta1tW\n 5DCg==","X-Gm-Message-State":"AOJu0Yw4vSjpRd/vrWI0iLo5Y2KVvbjLf1FrGRBIBUbAPHt47QWe0CNx\n KWX2NbbaByf14nuichkRnnqjDva/ntg4bwKDCXPrxLbi7dRxmRjg3Gdl","X-Gm-Gg":"AeBDieumTRG4haNZWIPI/vyXl0C2yHFILRutU0TKEea7KPVHJX6g/0BiVJx5TVr/+lO\n UpDhBsS8lGO6VIE26goW0n/GNYHS9bvXgBGrARUpZQIPPc7k7p0O2KdDuDMlZvL02x+30ddpKLm\n TWSp0F8tB5V1g2+SFJPWb2MNzRB9Mltl3SmwyJmUhkzd4nurbmzcli9ASf44WdLh5dfyv/CaKUF\n ZBEPWnfgP4FJiYBYh3L/QGPa6aRpYietnvWgM/D/HIPUjoL/i3drfRgDmn+9X2IiF4IoLH+6MZM\n LI/QrlzX+1yLxqSr20ybkeQYfMxg+FA+Xl9Me5gaWJp9vGuJBd7AhwA0adHbaUvDVCZzxlKu2gE\n RrnSLtB4syOWY6JH5KwOrFrM0Rj0JlDPhhH4d/JLfmUfZGJhz97jITd7oDzM2BKgjWyKfxNlfss\n 9F0S5nlFam4GXpzgvZAN8Q2om9ZGu7bZm1PUSTrdM=","X-Received":"by 2002:a05:600c:4750:b0:486:fdba:f5db with SMTP id\n 5b1f17b1804b1-488fb6e7316mr102268815e9.0.1776514666628;\n Sat, 18 Apr 2026 05:17:46 -0700 (PDT)","From":"Richard Sandiford <rdsandiford@googlemail.com>","To":"Alice Carlotti <alice.carlotti@arm.com>","Mail-Followup-To":"Alice Carlotti\n <alice.carlotti@arm.com>,gcc-patches@gcc.gnu.org,  Richard Earnshaw\n <richard.earnshaw@arm.com>,  Tamar Christina <tamar.christina@arm.com>,\n Kyrylo Tkachov <ktkachov@nvidia.com>,  Alex Coplan <alex.coplan@arm.com>,\n Andrew Pinski <andrew.pinski@oss.qualcomm.com>,  Wilco Dijkstra\n <wilco.dijkstra@arm.com>, rdsandiford@googlemail.com","Cc":"gcc-patches@gcc.gnu.org,  Richard Earnshaw <richard.earnshaw@arm.com>,\n Tamar Christina <tamar.christina@arm.com>,  Kyrylo Tkachov\n <ktkachov@nvidia.com>,  Alex Coplan <alex.coplan@arm.com>,  Andrew Pinski\n <andrew.pinski@oss.qualcomm.com>,  Wilco Dijkstra <wilco.dijkstra@arm.com>","Subject":"Re: [PATCH 2/7] aarch64: Fix za/zt0 zeroing on function entry","In-Reply-To":"<3fbf616c-aa2d-9cda-a670-2cf61c3d554c@e124511.cambridge.arm.com>\n (Alice Carlotti's message of \"Sat, 18 Apr 2026 01:29:17 +0100\")","References":"<500b3dee-1ffe-5d08-2308-5bf06d38650c@e124511.cambridge.arm.com>\n <3fbf616c-aa2d-9cda-a670-2cf61c3d554c@e124511.cambridge.arm.com>","Date":"Sat, 18 Apr 2026 13:17:38 +0100","Message-ID":"<87cxzwsbrx.fsf@googlemail.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","Content-Type":"text/plain","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}}]