[llvm] [CodeGen] Sort fixed frame objects by stack offset (PR #219669)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 04:18:49 PDT 2026


================
@@ -1982,6 +1983,18 @@ class BaseMemOpClusterMutation : public ScheduleDAGMutation {
         return A->getReg() < B->getReg();
       if (A->isFI()) {
         const MachineFunction &MF = *A->getParent()->getParent()->getParent();
+        const MachineFrameInfo &MFI = MF.getFrameInfo();
+        if (MFI.isFixedObjectIndex(A->getIndex()) &&
+            MFI.isFixedObjectIndex(B->getIndex())) {
+          // Fixed objects have explicit offsets, and targets may create their
+          // frame indices in an order unrelated to those offsets. Sort by the
+          // actual object offsets so target clustering hooks see memory
+          // operations in address order.
+          int64_t AOffset = MFI.getObjectOffset(A->getIndex());
+          int64_t BOffset = MFI.getObjectOffset(B->getIndex());
+          if (AOffset != BOffset)
+            return AOffset < BOffset;
+        }
----------------
arsenm wrote:

You could also provide an ordering between fixed and unfixed objects?

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


More information about the llvm-commits mailing list