[llvm] [AArch64][SME] Fixup ABI routine insertion points to avoid clobbering NZCV (PR #161353)

Sam Tebbs via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 7 03:25:51 PDT 2025


================
@@ -476,6 +491,41 @@ MachineSMEABI::assignBundleZAStates(const EdgeBundles &Bundles,
   return BundleStates;
 }
 
+std::pair<MachineBasicBlock::iterator, LiveRegs>
+MachineSMEABI::findStateChangeInsertionPoint(
+    MachineBasicBlock &MBB, const BlockInfo &Block,
+    SmallVectorImpl<InstInfo>::const_iterator Inst) {
+  LiveRegs PhysLiveRegs;
+  MachineBasicBlock::iterator InsertPt;
+  if (Inst != Block.Insts.end()) {
+    InsertPt = Inst->InsertPt;
+    PhysLiveRegs = Inst->PhysLiveRegs;
+  } else {
+    InsertPt = MBB.getFirstTerminator();
+    PhysLiveRegs = Block.PhysLiveRegsAtExit;
+  }
+  if (!(PhysLiveRegs & LiveRegs::NZCV))
+    return {InsertPt, PhysLiveRegs}; // Nothing to do (no live flags).
+  // Find the previous state change. We can not move before this point.
+  MachineBasicBlock::iterator PrevStateChangeI;
+  if (Inst == Block.Insts.begin())
+    PrevStateChangeI = MBB.begin();
+  else
+    PrevStateChangeI = std::prev(Inst)->InsertPt;
----------------
SamTebbs33 wrote:

Ah that makes sense. A comment or documentation above the function header would be a good thing to have then.

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


More information about the llvm-commits mailing list