Incorporate suggestions Chad, Jakob and Evan's suggestions on r149957.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149655 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Lang Hames 2012-02-03 01:13:49 +00:00
parent 16717a7c56
commit 6e3f7e4913

View File

@ -12052,28 +12052,39 @@ X86TargetLowering::EmitVAStartSaveXMMRegsWithCustomInserter(
return EndMBB; return EndMBB;
} }
// Check whether the given instruction should have had a kill marker on // The EFLAGS operand of SelectItr might be missing a kill marker
// the EFLAGS operand. // because there were multiple uses of EFLAGS, and ISel didn't know
static bool shouldHaveEFlagsKill(MachineBasicBlock::iterator SelectItr, // which to mark. Figure out whether SelectItr should have had a
MachineBasicBlock* BB) { // kill marker, and set it if it should. Returns the correct kill
for (MachineBasicBlock::iterator miI(llvm::next(SelectItr)), miE = BB->end(); // marker value.
miI != miE; ++miI) { static bool checkAndUpdateEFLAGSKill(MachineBasicBlock::iterator SelectItr,
MachineBasicBlock* BB,
const TargetRegisterInfo* TRI) {
// Scan forward through BB for a use/def of EFLAGS.
MachineBasicBlock::iterator miI(llvm::next(SelectItr));
for (MachineBasicBlock::iterator miE = BB->end(); miI != miE; ++miI) {
const MachineInstr& mi = *miI; const MachineInstr& mi = *miI;
if (mi.readsRegister(X86::EFLAGS)) { if (mi.readsRegister(X86::EFLAGS))
return false; return false;
} if (mi.definesRegister(X86::EFLAGS))
if (mi.definesRegister(X86::EFLAGS)) { break; // Should have kill-flag - update below.
// Should have kill-flag - update below. }
break;
// If we hit the end of the block, check whether EFLAGS is live into a
// successor.
if (miI == BB->end()) {
for (MachineBasicBlock::succ_iterator sItr = BB->succ_begin(),
sEnd = BB->succ_end();
sItr != sEnd; ++sItr) {
MachineBasicBlock* succ = *sItr;
if (succ->isLiveIn(X86::EFLAGS))
return false;
} }
} }
// We found a def, or hit the end of the basic block. SelectMI should have a // We found a def, or hit the end of the basic block and EFLAGS wasn't live
// kill flag on EFLAGS. // out. SelectMI should have a kill flag on EFLAGS.
MachineInstr& SelectMI = *SelectItr; SelectItr->addRegisterKilled(X86::EFLAGS, TRI);
MachineOperand* EFlagsOp = SelectMI.findRegisterUseOperand(X86::EFLAGS);
assert(EFlagsOp != 0 && "No EFLAGS operand on select instruction?");
EFlagsOp->setIsKill();
return true; return true;
} }
@ -12106,11 +12117,11 @@ X86TargetLowering::EmitLoweredSelect(MachineInstr *MI,
// If the EFLAGS register isn't dead in the terminator, then claim that it's // If the EFLAGS register isn't dead in the terminator, then claim that it's
// live into the sink and copy blocks. // live into the sink and copy blocks.
if (!MI->killsRegister(X86::EFLAGS)) { const TargetRegisterInfo* TRI = getTargetMachine().getRegisterInfo();
if (!shouldHaveEFlagsKill(MI, BB)) { if (!MI->killsRegister(X86::EFLAGS) &&
copy0MBB->addLiveIn(X86::EFLAGS); !checkAndUpdateEFLAGSKill(MI, BB, TRI)) {
sinkMBB->addLiveIn(X86::EFLAGS); copy0MBB->addLiveIn(X86::EFLAGS);
} sinkMBB->addLiveIn(X86::EFLAGS);
} }
// Transfer the remainder of BB and its successor edges to sinkMBB. // Transfer the remainder of BB and its successor edges to sinkMBB.