@@ -1600,6 +1600,22 @@ bool RegisterCoalescer::reMaterializeDef(const CoalescerPair &CP,
16001600 SlotIndex DefIndex =
16011601 CurrIdx.getRegSlot (NewMI.getOperand (0 ).isEarlyClobber ());
16021602 VNInfo::Allocator &Alloc = LIS->getVNInfoAllocator ();
1603+
1604+ // Refine the subranges that are now defined by the remat.
1605+ // This will split existing subranges if necessary.
1606+ DstInt.refineSubRanges (
1607+ Alloc, DstMask,
1608+ [&DefIndex, &Alloc](LiveInterval::SubRange &SR) {
1609+ // We know that this lane is defined by this instruction,
1610+ // but at this point it might not be live because it was not defined
1611+ // by the original instruction. This happens when the
1612+ // rematerialization widens the defined register. Assign that lane a
1613+ // dead def so that the interferences are properly modeled.
1614+ if (!SR.liveAt (DefIndex))
1615+ SR.createDeadDef (DefIndex, Alloc);
1616+ },
1617+ *LIS->getSlotIndexes (), *TRI);
1618+
16031619 for (LiveInterval::SubRange &SR : DstInt.subranges ()) {
16041620 if ((SR.LaneMask & DstMask).none ()) {
16051621 LLVM_DEBUG (dbgs ()
@@ -1617,15 +1633,6 @@ bool RegisterCoalescer::reMaterializeDef(const CoalescerPair &CP,
16171633 // updateRegDefUses. The original subrange def may have only undefed
16181634 // some lanes.
16191635 UpdatedSubRanges = true ;
1620- } else {
1621- // We know that this lane is defined by this instruction,
1622- // but at this point it might not be live because it was not defined
1623- // by the original instruction. This happens when the
1624- // rematerialization widens the defined register. Assign that lane a
1625- // dead def so that the interferences are properly modeled.
1626- if (!SR.liveAt (DefIndex))
1627- SR.createDeadDef (DefIndex, Alloc);
1628- SR.LaneMask = DstMask & SR.LaneMask ;
16291636 }
16301637 }
16311638 if (UpdatedSubRanges)
0 commit comments