MachineCSE: Clear dead-def flag on CSE.

In case CSE reuses a previoulsy unused register the dead-def flag has to
be cleared on the def operand, as exposed by the arm64-cse.ll test.

This fixes PR22439 and the corresponding rdar://19694987

Differential Revision: http://reviews.llvm.org/D7395

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228178 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Matthias Braun 2015-02-04 19:35:16 +00:00
parent 7724d08fc6
commit a602c10686
4 changed files with 21 additions and 3 deletions

View File

@ -1048,6 +1048,9 @@ public:
bool addRegisterDead(unsigned Reg, const TargetRegisterInfo *RegInfo, bool addRegisterDead(unsigned Reg, const TargetRegisterInfo *RegInfo,
bool AddIfNotFound = false); bool AddIfNotFound = false);
/// Clear all dead flags on operands defining register @p Reg.
void clearRegisterDeads(unsigned Reg);
/// Mark all subregister defs of register @p Reg with the undef flag. /// Mark all subregister defs of register @p Reg with the undef flag.
/// This function is used when we determined to have a subregister def in an /// This function is used when we determined to have a subregister def in an
/// otherwise undefined super register. /// otherwise undefined super register.

View File

@ -580,8 +580,15 @@ bool MachineCSE::ProcessBlock(MachineBasicBlock *MBB) {
// Actually perform the elimination. // Actually perform the elimination.
if (DoCSE) { if (DoCSE) {
for (unsigned i = 0, e = CSEPairs.size(); i != e; ++i) { for (unsigned i = 0, e = CSEPairs.size(); i != e; ++i) {
MRI->replaceRegWith(CSEPairs[i].first, CSEPairs[i].second); unsigned OldReg = CSEPairs[i].first;
MRI->clearKillFlags(CSEPairs[i].second); unsigned NewReg = CSEPairs[i].second;
// OldReg may have been unused but is used now, clear the Dead flag
MachineInstr *Def = MRI->getUniqueVRegDef(NewReg);
assert(Def != nullptr && "CSEd register has no unique definition?");
Def->clearRegisterDeads(NewReg);
// Replace with NewReg and clear kill flags which may be wrong now.
MRI->replaceRegWith(OldReg, NewReg);
MRI->clearKillFlags(NewReg);
} }
// Go through implicit defs of CSMI and MI, if a def is not dead at MI, // Go through implicit defs of CSMI and MI, if a def is not dead at MI,

View File

@ -1889,6 +1889,14 @@ bool MachineInstr::addRegisterDead(unsigned Reg,
return true; return true;
} }
void MachineInstr::clearRegisterDeads(unsigned Reg) {
for (MachineOperand &MO : operands()) {
if (!MO.isReg() || !MO.isDef() || MO.getReg() != Reg)
continue;
MO.setIsDead(false);
}
}
void MachineInstr::addRegisterDefReadUndef(unsigned Reg) { void MachineInstr::addRegisterDefReadUndef(unsigned Reg) {
for (MachineOperand &MO : operands()) { for (MachineOperand &MO : operands()) {
if (!MO.isReg() || !MO.isDef() || MO.getReg() != Reg || MO.getSubReg() == 0) if (!MO.isReg() || !MO.isDef() || MO.getReg() != Reg || MO.getSubReg() == 0)

View File

@ -1,4 +1,4 @@
; RUN: llc -O3 < %s -aarch64-atomic-cfg-tidy=0 -aarch64-gep-opt=false | FileCheck %s ; RUN: llc -O3 < %s -aarch64-atomic-cfg-tidy=0 -aarch64-gep-opt=false -verify-machineinstrs | FileCheck %s
target triple = "arm64-apple-ios" target triple = "arm64-apple-ios"
; rdar://12462006 ; rdar://12462006