[llvm] [AArch64][SME] Support saving/restoring ZT0 in the MachineSMEABIPass (PR #166362)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 26 03:45:15 PST 2025


================
@@ -72,16 +72,30 @@ using namespace llvm;
 
 namespace {
 
-enum ZAState {
+// Note: For agnostic ZA, we assume the function is always entered/exited in the
+// "ACTIVE" state -- this _may_ not be the case (since OFF is also a
+// possibility, but for the purpose of placing ZA saves/restores, that does not
+// matter).
+enum ZAState : uint8_t {
   // Any/unknown state (not valid)
   ANY = 0,
 
   // ZA is in use and active (i.e. within the accumulator)
   ACTIVE,
 
+  // ZA is active, but ZT0 has been saved.
+  // This handles the edge case of sharedZA && !sharesZT0.
+  ACTIVE_ZT0_SAVED,
+
   // A ZA save has been set up or committed (i.e. ZA is dormant or off)
+  // If the function uses ZT0 it must also be saved.
   LOCAL_SAVED,
 
+  // ZA has been committed to the lazy save buffer of the current function.
+  // If the function uses ZT0 it must also be saved.
+  // ZA is off when a save has been committed.
----------------
sdesmalen-arm wrote:

These two lines confuse me a little bit.

> // ZA has been committed [..]
> // ZA is off _when_ a save has been committed.

So ZA is just off?

> // If the function uses ZT0 it must also be saved.

In order to get to `LOCAL_COMMITTED` it must have first been in state `LOCAL_SAVED`, which saves `ZT0` if available, so this comment can be removed?

https://github.com/llvm/llvm-project/pull/166362


More information about the llvm-commits mailing list