@@ -305,11 +305,7 @@ namespace {
305305 // / number if it is not zero. If DstReg is a physical register and the
306306 // / existing subregister number of the def / use being updated is not zero,
307307 // / make sure to set it to the correct physical subregister.
308- // /
309- // / If \p IsSubregToReg, we are coalescing a DstReg = SUBREG_TO_REG
310- // / SrcReg. This introduces an implicit-def of DstReg on coalesced users.
311- void updateRegDefsUses (Register SrcReg, Register DstReg, unsigned SubIdx,
312- bool IsSubregToReg);
308+ void updateRegDefsUses (Register SrcReg, Register DstReg, unsigned SubIdx);
313309
314310 // / If the given machine operand reads only undefined lanes add an undef
315311 // / flag.
@@ -1327,7 +1323,8 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
13271323 if (DstReg.isPhysical ()) {
13281324 Register NewDstReg = DstReg;
13291325
1330- unsigned NewDstIdx = TRI->composeSubRegIndices (CP.getSrcIdx (), DefSubIdx);
1326+ unsigned NewDstIdx = TRI->composeSubRegIndices (CP.getSrcIdx (),
1327+ DefMI->getOperand (0 ).getSubReg ());
13311328 if (NewDstIdx)
13321329 NewDstReg = TRI->getSubReg (DstReg, NewDstIdx);
13331330
@@ -1471,7 +1468,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
14711468 MRI->setRegClass (DstReg, NewRC);
14721469
14731470 // Update machine operands and add flags.
1474- updateRegDefsUses (DstReg, DstReg, DstIdx, false );
1471+ updateRegDefsUses (DstReg, DstReg, DstIdx);
14751472 NewMI.getOperand (0 ).setSubReg (NewIdx);
14761473 // updateRegDefUses can add an "undef" flag to the definition, since
14771474 // it will replace DstReg with DstReg.DstIdx. If NewIdx is 0, make
@@ -1786,7 +1783,7 @@ void RegisterCoalescer::addUndefFlag(const LiveInterval &Int, SlotIndex UseIdx,
17861783}
17871784
17881785void RegisterCoalescer::updateRegDefsUses (Register SrcReg, Register DstReg,
1789- unsigned SubIdx, bool IsSubregToReg ) {
1786+ unsigned SubIdx) {
17901787 bool DstIsPhys = DstReg.isPhysical ();
17911788 LiveInterval *DstInt = DstIsPhys ? nullptr : &LIS->getInterval (DstReg);
17921789
@@ -1826,22 +1823,16 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
18261823 if (DstInt && !Reads && SubIdx && !UseMI->isDebugInstr ())
18271824 Reads = DstInt->liveAt (LIS->getInstructionIndex (*UseMI));
18281825
1829- bool FullDef = true ;
1830-
18311826 // Replace SrcReg with DstReg in all UseMI operands.
18321827 for (unsigned i = 0 , e = Ops.size (); i != e; ++i) {
18331828 MachineOperand &MO = UseMI->getOperand (Ops[i]);
18341829
18351830 // Adjust <undef> flags in case of sub-register joins. We don't want to
18361831 // turn a full def into a read-modify-write sub-register def and vice
18371832 // versa.
1838- if (SubIdx && MO.isDef ()) {
1833+ if (SubIdx && MO.isDef ())
18391834 MO.setIsUndef (!Reads);
18401835
1841- if (!Reads)
1842- FullDef = false ;
1843- }
1844-
18451836 // A subreg use of a partially undef (super) register may be a complete
18461837 // undef use now and then has to be marked that way.
18471838 if (MO.isUse () && !DstIsPhys) {
@@ -1873,25 +1864,6 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
18731864 MO.substVirtReg (DstReg, SubIdx, *TRI);
18741865 }
18751866
1876- if (IsSubregToReg && !FullDef) {
1877- // If the coalesed instruction doesn't fully define the register, we need
1878- // to preserve the original super register liveness for SUBREG_TO_REG.
1879- //
1880- // We pretended SUBREG_TO_REG was a regular copy for coalescing purposes,
1881- // but it introduces liveness for other subregisters. Downstream users may
1882- // have been relying on those bits, so we need to ensure their liveness is
1883- // captured with a def of other lanes.
1884-
1885- // FIXME: Need to add new subrange if tracking subranges. We could also
1886- // skip adding this if we knew the other lanes are dead, and only for
1887- // other lanes.
1888-
1889- assert (!MRI->shouldTrackSubRegLiveness (DstReg) &&
1890- " this should update subranges" );
1891- MachineInstrBuilder MIB (*MF, UseMI);
1892- MIB.addReg (DstReg, RegState::ImplicitDefine);
1893- }
1894-
18951867 LLVM_DEBUG ({
18961868 dbgs () << " \t\t updated: " ;
18971869 if (!UseMI->isDebugInstr ())
@@ -2091,8 +2063,6 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
20912063 });
20922064 }
20932065
2094- const bool IsSubregToReg = CopyMI->isSubregToReg ();
2095-
20962066 ShrinkMask = LaneBitmask::getNone ();
20972067 ShrinkMainRange = false ;
20982068
@@ -2160,12 +2130,9 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
21602130
21612131 // Rewrite all SrcReg operands to DstReg.
21622132 // Also update DstReg operands to include DstIdx if it is set.
2163- if (CP.getDstIdx ()) {
2164- assert (!IsSubregToReg && " can this happen?" );
2165- updateRegDefsUses (CP.getDstReg (), CP.getDstReg (), CP.getDstIdx (), false );
2166- }
2167- updateRegDefsUses (CP.getSrcReg (), CP.getDstReg (), CP.getSrcIdx (),
2168- IsSubregToReg);
2133+ if (CP.getDstIdx ())
2134+ updateRegDefsUses (CP.getDstReg (), CP.getDstReg (), CP.getDstIdx ());
2135+ updateRegDefsUses (CP.getSrcReg (), CP.getDstReg (), CP.getSrcIdx ());
21692136
21702137 // Shrink subregister ranges if necessary.
21712138 if (ShrinkMask.any ()) {
0 commit comments