]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Ensure ZT0 is zeroed in a new-ZT0 function
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 21 Feb 2024 11:12:28 +0000 (11:12 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Wed, 21 Feb 2024 11:12:28 +0000 (11:12 +0000)
ACLE guarantees that a function like:

  __arm_new("zt0") foo() { ... }

will start with ZT0 equal to zero.  I'd forgotten to enforce that
after commiting a lazy save.  After such a save, we should zero
ZA iff the function has ZA state and zero ZT0 iff the function
has ZT0 state.

gcc/
* config/aarch64/aarch64.cc (aarch64_mode_emit_local_sme_state):
In the code that commits a lazy save, only zero ZA if the function
has ZA state.  Similarly zero ZT0 if the function has ZT0 state.

gcc/testsuite/
* gcc.target/aarch64/sme/zt0_state_5.c (test3): Expect ZT0 rather
than ZA to be zeroed.
(test5): Remove zeroing of ZA.

gcc/config/aarch64/aarch64.cc
gcc/testsuite/gcc.target/aarch64/sme/zt0_state_5.c

index ed7fbca512bbafc9ef9531ce4c9ca5d2ab828496..de746e28ca5a26a4e45c2be8f7b315d0d9285f5f 100644 (file)
@@ -29338,6 +29338,7 @@ aarch64_mode_emit_local_sme_state (aarch64_local_sme_state mode,
             bl __arm_tpidr2_save
             msr tpidr2_el0, xzr
             zero { za }       // Only if ZA is live
+            zero { zt0 }      // Only if ZT0 is live
         no_save:  */
       auto tmp_reg = gen_reg_rtx (DImode);
       emit_insn (gen_aarch64_read_tpidr2 (tmp_reg));
@@ -29348,7 +29349,12 @@ aarch64_mode_emit_local_sme_state (aarch64_local_sme_state mode,
       emit_insn (gen_aarch64_clear_tpidr2 ());
       if (mode == aarch64_local_sme_state::ACTIVE_LIVE
          || mode == aarch64_local_sme_state::ACTIVE_DEAD)
-       emit_insn (gen_aarch64_initial_zero_za ());
+       {
+         if (aarch64_cfun_has_state ("za"))
+           emit_insn (gen_aarch64_initial_zero_za ());
+         if (aarch64_cfun_has_state ("zt0"))
+           emit_insn (gen_aarch64_sme_zero_zt0 ());
+       }
       emit_label (label);
     }
 
index 0fba21868ed379cb8c77241349055f136da8db82..2e008463aecca1c70f525515623b9619da5566d0 100644 (file)
@@ -54,7 +54,7 @@ __arm_new("zt0") int test3()
 **     cbz     x0, [^\n]+
 **     bl      __arm_tpidr2_save
 **     msr     tpidr2_el0, xzr
-**     zero    { za }
+**     zero    { zt0 }
 **     smstart za
 **     bl      in_zt0
 **     smstop  za
@@ -102,7 +102,6 @@ __arm_new("zt0") void test5()
 **     cbz     x0, [^\n]+
 **     bl      __arm_tpidr2_save
 **     msr     tpidr2_el0, xzr
-**     zero    { za }
 **     smstart za
 **     bl      out_zt0
 **     ...