[llvm] [AArch64][SME] Avoid clobbering X0 in the MachineSMEABIPass (PR #170131)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 1 05:46:21 PST 2025
================
@@ -650,15 +650,21 @@ MachineSMEABI::findStateChangeInsertionPoint(
// Note: LiveUnits will only accurately track X0 and NZCV.
LiveRegUnits LiveUnits(*TRI);
setPhysLiveRegs(LiveUnits, PhysLiveRegs);
+ auto BestCandidate = std::make_pair(InsertPt, PhysLiveRegs);
for (MachineBasicBlock::iterator I = InsertPt; I != PrevStateChangeI; --I) {
// Don't move before/into a call (which may have a state change before it).
if (I->getOpcode() == TII->getCallFrameDestroyOpcode() || I->isCall())
break;
LiveUnits.stepBackward(*I);
- if (LiveUnits.available(AArch64::NZCV))
- return {I, getPhysLiveRegs(LiveUnits)};
+ LiveRegs CurrentPhysLiveRegs = getPhysLiveRegs(LiveUnits);
+ // Find places where NZCV is available, but keep looking for locations where
+ // both NZCV and X0 are available, which can avoid some copies.
+ if (!(CurrentPhysLiveRegs & LiveRegs::NZCV))
----------------
sdesmalen-arm wrote:
When not breaking from the loop here, Is it possible for NZCV to be set again by a previous instruction (i.e. at this point it is still available, because the previous instruction has a `kill` use of NZCV, but then the preceding instruction of that has a another `def` of NZCV and also a `kill` of `x0` (which would then trigger a break from the loop)?
https://github.com/llvm/llvm-project/pull/170131
More information about the llvm-commits
mailing list