Skip to content

Commit

Permalink
[BreakFalseDeps][X86] Move operand loop out of X86's getUndefRegClear…
Browse files Browse the repository at this point in the history
…ance and put in the pass.

X86 is the only user of this interface in tree. Previously the
X86 pass would loop over operands looking for one undef operand for
the pass to fix. But there could theoretically be multiple operands
to fix. So it makes more sense for the pass to do the looping and
ask the target if an operand needs to be fixed.
  • Loading branch information
topperc committed Aug 10, 2020
1 parent 0d4b7ad commit 96dfc78
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ class TargetInstrInfo : public MCInstrInfo {
/// This hook works similarly to getPartialRegUpdateClearance, except that it
/// does not take an operand index. Instead sets \p OpNum to the index of the
/// unused register.
virtual unsigned getUndefRegClearance(const MachineInstr &MI, unsigned &OpNum,
virtual unsigned getUndefRegClearance(const MachineInstr &MI, unsigned OpNum,
const TargetRegisterInfo *TRI) const {
// The default implementation returns 0 for no undef register dependency.
return 0;
Expand Down
26 changes: 16 additions & 10 deletions llvm/lib/CodeGen/BreakFalseDeps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,25 +186,31 @@ bool BreakFalseDeps::shouldBreakDependence(MachineInstr *MI, unsigned OpIdx,
void BreakFalseDeps::processDefs(MachineInstr *MI) {
assert(!MI->isDebugInstr() && "Won't process debug values");

const MCInstrDesc &MCID = MI->getDesc();

// Break dependence on undef uses. Do this before updating LiveRegs below.
// This can remove a false dependence with no additional instructions.
unsigned OpNum;
unsigned Pref = TII->getUndefRegClearance(*MI, OpNum, TRI);
if (Pref) {
bool HadTrueDependency = pickBestRegisterForUndef(MI, OpNum, Pref);
// We don't need to bother trying to break a dependency if this
// instruction has a true dependency on that register through another
// operand - we'll have to wait for it to be available regardless.
if (!HadTrueDependency && shouldBreakDependence(MI, OpNum, Pref))
UndefReads.push_back(std::make_pair(MI, OpNum));
for (unsigned i = MCID.getNumDefs(), e = MCID.getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI->getOperand(i);
if (!MO.isReg() || !MO.getReg() || !MO.isUse() || !MO.isUndef())
continue;

unsigned Pref = TII->getUndefRegClearance(*MI, i, TRI);
if (Pref) {
bool HadTrueDependency = pickBestRegisterForUndef(MI, i, Pref);
// We don't need to bother trying to break a dependency if this
// instruction has a true dependency on that register through another
// operand - we'll have to wait for it to be available regardless.
if (!HadTrueDependency && shouldBreakDependence(MI, i, Pref))
UndefReads.push_back(std::make_pair(MI, i));
}
}

// The code below allows the target to create a new instruction to break the
// dependence. That opposes the goal of minimizing size, so bail out now.
if (MF->getFunction().hasMinSize())
return;

const MCInstrDesc &MCID = MI->getDesc();
for (unsigned i = 0,
e = MI->isVariadic() ? MI->getNumOperands() : MCID.getNumDefs();
i != e; ++i) {
Expand Down
16 changes: 5 additions & 11 deletions llvm/lib/Target/X86/X86InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5121,18 +5121,12 @@ static bool hasUndefRegUpdate(unsigned Opcode, unsigned OpNum,
/// Like getPartialRegUpdateClearance, this makes a strong assumption that the
/// high bits that are passed-through are not live.
unsigned
X86InstrInfo::getUndefRegClearance(const MachineInstr &MI, unsigned &OpNum,
X86InstrInfo::getUndefRegClearance(const MachineInstr &MI, unsigned OpNum,
const TargetRegisterInfo *TRI) const {
for (unsigned i = MI.getNumExplicitDefs(), e = MI.getNumExplicitOperands();
i != e; ++i) {
const MachineOperand &MO = MI.getOperand(i);
if (MO.isReg() && MO.isUndef() &&
Register::isPhysicalRegister(MO.getReg()) &&
hasUndefRegUpdate(MI.getOpcode(), i)) {
OpNum = i;
return UndefRegClearance;
}
}
const MachineOperand &MO = MI.getOperand(OpNum);
if (Register::isPhysicalRegister(MO.getReg()) &&
hasUndefRegUpdate(MI.getOpcode(), OpNum))
return UndefRegClearance;

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/X86InstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class X86InstrInfo final : public X86GenInstrInfo {
unsigned
getPartialRegUpdateClearance(const MachineInstr &MI, unsigned OpNum,
const TargetRegisterInfo *TRI) const override;
unsigned getUndefRegClearance(const MachineInstr &MI, unsigned &OpNum,
unsigned getUndefRegClearance(const MachineInstr &MI, unsigned OpNum,
const TargetRegisterInfo *TRI) const override;
void breakPartialRegDependency(MachineInstr &MI, unsigned OpNum,
const TargetRegisterInfo *TRI) const override;
Expand Down

0 comments on commit 96dfc78

Please sign in to comment.