Skip to content

Commit

Permalink
[ExecutionDepsFix] Don't revisit true dependencies
Browse files Browse the repository at this point in the history
If an instruction has a true dependency, it makes sense for to use that
register for any undef read operands in the same instruction (we'll have
to wait for that register to become available anyway). This logic
was already implemented. However, the code would then still try to
revisit that instruction and break the dependency (and always fail,
since by definition a true dependency has to be live before the
instruction). Avoid revisiting such instructions as a performance
optimization. No functional change.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299467 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Keno committed Apr 4, 2017
1 parent d6c407e commit 54eda94
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/llvm/CodeGen/ExecutionDepsFix.h
Original file line number Diff line number Diff line change
@@ -210,7 +210,7 @@ class ExecutionDepsFix : public MachineFunctionPass {
void processDefs(MachineInstr *, bool breakDependency, bool Kill);
void visitSoftInstr(MachineInstr*, unsigned mask);
void visitHardInstr(MachineInstr*, unsigned domain);
void pickBestRegisterForUndef(MachineInstr *MI, unsigned OpIdx,
bool pickBestRegisterForUndef(MachineInstr *MI, unsigned OpIdx,
unsigned Pref);
bool shouldBreakDependence(MachineInstr*, unsigned OpIdx, unsigned Pref);
void processUndefReads(MachineBasicBlock*);
19 changes: 13 additions & 6 deletions lib/CodeGen/ExecutionDepsFix.cpp
Original file line number Diff line number Diff line change
@@ -288,16 +288,18 @@ bool ExecutionDepsFix::visitInstr(MachineInstr *MI) {
/// \brief Helps avoid false dependencies on undef registers by updating the
/// machine instructions' undef operand to use a register that the instruction
/// is truly dependent on, or use a register with clearance higher than Pref.
void ExecutionDepsFix::pickBestRegisterForUndef(MachineInstr *MI,
unsigned OpIdx, unsigned Pref) {
/// Returns true if it was able to find a true dependency, thus not requiring
/// a dependency breaking instruction regardless of clearance.
bool ExecutionDepsFix::pickBestRegisterForUndef(MachineInstr *MI,
unsigned OpIdx, unsigned Pref) {
MachineOperand &MO = MI->getOperand(OpIdx);
assert(MO.isUndef() && "Expected undef machine operand");

unsigned OriginalReg = MO.getReg();

// Update only undef operands that are mapped to one register.
if (AliasMap[OriginalReg].size() != 1)
return;
return false;

// Get the undef operand's register class
const TargetRegisterClass *OpRC =
@@ -312,7 +314,7 @@ void ExecutionDepsFix::pickBestRegisterForUndef(MachineInstr *MI,
// We found a true dependency - replace the undef register with the true
// dependency.
MO.setReg(CurrMO.getReg());
return;
return true;
}

// Go over all registers in the register class and find the register with
@@ -337,6 +339,8 @@ void ExecutionDepsFix::pickBestRegisterForUndef(MachineInstr *MI,
// Update the operand if we found a register with better clearance.
if (MaxClearanceReg != OriginalReg)
MO.setReg(MaxClearanceReg);

return false;
}

/// \brief Return true to if it makes sense to break dependence on a partial def
@@ -371,8 +375,11 @@ void ExecutionDepsFix::processDefs(MachineInstr *MI, bool breakDependency,
if (breakDependency) {
unsigned Pref = TII->getUndefRegClearance(*MI, OpNum, TRI);
if (Pref) {
pickBestRegisterForUndef(MI, OpNum, Pref);
if (shouldBreakDependence(MI, OpNum, 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));
}
}

0 comments on commit 54eda94

Please sign in to comment.