From 5379f412bc6ac6171f3bd73930197bfce88c2faa Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Fri, 19 Dec 2008 20:58:01 +0000 Subject: Fix PR3149. If an early clobber def is a physical register and it is tied to an input operand, it effectively extends the live range of the physical register. Currently we do not have a good way to represent this. 172 %ECX = MOV32rr %reg1039 180 INLINEASM , 10, %EAX, 14, %ECX, 9, %EAX, 36, , 1, %reg0, 0, 9, %ECX, 36, , 1, %reg0, 0 188 %EAX = MOV32rr %EAX 196 %ECX = MOV32rr %ECX 204 %ECX = MOV32rr %ECX 212 %EAX = MOV32rr %EAX 220 %EAX = MOV32rr %EAX 228 %reg1039 = MOV32rr %ECX The early clobber operand ties ECX input to the ECX def. The live interval of ECX is represented as this: %reg20,inf = [46,47:1)[174,230:0) 0@174-(230) 1@46-(47) The right way to represent this is something like %reg20,inf = [46,47:2)[174,182:1)[181:230:0) 0@174-(182) 1@181-230 @2@46-(47) Of course that won't work since that means overlapping live ranges defined by two val#. The workaround for now is to add a bit to val# which says the val# is redefined by a early clobber def somewhere. This prevents the move at 228 from being optimized away by SimpleRegisterCoalescing::AdjustCopiesBackFrom. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61259 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/LiveIntervalAnalysis.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/CodeGen/LiveIntervalAnalysis.cpp') diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp index 52b57d6d2e..1900c1a4d7 100644 --- a/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -360,6 +360,7 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb, mi->getOpcode() == TargetInstrInfo::INSERT_SUBREG || tii_->isMoveInstr(*mi, SrcReg, DstReg)) CopyMI = mi; + // Earlyclobbers move back one. ValNo = interval.getNextValue(defIndex, CopyMI, VNInfoAllocator); assert(ValNo->id == 0 && "First value in interval is not 0?"); @@ -435,9 +436,8 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb, assert(interval.containsOneValue()); unsigned DefIndex = getDefIndex(interval.getValNumInfo(0)->def); unsigned RedefIndex = getDefIndex(MIIdx); - // Earlyclobbers move back one. - if (MO.isEarlyClobber()) - RedefIndex = getUseIndex(MIIdx); + // It cannot be an early clobber MO. + assert(!MO.isEarlyClobber() && "Unexpected early clobber!"); const LiveRange *OldLR = interval.getLiveRangeContaining(RedefIndex-1); VNInfo *OldValNo = OldLR->valno; @@ -505,9 +505,8 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb, // live until the end of the block. We've already taken care of the // rest of the live range. unsigned defIndex = getDefIndex(MIIdx); - // Earlyclobbers move back one. - if (MO.isEarlyClobber()) - defIndex = getUseIndex(MIIdx); + // It cannot be an early clobber MO. + assert(!MO.isEarlyClobber() && "Unexpected early clobber!"); VNInfo *ValNo; MachineInstr *CopyMI = NULL; @@ -592,8 +591,11 @@ exit: // Already exists? Extend old live interval. LiveInterval::iterator OldLR = interval.FindLiveRangeContaining(start); - VNInfo *ValNo = (OldLR != interval.end()) + bool Extend = OldLR != interval.end(); + VNInfo *ValNo = Extend ? OldLR->valno : interval.getNextValue(start, CopyMI, VNInfoAllocator); + if (MO.isEarlyClobber() && Extend) + ValNo->redefByEC = true; LiveRange LR(start, end, ValNo); interval.addRange(LR); interval.addKill(LR.valno, end); -- cgit v1.2.3-70-g09d2