aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/VirtRegMap.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2007-08-14 20:23:13 +0000
committerEvan Cheng <evan.cheng@apple.com>2007-08-14 20:23:13 +0000
commitc91f0b80687f0a6fafa5a5e6cd87498e2de6fc3e (patch)
tree5d3f30b652b21d8cd3631c6f90b253546ccd2ddd /lib/CodeGen/VirtRegMap.cpp
parenta6a8663894c4eff0bd183a6209f8165680b8c913 (diff)
If a MI's def is remat as well as spilled, and the store is later deemed dead, mark the def operand as isDead.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41083 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/VirtRegMap.cpp')
-rw-r--r--lib/CodeGen/VirtRegMap.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp
index fa7951eeea..00a9bf948c 100644
--- a/lib/CodeGen/VirtRegMap.cpp
+++ b/lib/CodeGen/VirtRegMap.cpp
@@ -433,12 +433,39 @@ void AvailableSpills::ModifyStackSlotOrReMat(int SlotOrReMat) {
/// InvalidateKills - MI is going to be deleted. If any of its operands are
/// marked kill, then invalidate the information.
static void InvalidateKills(MachineInstr &MI, BitVector &RegKills,
- std::vector<MachineOperand*> &KillOps) {
+ std::vector<MachineOperand*> &KillOps,
+ MachineInstr *NewDef = NULL) {
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isReg() || !MO.isUse() || !MO.isKill())
continue;
unsigned Reg = MO.getReg();
+ if (NewDef) {
+ // Due to remat, it's possible this reg isn't being reused. That is,
+ // the def of this reg (by prev MI) is now dead.
+ bool FoundUse = false, Done = false;
+ MachineBasicBlock::iterator I = MI, E = NewDef;
+ ++I; ++E;
+ for (; !Done && I != E; ++I) {
+ MachineInstr *NMI = I;
+ for (unsigned j = 0, ee = NMI->getNumOperands(); j != ee; ++j) {
+ MachineOperand &MO = NMI->getOperand(j);
+ if (!MO.isReg() || MO.getReg() != Reg)
+ continue;
+ if (MO.isUse())
+ FoundUse = true;
+ Done = true; // Stop after scanning all the operands of this MI.
+ }
+ }
+ if (!FoundUse) {
+ // Def is dead!
+ MachineBasicBlock::iterator MII = MI;
+ MachineInstr *DefMI = prior(MII);
+ MachineOperand *DefOp = DefMI->findRegisterDefOperand(Reg);
+ assert(DefOp && "Missing def?");
+ DefOp->setIsDead();
+ }
+ }
if (KillOps[Reg] == &MO) {
RegKills.reset(Reg);
KillOps[Reg] = NULL;
@@ -1081,7 +1108,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) {
if (LastStore) {
DOUT << "Removed dead store:\t" << *LastStore;
++NumDSE;
- InvalidateKills(*LastStore, RegKills, KillOps);
+ InvalidateKills(*LastStore, RegKills, KillOps, &MI);
MBB.erase(LastStore);
VRM.RemoveFromFoldedVirtMap(LastStore);
}