[llvm] [AArch64] Restore Z-registers before P-registers (PR #79623)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 12 08:06:47 PST 2024


================
@@ -3201,11 +3196,27 @@ bool AArch64FrameLowering::restoreCalleeSavedRegisters(
     return true;
   }
 
+  // For performance reasons restore SVE register in increasing order
+  auto PPRBegin =
+      std::find_if(RegPairs.begin(), RegPairs.end(), [](const RegPairInfo &c) {
+        return c.Type == RegPairInfo::PPR;
+      });
+  auto PPREnd = std::find_if(
+      RegPairs.rbegin(), RegPairs.rend(),
+      [](const RegPairInfo &c) { return c.Type == RegPairInfo::PPR; });
+  std::reverse(PPRBegin, PPREnd.base());
+  auto ZPRBegin =
+      std::find_if(RegPairs.begin(), RegPairs.end(), [](const RegPairInfo &c) {
+        return c.Type == RegPairInfo::ZPR;
+      });
+  auto ZPREnd = std::find_if(
+      RegPairs.rbegin(), RegPairs.rend(),
+      [](const RegPairInfo &c) { return c.Type == RegPairInfo::ZPR; });
+  std::reverse(ZPRBegin, ZPREnd.base());
+
   if (ReverseCSRRestoreSeq) {
----------------
sdesmalen-arm wrote:

If `ReverseCSRRestoreSeq == true`, then it always reverses all RegPairs. That means that if RegPairs has `{ ..., P4, P5, ... Z8, Z9, .. }` that if `ReverseCSRRestoreSeq == true`, that the Z registers will be restored first, which I thought is what you want to avoid (reading the commit messsage in the PR).

That said, I think this option is never really used other than in some of the tests. Which makes me wonder, can we remove it? @francisvm 

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


More information about the llvm-commits mailing list