@@ -305,11 +305,7 @@ namespace {
305
305
// / number if it is not zero. If DstReg is a physical register and the
306
306
// / existing subregister number of the def / use being updated is not zero,
307
307
// / 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);
313
309
314
310
// / If the given machine operand reads only undefined lanes add an undef
315
311
// / flag.
@@ -1332,7 +1328,8 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
1332
1328
if (DstReg.isPhysical ()) {
1333
1329
Register NewDstReg = DstReg;
1334
1330
1335
- unsigned NewDstIdx = TRI->composeSubRegIndices (CP.getSrcIdx (), DefSubIdx);
1331
+ unsigned NewDstIdx = TRI->composeSubRegIndices (CP.getSrcIdx (),
1332
+ DefMI->getOperand (0 ).getSubReg ());
1336
1333
if (NewDstIdx)
1337
1334
NewDstReg = TRI->getSubReg (DstReg, NewDstIdx);
1338
1335
@@ -1481,7 +1478,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
1481
1478
MRI->setRegClass (DstReg, NewRC);
1482
1479
1483
1480
// Update machine operands and add flags.
1484
- updateRegDefsUses (DstReg, DstReg, DstIdx, false );
1481
+ updateRegDefsUses (DstReg, DstReg, DstIdx);
1485
1482
NewMI.getOperand (0 ).setSubReg (NewIdx);
1486
1483
// updateRegDefUses can add an "undef" flag to the definition, since
1487
1484
// it will replace DstReg with DstReg.DstIdx. If NewIdx is 0, make
@@ -1796,7 +1793,7 @@ void RegisterCoalescer::addUndefFlag(const LiveInterval &Int, SlotIndex UseIdx,
1796
1793
}
1797
1794
1798
1795
void RegisterCoalescer::updateRegDefsUses (Register SrcReg, Register DstReg,
1799
- unsigned SubIdx, bool IsSubregToReg ) {
1796
+ unsigned SubIdx) {
1800
1797
bool DstIsPhys = DstReg.isPhysical ();
1801
1798
LiveInterval *DstInt = DstIsPhys ? nullptr : &LIS->getInterval (DstReg);
1802
1799
@@ -1836,22 +1833,16 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
1836
1833
if (DstInt && !Reads && SubIdx && !UseMI->isDebugInstr ())
1837
1834
Reads = DstInt->liveAt (LIS->getInstructionIndex (*UseMI));
1838
1835
1839
- bool FullDef = true ;
1840
-
1841
1836
// Replace SrcReg with DstReg in all UseMI operands.
1842
1837
for (unsigned i = 0 , e = Ops.size (); i != e; ++i) {
1843
1838
MachineOperand &MO = UseMI->getOperand (Ops[i]);
1844
1839
1845
1840
// Adjust <undef> flags in case of sub-register joins. We don't want to
1846
1841
// turn a full def into a read-modify-write sub-register def and vice
1847
1842
// versa.
1848
- if (SubIdx && MO.isDef ()) {
1843
+ if (SubIdx && MO.isDef ())
1849
1844
MO.setIsUndef (!Reads);
1850
1845
1851
- if (!Reads)
1852
- FullDef = false ;
1853
- }
1854
-
1855
1846
// A subreg use of a partially undef (super) register may be a complete
1856
1847
// undef use now and then has to be marked that way.
1857
1848
if (MO.isUse () && !DstIsPhys) {
@@ -1883,25 +1874,6 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
1883
1874
MO.substVirtReg (DstReg, SubIdx, *TRI);
1884
1875
}
1885
1876
1886
- if (IsSubregToReg && !FullDef) {
1887
- // If the coalesed instruction doesn't fully define the register, we need
1888
- // to preserve the original super register liveness for SUBREG_TO_REG.
1889
- //
1890
- // We pretended SUBREG_TO_REG was a regular copy for coalescing purposes,
1891
- // but it introduces liveness for other subregisters. Downstream users may
1892
- // have been relying on those bits, so we need to ensure their liveness is
1893
- // captured with a def of other lanes.
1894
-
1895
- // FIXME: Need to add new subrange if tracking subranges. We could also
1896
- // skip adding this if we knew the other lanes are dead, and only for
1897
- // other lanes.
1898
-
1899
- assert (!MRI->shouldTrackSubRegLiveness (DstReg) &&
1900
- " this should update subranges" );
1901
- MachineInstrBuilder MIB (*MF, UseMI);
1902
- MIB.addReg (DstReg, RegState::ImplicitDefine);
1903
- }
1904
-
1905
1877
LLVM_DEBUG ({
1906
1878
dbgs () << " \t\t updated: " ;
1907
1879
if (!UseMI->isDebugInstr ())
@@ -2101,8 +2073,6 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
2101
2073
});
2102
2074
}
2103
2075
2104
- const bool IsSubregToReg = CopyMI->isSubregToReg ();
2105
-
2106
2076
ShrinkMask = LaneBitmask::getNone ();
2107
2077
ShrinkMainRange = false ;
2108
2078
@@ -2170,12 +2140,9 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
2170
2140
2171
2141
// Rewrite all SrcReg operands to DstReg.
2172
2142
// Also update DstReg operands to include DstIdx if it is set.
2173
- if (CP.getDstIdx ()) {
2174
- assert (!IsSubregToReg && " can this happen?" );
2175
- updateRegDefsUses (CP.getDstReg (), CP.getDstReg (), CP.getDstIdx (), false );
2176
- }
2177
- updateRegDefsUses (CP.getSrcReg (), CP.getDstReg (), CP.getSrcIdx (),
2178
- IsSubregToReg);
2143
+ if (CP.getDstIdx ())
2144
+ updateRegDefsUses (CP.getDstReg (), CP.getDstReg (), CP.getDstIdx ());
2145
+ updateRegDefsUses (CP.getSrcReg (), CP.getDstReg (), CP.getSrcIdx ());
2179
2146
2180
2147
// Shrink subregister ranges if necessary.
2181
2148
if (ShrinkMask.any ()) {
0 commit comments