Skip to content

Commit

Permalink
X86FixupBWInsts: Minor cleanup. NFC
Browse files Browse the repository at this point in the history
Summary: Cleanup some remnants of code from when the X86FixupBWInsts pass did both forward liveness analysis and backward liveness analysis.

Reviewers: MatzeB, myatsina, DavidKreitzer

Reviewed By: MatzeB

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D31264

llvm-svn: 298599
  • Loading branch information
Zvi Rackover committed Mar 23, 2017
1 parent c53faf7 commit db4b032
Showing 1 changed file with 14 additions and 35 deletions.
49 changes: 14 additions & 35 deletions llvm/lib/Target/X86/X86FixupBWInsts.cpp
Expand Up @@ -95,10 +95,9 @@ class FixupBWInstPass : public MachineFunctionPass {

// Change the MachineInstr \p MI into an eqivalent 32 bit instruction if
// possible. Return the replacement instruction if OK, return nullptr
// otherwise. Set WasCandidate to true or false depending on whether the
// MI was a candidate for this sort of transformation.
MachineInstr *tryReplaceInstr(MachineInstr *MI, MachineBasicBlock &MBB,
bool &WasCandidate) const;
// otherwise.
MachineInstr *tryReplaceInstr(MachineInstr *MI, MachineBasicBlock &MBB) const;

public:
static char ID;

Expand Down Expand Up @@ -269,52 +268,41 @@ MachineInstr *FixupBWInstPass::tryReplaceCopy(MachineInstr *MI) const {
return MIB;
}

MachineInstr *FixupBWInstPass::tryReplaceInstr(
MachineInstr *MI, MachineBasicBlock &MBB,
bool &WasCandidate) const {
MachineInstr *NewMI = nullptr;
WasCandidate = false;

MachineInstr *FixupBWInstPass::tryReplaceInstr(MachineInstr *MI,
MachineBasicBlock &MBB) const {
// See if this is an instruction of the type we are currently looking for.
switch (MI->getOpcode()) {

case X86::MOV8rm:
// Only replace 8 bit loads with the zero extending versions if
// in an inner most loop and not optimizing for size. This takes
// an extra byte to encode, and provides limited performance upside.
if (MachineLoop *ML = MLI->getLoopFor(&MBB)) {
if (ML->begin() == ML->end() && !OptForSize) {
NewMI = tryReplaceLoad(X86::MOVZX32rm8, MI);
WasCandidate = true;
}
}
if (MachineLoop *ML = MLI->getLoopFor(&MBB))
if (ML->begin() == ML->end() && !OptForSize)
return tryReplaceLoad(X86::MOVZX32rm8, MI);
break;

case X86::MOV16rm:
// Always try to replace 16 bit load with 32 bit zero extending.
// Code size is the same, and there is sometimes a perf advantage
// from eliminating a false dependence on the upper portion of
// the register.
NewMI = tryReplaceLoad(X86::MOVZX32rm16, MI);
WasCandidate = true;
break;
return tryReplaceLoad(X86::MOVZX32rm16, MI);

case X86::MOV8rr:
case X86::MOV16rr:
// Always try to replace 8/16 bit copies with a 32 bit copy.
// Code size is either less (16) or equal (8), and there is sometimes a
// perf advantage from eliminating a false dependence on the upper portion
// of the register.
NewMI = tryReplaceCopy(MI);
WasCandidate = true;
break;
return tryReplaceCopy(MI);

default:
// nothing to do here.
break;
}

return NewMI;
return nullptr;
}

void FixupBWInstPass::processBasicBlock(MachineFunction &MF,
Expand All @@ -338,18 +326,11 @@ void FixupBWInstPass::processBasicBlock(MachineFunction &MF,
// We run after PEI, so we need to AddPristinesAndCSRs.
LiveRegs.addLiveOuts(MBB);

bool WasCandidate = false;

for (auto I = MBB.rbegin(); I != MBB.rend(); ++I) {
MachineInstr *MI = &*I;

MachineInstr *NewMI = tryReplaceInstr(MI, MBB, WasCandidate);

// Add this to replacements if it was a candidate, even if NewMI is
// nullptr. We will revisit that in a bit.
if (WasCandidate) {
if (MachineInstr *NewMI = tryReplaceInstr(MI, MBB))
MIReplacements.push_back(std::make_pair(MI, NewMI));
}

// We're done with this instruction, update liveness for the next one.
LiveRegs.stepBackward(*MI);
Expand All @@ -359,9 +340,7 @@ void FixupBWInstPass::processBasicBlock(MachineFunction &MF,
MachineInstr *MI = MIReplacements.back().first;
MachineInstr *NewMI = MIReplacements.back().second;
MIReplacements.pop_back();
if (NewMI) {
MBB.insert(MI, NewMI);
MBB.erase(MI);
}
MBB.insert(MI, NewMI);
MBB.erase(MI);
}
}

0 comments on commit db4b032

Please sign in to comment.