[llvm] [NFC] Remove reverse restore from epilogue for SVE registers (PR #79623)

Momchil Velikov via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 05:04:26 PST 2024


================
@@ -3196,9 +3196,21 @@ bool AArch64FrameLowering::restoreCalleeSavedRegisters(
     return true;
   }
 
+  SmallVector<RegPairInfo, 8> RegPairsScalable = RegPairs;
+  llvm::stable_sort(
+      RegPairsScalable, [](const RegPairInfo &A, const RegPairInfo &B) {
+        return !(A.Type == RegPairInfo::PPR && B.Type == RegPairInfo::ZPR);
----------------
momchil-velikov wrote:

Yeah, so the predicate is incorrect, as it does not satisfy the requirements of the `std::sort` /`std::stable_sort` (and by extension to `llvm::stable_sort`. You can easily check the after "sorting" the sequence is not sorted with respect to the predicate:

```
diff --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
index 9370cbbc6ca2..e80c66e2485e 100644
--- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
@@ -3196,11 +3196,15 @@ bool AArch64FrameLowering::restoreCalleeSavedRegisters(
     return true;
   }
 
+  auto Comp = [](const RegPairInfo &A, const RegPairInfo &B) {
+    return !(A.Type == RegPairInfo::PPR && B.Type == RegPairInfo::ZPR);
+  };
+
   SmallVector<RegPairInfo, 8> RegPairsScalable = RegPairs;
-  llvm::stable_sort(
-      RegPairsScalable, [](const RegPairInfo &A, const RegPairInfo &B) {
-        return !(A.Type == RegPairInfo::PPR && B.Type == RegPairInfo::ZPR);
-      });
+  llvm::stable_sort(RegPairsScalable, Comp);
+
+  for (size_t i = 0; i + 1 < RegPairsScalable.size(); ++i)
+    assert(!Comp(RegPairs[i+1], RegPairs[i]));
 ```

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


More information about the llvm-commits mailing list