diff options
Diffstat (limited to 'llvm/lib/CodeGen/RegisterCoalescer.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/RegisterCoalescer.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/RegisterCoalescer.cpp b/llvm/lib/CodeGen/RegisterCoalescer.cpp index c067d87a9fd8..c1af37c8510f 100644 --- a/llvm/lib/CodeGen/RegisterCoalescer.cpp +++ b/llvm/lib/CodeGen/RegisterCoalescer.cpp @@ -1201,6 +1201,8 @@ bool RegisterCoalescer::removePartialRedundancy(const CoalescerPair &CP, << printMBBReference(MBB) << '\t' << CopyMI); } + const bool IsUndefCopy = CopyMI.getOperand(1).isUndef(); + // Remove CopyMI. // Note: This is fine to remove the copy before updating the live-ranges. // While updating the live-ranges, we only look at slot indices and @@ -1214,6 +1216,19 @@ bool RegisterCoalescer::removePartialRedundancy(const CoalescerPair &CP, LIS->pruneValue(*static_cast<LiveRange *>(&IntB), CopyIdx.getRegSlot(), &EndPoints); BValNo->markUnused(); + + if (IsUndefCopy) { + // We're introducing an undef phi def, and need to set undef on any users of + // the previously local def to avoid artifically extending the lifetime + // through the block. + for (MachineOperand &MO : MRI->use_nodbg_operands(IntB.reg())) { + const MachineInstr &MI = *MO.getParent(); + SlotIndex UseIdx = LIS->getInstructionIndex(MI); + if (!IntB.liveAt(UseIdx)) + MO.setIsUndef(true); + } + } + // Extend IntB to the EndPoints of its original live interval. LIS->extendToIndices(IntB, EndPoints); @@ -1596,8 +1611,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP, LR->createDeadDef(NewMIIdx.getRegSlot(), LIS->getVNInfoAllocator()); } - if (NewMI.getOperand(0).getSubReg()) - NewMI.getOperand(0).setIsUndef(); + NewMI.setRegisterDefReadUndef(NewMI.getOperand(0).getReg()); // Transfer over implicit operands to the rematerialized instruction. for (MachineOperand &MO : ImplicitOps) |
