Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 55 additions & 22 deletions llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2529,31 +2529,64 @@ MachineBasicBlock::iterator AArch64LoadStoreOpt::findMatchingUpdateInsnForward(
return E;
}

for (unsigned Count = 0; MBBI != E && Count < Limit;
MBBI = next_nodbg(MBBI, E)) {
MachineInstr &MI = *MBBI;

// Don't count transient instructions towards the search limit since there
// may be different numbers of them if e.g. debug information is present.
if (!MI.isTransient())
++Count;

// If we found a match, return it.
if (isMatchingUpdateInsn(*I, MI, BaseReg, UnscaledOffset))
return MBBI;
unsigned Count = 0;
MachineBasicBlock *CurMBB = I->getParent();
// choice of next block to visit is liveins-based
bool VisitSucc = CurMBB->getParent()->getRegInfo().tracksLiveness();

while (true) {
for (MachineBasicBlock::iterator CurEnd = CurMBB->end();
MBBI != CurEnd && Count < Limit; MBBI = next_nodbg(MBBI, CurEnd)) {
MachineInstr &MI = *MBBI;

// Don't count transient instructions towards the search limit since there
// may be different numbers of them if e.g. debug information is present.
if (!MI.isTransient())
++Count;

// If we found a match, return it.
if (isMatchingUpdateInsn(*I, MI, BaseReg, UnscaledOffset))
return MBBI;

// Update the status of what the instruction clobbered and used.
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits, UsedRegUnits,
TRI);

// Otherwise, if the base register is used or modified, we have no match,
// so return early. If we are optimizing SP, do not allow instructions
// that may load or store in between the load and the optimized value
// update.
if (!ModifiedRegUnits.available(BaseReg) ||
!UsedRegUnits.available(BaseReg) ||
(BaseRegSP && MBBI->mayLoadOrStore()))
return E;
}

// Update the status of what the instruction clobbered and used.
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits, UsedRegUnits, TRI);
if (!VisitSucc || Limit <= Count)
break;

// Otherwise, if the base register is used or modified, we have no match, so
// return early.
// If we are optimizing SP, do not allow instructions that may load or store
// in between the load and the optimized value update.
if (!ModifiedRegUnits.available(BaseReg) ||
!UsedRegUnits.available(BaseReg) ||
(BaseRegSP && MBBI->mayLoadOrStore()))
return E;
// Try to go downward to successors along a CF path w/o side enters
// such that BaseReg is alive along it but not at its exits
MachineBasicBlock *SuccToVisit = nullptr;
unsigned LiveSuccCount = 0;
MCRegister RegNoBAse = BaseReg;
for (MachineBasicBlock *Succ : CurMBB->successors()) {
for (MCRegAliasIterator AI(BaseReg, TRI, true); AI.isValid(); ++AI) {
if (Succ->isLiveIn(*AI)) {
if (LiveSuccCount++)
return E;
if (Succ->pred_size() == 1)
SuccToVisit = Succ;
break;
}
}
}
if (!SuccToVisit)
break;
CurMBB = SuccToVisit;
MBBI = CurMBB->begin();
}

return E;
}

Expand Down
Loading
Loading