Fix addRegisterDead and addRegisterKilled to be more thorough

when searching for redundant subregister dead/kill bits.

Previously it was common to see instructions marked like this:
  "RET %EAX<imp-use,kill>, %AX<imp-use,kill>"

With this change, addRegisterKilled continues scanning after
finding the %EAX operand, so it proceeds to discover the
redundant %AX kill and eliminates it, producing this:
  "RET %EAX<imp-use,kill>"

This currently has no effect on the generated code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55698 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2008-09-03 15:56:16 +00:00
parent d0ac373660
commit 3f62940561

View File

@@ -800,6 +800,7 @@ bool MachineInstr::addRegisterKilled(unsigned IncomingReg,
bool AddIfNotFound) { bool AddIfNotFound) {
bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg); bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg);
bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg); bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg);
bool Found = false;
SmallVector<unsigned,4> DeadOps; SmallVector<unsigned,4> DeadOps;
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
MachineOperand &MO = getOperand(i); MachineOperand &MO = getOperand(i);
@@ -810,11 +811,15 @@ bool MachineInstr::addRegisterKilled(unsigned IncomingReg,
continue; continue;
if (Reg == IncomingReg) { if (Reg == IncomingReg) {
MO.setIsKill(); if (!Found) {
return true; if (MO.isKill())
} // The register is already marked kill.
if (hasAliases && MO.isKill() && return true;
TargetRegisterInfo::isPhysicalRegister(Reg)) { MO.setIsKill();
Found = true;
}
} else if (hasAliases && MO.isKill() &&
TargetRegisterInfo::isPhysicalRegister(Reg)) {
// A super-register kill already exists. // A super-register kill already exists.
if (RegInfo->isSuperRegister(IncomingReg, Reg)) if (RegInfo->isSuperRegister(IncomingReg, Reg))
return true; return true;
@@ -835,14 +840,14 @@ bool MachineInstr::addRegisterKilled(unsigned IncomingReg,
// If not found, this means an alias of one of the operands is killed. Add a // If not found, this means an alias of one of the operands is killed. Add a
// new implicit operand if required. // new implicit operand if required.
if (AddIfNotFound) { if (!Found && AddIfNotFound) {
addOperand(MachineOperand::CreateReg(IncomingReg, addOperand(MachineOperand::CreateReg(IncomingReg,
false /*IsDef*/, false /*IsDef*/,
true /*IsImp*/, true /*IsImp*/,
true /*IsKill*/)); true /*IsKill*/));
return true; return true;
} }
return false; return Found;
} }
bool MachineInstr::addRegisterDead(unsigned IncomingReg, bool MachineInstr::addRegisterDead(unsigned IncomingReg,
@@ -850,18 +855,26 @@ bool MachineInstr::addRegisterDead(unsigned IncomingReg,
bool AddIfNotFound) { bool AddIfNotFound) {
bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg); bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg);
bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg); bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg);
bool Found = false;
SmallVector<unsigned,4> DeadOps; SmallVector<unsigned,4> DeadOps;
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
MachineOperand &MO = getOperand(i); MachineOperand &MO = getOperand(i);
if (!MO.isRegister() || !MO.isDef()) if (!MO.isRegister() || !MO.isDef())
continue; continue;
unsigned Reg = MO.getReg(); unsigned Reg = MO.getReg();
if (!Reg)
continue;
if (Reg == IncomingReg) { if (Reg == IncomingReg) {
MO.setIsDead(); if (!Found) {
return true; if (MO.isDead())
} // The register is already marked dead.
if (hasAliases && MO.isDead() && return true;
TargetRegisterInfo::isPhysicalRegister(Reg)) { MO.setIsDead();
Found = true;
}
} else if (hasAliases && MO.isDead() &&
TargetRegisterInfo::isPhysicalRegister(Reg)) {
// There exists a super-register that's marked dead. // There exists a super-register that's marked dead.
if (RegInfo->isSuperRegister(IncomingReg, Reg)) if (RegInfo->isSuperRegister(IncomingReg, Reg))
return true; return true;
@@ -882,13 +895,15 @@ bool MachineInstr::addRegisterDead(unsigned IncomingReg,
DeadOps.pop_back(); DeadOps.pop_back();
} }
// If not found, this means an alias of one of the operand is dead. Add a // If not found, this means an alias of one of the operands is dead. Add a
// new implicit operand. // new implicit operand if required.
if (AddIfNotFound) { if (!Found && AddIfNotFound) {
addOperand(MachineOperand::CreateReg(IncomingReg, true/*IsDef*/, addOperand(MachineOperand::CreateReg(IncomingReg,
true/*IsImp*/,false/*IsKill*/, true /*IsDef*/,
true/*IsDead*/)); true /*IsImp*/,
false /*IsKill*/,
true /*IsDead*/));
return true; return true;
} }
return false; return Found;
} }