From: Evan Cheng Date: Tue, 14 Aug 2007 05:42:54 +0000 (+0000) Subject: If a rematerializable def is not deleted, i.e. it is also spilled, check if the X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=dc6be1985944716a0fb4a2706dcea9e1296e3d6a;p=oota-llvm.git If a rematerializable def is not deleted, i.e. it is also spilled, check if the spilled value is available for reuse. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41067 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp index 9d57a0a2678..e996374367f 100644 --- a/lib/CodeGen/VirtRegMap.cpp +++ b/lib/CodeGen/VirtRegMap.cpp @@ -744,10 +744,19 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { bool DoReMat = VRM.isReMaterialized(VirtReg); int SSorRMId = DoReMat ? VRM.getReMatId(VirtReg) : VRM.getStackSlot(VirtReg); - unsigned PhysReg; + int ReuseSlot = SSorRMId; // Check to see if this stack slot is available. - if ((PhysReg = Spills.getSpillSlotOrReMatPhysReg(SSorRMId))) { + unsigned PhysReg = Spills.getSpillSlotOrReMatPhysReg(SSorRMId); + if (!PhysReg && DoReMat) { + // This use is rematerializable. But perhaps the value is available in + // stack if the definition is not deleted. If so, check if we can + // reuse the value. + ReuseSlot = VRM.getStackSlot(VirtReg); + if (ReuseSlot != VirtRegMap::NO_STACK_SLOT) + PhysReg = Spills.getSpillSlotOrReMatPhysReg(ReuseSlot); + } + if (PhysReg) { // This spilled operand might be part of a two-address operand. If this // is the case, then changing it will necessarily require changing the // def part of the instruction as well. However, in some cases, we @@ -761,16 +770,16 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { // Okay, we have a two address operand. We can reuse this physreg as // long as we are allowed to clobber the value and there isn't an // earlier def that has already clobbered the physreg. - CanReuse = Spills.canClobberPhysReg(SSorRMId) && + CanReuse = Spills.canClobberPhysReg(ReuseSlot) && !ReusedOperands.isClobbered(PhysReg); } if (CanReuse) { // If this stack slot value is already available, reuse it! - if (SSorRMId > VirtRegMap::MAX_STACK_SLOT) - DOUT << "Reusing RM#" << SSorRMId-VirtRegMap::MAX_STACK_SLOT-1; + if (ReuseSlot > VirtRegMap::MAX_STACK_SLOT) + DOUT << "Reusing RM#" << ReuseSlot-VirtRegMap::MAX_STACK_SLOT-1; else - DOUT << "Reusing SS#" << SSorRMId; + DOUT << "Reusing SS#" << ReuseSlot; DOUT << " from physreg " << MRI->getName(PhysReg) << " for vreg" << VirtReg <<" instead of reloading into physreg " @@ -791,7 +800,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { // or R0 and R1 might not be compatible with each other. In this // case, we actually insert a reload for V1 in R1, ensuring that // we can get at R0 or its alias. - ReusedOperands.addReuse(i, SSorRMId, PhysReg, + ReusedOperands.addReuse(i, ReuseSlot, PhysReg, VRM.getPhys(VirtReg), VirtReg); if (ti != -1) // Only mark it clobbered if this is a use&def operand. @@ -825,10 +834,10 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { // incoming, we don't need to inserted a dead copy. if (DesignatedReg == PhysReg) { // If this stack slot value is already available, reuse it! - if (SSorRMId > VirtRegMap::MAX_STACK_SLOT) - DOUT << "Reusing RM#" << SSorRMId-VirtRegMap::MAX_STACK_SLOT-1; + if (ReuseSlot > VirtRegMap::MAX_STACK_SLOT) + DOUT << "Reusing RM#" << ReuseSlot-VirtRegMap::MAX_STACK_SLOT-1; else - DOUT << "Reusing SS#" << SSorRMId; + DOUT << "Reusing SS#" << ReuseSlot; DOUT << " from physreg " << MRI->getName(PhysReg) << " for vreg" << VirtReg << " instead of reloading into same physreg.\n"; @@ -849,7 +858,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { // This invalidates DesignatedReg. Spills.ClobberPhysReg(DesignatedReg); - Spills.addAvailable(SSorRMId, &MI, DesignatedReg); + Spills.addAvailable(ReuseSlot, &MI, DesignatedReg); MI.getOperand(i).setReg(DesignatedReg); DOUT << '\t' << *prior(MII); ++NumReused;