From 015a147c9f903dc8a7b4d8b7009248c2bf64da43 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 30 Aug 2018 07:18:10 +0000 Subject: CodeGen: Make computeRegisterLiveness search forward first If there is an unused def, this would previously report that the register was live. Check for uses first so that it is reported as dead if never used. llvm-svn: 341027 --- llvm/lib/CodeGen/MachineBasicBlock.cpp | 68 +++++++++++++++++----------------- 1 file changed, 35 insertions(+), 33 deletions(-) (limited to 'llvm/lib/CodeGen/MachineBasicBlock.cpp') diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index 62c360c51006..71fdb0f90f22 100644 --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -1375,8 +1375,42 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI, unsigned Neighborhood) const { unsigned N = Neighborhood; - // Start by searching backwards from Before, looking for kills, reads or defs. + // Try searching forwards from Before, looking for reads or defs. const_iterator I(Before); + // If this is the last insn in the block, don't search forwards. + if (I != end()) { + for (++I; I != end() && N > 0; ++I, --N) { + MachineOperandIteratorBase::PhysRegInfo Info = + ConstMIOperands(*I).analyzePhysReg(Reg, TRI); + + // Register is live when we read it here. + if (Info.Read) + return LQR_Live; + // Register is dead if we can fully overwrite or clobber it here. + if (Info.FullyDefined || Info.Clobbered) + return LQR_Dead; + } + } + + // If we reached the end, it is safe to clobber Reg at the end of a block of + // no successor has it live in. + if (I == end()) { + for (MachineBasicBlock *S : successors()) { + for (MCSubRegIterator SubReg(Reg, TRI, /*IncludeSelf*/true); + SubReg.isValid(); ++SubReg) { + if (S->isLiveIn(*SubReg)) + return LQR_Live; + } + } + + return LQR_Dead; + } + + + N = Neighborhood; + + // Start by searching backwards from Before, looking for kills, reads or defs. + I = const_iterator(Before); // If this is the first insn in the block, don't search backwards. if (I != begin()) { do { @@ -1420,38 +1454,6 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI, return LQR_Dead; } - N = Neighborhood; - - // Try searching forwards from Before, looking for reads or defs. - I = const_iterator(Before); - // If this is the last insn in the block, don't search forwards. - if (I != end()) { - for (++I; I != end() && N > 0; ++I, --N) { - MachineOperandIteratorBase::PhysRegInfo Info = - ConstMIOperands(*I).analyzePhysReg(Reg, TRI); - - // Register is live when we read it here. - if (Info.Read) - return LQR_Live; - // Register is dead if we can fully overwrite or clobber it here. - if (Info.FullyDefined || Info.Clobbered) - return LQR_Dead; - } - } - - // If we reached the end, it is safe to clobber Reg at the end of a block of - // no successor has it live in. - if (I == end()) { - for (MachineBasicBlock *S : successors()) { - for (MCSubRegIterator SubReg(Reg, TRI, /*IncludeSelf*/true); - SubReg.isValid(); ++SubReg) { - if (S->isLiveIn(*SubReg)) - return LQR_Live; - } - } - - return LQR_Dead; - } // At this point we have no idea of the liveness of the register. return LQR_Unknown; -- cgit v1.2.3