From a8db456b53a1783e2c8b3f3a6666dfa715a885d4 Mon Sep 17 00:00:00 2001 From: Jeremy Morse Date: Thu, 31 Oct 2019 12:34:17 +0000 Subject: Revert "[DebugInfo] MachineSink: Insert undef DBG_VALUEs when sinking instructions" This reverts commit ee50590e1684c197bc4336984795e48bf53c7a4e. PR43855 reports a performance regression from this commit, which I'll look into. --- llvm/lib/CodeGen/MachineSink.cpp | 53 +++------------------------------------- 1 file changed, 3 insertions(+), 50 deletions(-) (limited to 'llvm/lib/CodeGen/MachineSink.cpp') diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp index 4c55158a004..27a2e7023f2 100644 --- a/llvm/lib/CodeGen/MachineSink.cpp +++ b/llvm/lib/CodeGen/MachineSink.cpp @@ -736,9 +736,6 @@ static bool SinkingPreventsImplicitNullCheck(MachineInstr &MI, static void performSink(MachineInstr &MI, MachineBasicBlock &SuccToSinkTo, MachineBasicBlock::iterator InsertPos, SmallVectorImpl *DbgVals = nullptr) { - const MachineRegisterInfo &MRI = MI.getMF()->getRegInfo(); - const TargetInstrInfo &TII = *MI.getMF()->getSubtarget().getInstrInfo(); - // If debug values are provided use those, otherwise call collectDebugValues. SmallVector DbgValuesToSink; if (DbgVals) @@ -761,57 +758,13 @@ static void performSink(MachineInstr &MI, MachineBasicBlock &SuccToSinkTo, SuccToSinkTo.splice(InsertPos, ParentBlock, MI, ++MachineBasicBlock::iterator(MI)); - // Sink a copy of debug users to the insert position. Mark the original - // DBG_VALUE location as 'undef', indicating that any earlier variable - // location should be terminated as we've optimised away the value at this - // point. - // If the sunk instruction is a copy, try to forward the copy instead of - // leaving an 'undef' DBG_VALUE in the original location. Don't do this if - // there's any subregister weirdness involved. + // Move previously adjacent debug value instructions to the insert position. for (SmallVectorImpl::iterator DBI = DbgValuesToSink.begin(), DBE = DbgValuesToSink.end(); DBI != DBE; ++DBI) { MachineInstr *DbgMI = *DBI; - MachineInstr *NewDbgMI = DbgMI->getMF()->CloneMachineInstr(*DBI); - SuccToSinkTo.insert(InsertPos, NewDbgMI); - - // Copy DBG_VALUE operand and set the original to undef. We then check to - // see whether this is something that can be copy-forwarded. If it isn't, - // continue around the loop. - MachineOperand DbgMO = DbgMI->getOperand(0); - DbgMI->getOperand(0).setReg(0); - - const MachineOperand *SrcMO = nullptr, *DstMO = nullptr; - if (!TII.isCopyInstr(MI, SrcMO, DstMO)) - continue; - - // Check validity of forwarding this copy. - bool PostRA = MRI.getNumVirtRegs() == 0; - - // Trying to forward between physical and virtual registers is too hard. - if (DbgMO.getReg().isVirtual() != SrcMO->getReg().isVirtual()) - continue; - - // Only try virtual register copy-forwarding before regalloc, and physical - // register copy-forwarding after regalloc. - bool arePhysRegs = !DbgMO.getReg().isVirtual(); - if (arePhysRegs != PostRA) - continue; - - // Pre-regalloc, only forward if all subregisters agree (or there are no - // subregs at all). More analysis might recover some forwardable copies. - if (!PostRA && (DbgMO.getSubReg() != SrcMO->getSubReg() || - DbgMO.getSubReg() != DstMO->getSubReg())) - continue; - - // Post-regalloc, we may be sinking a DBG_VALUE of a sub or super-register - // of this copy. Only forward the copy if the DBG_VALUE operand exactly - // matches the copy destination. - if (PostRA && DbgMO.getReg() != DstMO->getReg()) - continue; - - DbgMI->getOperand(0).setReg(SrcMO->getReg()); - DbgMI->getOperand(0).setSubReg(SrcMO->getSubReg()); + SuccToSinkTo.splice(InsertPos, ParentBlock, DbgMI, + ++MachineBasicBlock::iterator(DbgMI)); } } -- cgit v1.2.3