Skip to content

Commit

Permalink
[MachineCopyPropagation] Pass DestSourcePair to isBackwardPropagatabl…
Browse files Browse the repository at this point in the history
…eCopy. NFC

Instead of calling isCopyInstr again, just pass the DestSourcePair
from the isCopyInstr call from the caller.
  • Loading branch information
topperc committed Mar 26, 2023
1 parent bae6f8f commit e35fbf5
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions llvm/lib/CodeGen/MachineCopyPropagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,24 +899,19 @@ void MachineCopyPropagation::ForwardCopyPropagateBlock(MachineBasicBlock &MBB) {
Tracker.clear();
}

static bool isBackwardPropagatableCopy(MachineInstr &MI,
static bool isBackwardPropagatableCopy(const DestSourcePair &CopyOperands,
const MachineRegisterInfo &MRI,
const TargetInstrInfo &TII,
bool UseCopyInstr) {
std::optional<DestSourcePair> CopyOperands =
isCopyInstr(MI, TII, UseCopyInstr);
assert(CopyOperands && "MI is expected to be a COPY");

Register Def = CopyOperands->Destination->getReg();
Register Src = CopyOperands->Source->getReg();
const TargetInstrInfo &TII) {
Register Def = CopyOperands.Destination->getReg();
Register Src = CopyOperands.Source->getReg();

if (!Def || !Src)
return false;

if (MRI.isReserved(Def) || MRI.isReserved(Src))
return false;

return CopyOperands->Source->isRenamable() && CopyOperands->Source->isKill();
return CopyOperands.Source->isRenamable() && CopyOperands.Source->isKill();
}

void MachineCopyPropagation::propagateDefs(MachineInstr &MI) {
Expand Down Expand Up @@ -991,14 +986,13 @@ void MachineCopyPropagation::BackwardCopyPropagateBlock(
Register SrcReg = CopyOperands->Source->getReg();

if (!TRI->regsOverlap(DefReg, SrcReg)) {
MCRegister Def = DefReg.asMCReg();
MCRegister Src = SrcReg.asMCReg();

// Unlike forward cp, we don't invoke propagateDefs here,
// just let forward cp do COPY-to-COPY propagation.
if (isBackwardPropagatableCopy(MI, *MRI, *TII, UseCopyInstr)) {
Tracker.invalidateRegister(Src, *TRI, *TII, UseCopyInstr);
Tracker.invalidateRegister(Def, *TRI, *TII, UseCopyInstr);
if (isBackwardPropagatableCopy(*CopyOperands, *MRI, *TII)) {
Tracker.invalidateRegister(SrcReg.asMCReg(), *TRI, *TII,
UseCopyInstr);
Tracker.invalidateRegister(DefReg.asMCReg(), *TRI, *TII,
UseCopyInstr);
Tracker.trackCopy(&MI, *TRI, *TII, UseCopyInstr);
continue;
}
Expand Down

0 comments on commit e35fbf5

Please sign in to comment.