@@ -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.
@@ -1332,7 +1328,8 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
13321328 if (DstReg.isPhysical ()) {
13331329 Register NewDstReg = DstReg;
13341330
1335- unsigned NewDstIdx = TRI->composeSubRegIndices (CP.getSrcIdx (), DefSubIdx);
1331+ unsigned NewDstIdx = TRI->composeSubRegIndices (CP.getSrcIdx (),
1332+ DefMI->getOperand (0 ).getSubReg ());
13361333 if (NewDstIdx)
13371334 NewDstReg = TRI->getSubReg (DstReg, NewDstIdx);
13381335
@@ -1481,7 +1478,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
14811478 MRI->setRegClass (DstReg, NewRC);
14821479
14831480 // Update machine operands and add flags.
1484- updateRegDefsUses (DstReg, DstReg, DstIdx, false );
1481+ updateRegDefsUses (DstReg, DstReg, DstIdx);
14851482 NewMI.getOperand (0 ).setSubReg (NewIdx);
14861483 // updateRegDefUses can add an "undef" flag to the definition, since
14871484 // it will replace DstReg with DstReg.DstIdx. If NewIdx is 0, make
@@ -1803,7 +1800,7 @@ void RegisterCoalescer::addUndefFlag(const LiveInterval &Int, SlotIndex UseIdx,
18031800}
18041801
18051802void RegisterCoalescer::updateRegDefsUses (Register SrcReg, Register DstReg,
1806- unsigned SubIdx, bool IsSubregToReg ) {
1803+ unsigned SubIdx) {
18071804 bool DstIsPhys = DstReg.isPhysical ();
18081805 LiveInterval *DstInt = DstIsPhys ? nullptr : &LIS->getInterval (DstReg);
18091806
@@ -1843,22 +1840,16 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
18431840 if (DstInt && !Reads && SubIdx && !UseMI->isDebugInstr ())
18441841 Reads = DstInt->liveAt (LIS->getInstructionIndex (*UseMI));
18451842
1846- bool FullDef = true ;
1847-
18481843 // Replace SrcReg with DstReg in all UseMI operands.
18491844 for (unsigned i = 0 , e = Ops.size (); i != e; ++i) {
18501845 MachineOperand &MO = UseMI->getOperand (Ops[i]);
18511846
18521847 // Adjust <undef> flags in case of sub-register joins. We don't want to
18531848 // turn a full def into a read-modify-write sub-register def and vice
18541849 // versa.
1855- if (SubIdx && MO.isDef ()) {
1850+ if (SubIdx && MO.isDef ())
18561851 MO.setIsUndef (!Reads);
18571852
1858- if (!Reads)
1859- FullDef = false ;
1860- }
1861-
18621853 // A subreg use of a partially undef (super) register may be a complete
18631854 // undef use now and then has to be marked that way.
18641855 if (MO.isUse () && !DstIsPhys) {
@@ -1890,25 +1881,6 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
18901881 MO.substVirtReg (DstReg, SubIdx, *TRI);
18911882 }
18921883
1893- if (IsSubregToReg && !FullDef) {
1894- // If the coalesed instruction doesn't fully define the register, we need
1895- // to preserve the original super register liveness for SUBREG_TO_REG.
1896- //
1897- // We pretended SUBREG_TO_REG was a regular copy for coalescing purposes,
1898- // but it introduces liveness for other subregisters. Downstream users may
1899- // have been relying on those bits, so we need to ensure their liveness is
1900- // captured with a def of other lanes.
1901-
1902- // FIXME: Need to add new subrange if tracking subranges. We could also
1903- // skip adding this if we knew the other lanes are dead, and only for
1904- // other lanes.
1905-
1906- assert (!MRI->shouldTrackSubRegLiveness (DstReg) &&
1907- " this should update subranges" );
1908- MachineInstrBuilder MIB (*MF, UseMI);
1909- MIB.addReg (DstReg, RegState::ImplicitDefine);
1910- }
1911-
19121884 LLVM_DEBUG ({
19131885 dbgs () << " \t\t updated: " ;
19141886 if (!UseMI->isDebugInstr ())
@@ -2108,8 +2080,6 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
21082080 });
21092081 }
21102082
2111- const bool IsSubregToReg = CopyMI->isSubregToReg ();
2112-
21132083 ShrinkMask = LaneBitmask::getNone ();
21142084 ShrinkMainRange = false ;
21152085
@@ -2177,12 +2147,9 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
21772147
21782148 // Rewrite all SrcReg operands to DstReg.
21792149 // Also update DstReg operands to include DstIdx if it is set.
2180- if (CP.getDstIdx ()) {
2181- assert (!IsSubregToReg && " can this happen?" );
2182- updateRegDefsUses (CP.getDstReg (), CP.getDstReg (), CP.getDstIdx (), false );
2183- }
2184- updateRegDefsUses (CP.getSrcReg (), CP.getDstReg (), CP.getSrcIdx (),
2185- IsSubregToReg);
2150+ if (CP.getDstIdx ())
2151+ updateRegDefsUses (CP.getDstReg (), CP.getDstReg (), CP.getDstIdx ());
2152+ updateRegDefsUses (CP.getSrcReg (), CP.getDstReg (), CP.getSrcIdx ());
21862153
21872154 // Shrink subregister ranges if necessary.
21882155 if (ShrinkMask.any ()) {
0 commit comments