@@ -306,11 +306,7 @@ namespace {
306
306
// / number if it is not zero. If DstReg is a physical register and the
307
307
// / existing subregister number of the def / use being updated is not zero,
308
308
// / make sure to set it to the correct physical subregister.
309
- // /
310
- // / If \p IsSubregToReg, we are coalescing a DstReg = SUBREG_TO_REG
311
- // / SrcReg. This introduces an implicit-def of DstReg on coalesced users.
312
- void updateRegDefsUses (Register SrcReg, Register DstReg, unsigned SubIdx,
313
- bool IsSubregToReg);
309
+ void updateRegDefsUses (Register SrcReg, Register DstReg, unsigned SubIdx);
314
310
315
311
// / If the given machine operand reads only undefined lanes add an undef
316
312
// / flag.
@@ -1434,7 +1430,6 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
1434
1430
1435
1431
// CopyMI may have implicit operands, save them so that we can transfer them
1436
1432
// over to the newly materialized instruction after CopyMI is removed.
1437
- LaneBitmask NewMIImplicitOpsMask;
1438
1433
SmallVector<MachineOperand, 4 > ImplicitOps;
1439
1434
ImplicitOps.reserve (CopyMI->getNumOperands () -
1440
1435
CopyMI->getDesc ().getNumOperands ());
@@ -1448,9 +1443,6 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
1448
1443
(MO.getSubReg () == 0 && MO.getReg () == DstOperand.getReg ())) &&
1449
1444
" unexpected implicit virtual register def" );
1450
1445
ImplicitOps.push_back (MO);
1451
- if (MO.isDef () && MO.getReg ().isVirtual () &&
1452
- MRI->shouldTrackSubRegLiveness (DstReg))
1453
- NewMIImplicitOpsMask |= MRI->getMaxLaneMaskForVReg (MO.getReg ());
1454
1446
}
1455
1447
}
1456
1448
@@ -1493,11 +1485,14 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
1493
1485
} else {
1494
1486
assert (MO.getReg () == NewMI.getOperand (0 ).getReg ());
1495
1487
1496
- // If lanemasks need to be tracked, compile the lanemask of the NewMI
1497
- // implicit def operands to avoid subranges for the super-regs from
1498
- // being removed by code later on in this function.
1499
- if (MRI->shouldTrackSubRegLiveness (MO.getReg ()))
1500
- NewMIImplicitOpsMask |= MRI->getMaxLaneMaskForVReg (MO.getReg ());
1488
+ // We're only expecting another def of the main output, so the range
1489
+ // should get updated with the regular output range.
1490
+ //
1491
+ // FIXME: The range updating below probably needs updating to look at
1492
+ // the super register if subranges are tracked.
1493
+ assert (!MRI->shouldTrackSubRegLiveness (DstReg) &&
1494
+ " subrange update for implicit-def of super register may not be "
1495
+ " properly handled" );
1501
1496
}
1502
1497
}
1503
1498
}
@@ -1521,7 +1516,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
1521
1516
MRI->setRegClass (DstReg, NewRC);
1522
1517
1523
1518
// Update machine operands and add flags.
1524
- updateRegDefsUses (DstReg, DstReg, DstIdx, false );
1519
+ updateRegDefsUses (DstReg, DstReg, DstIdx);
1525
1520
NewMI.getOperand (0 ).setSubReg (NewIdx);
1526
1521
// updateRegDefUses can add an "undef" flag to the definition, since
1527
1522
// it will replace DstReg with DstReg.DstIdx. If NewIdx is 0, make
@@ -1597,8 +1592,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
1597
1592
CurrIdx.getRegSlot (NewMI.getOperand (0 ).isEarlyClobber ());
1598
1593
VNInfo::Allocator &Alloc = LIS->getVNInfoAllocator ();
1599
1594
for (LiveInterval::SubRange &SR : DstInt.subranges ()) {
1600
- if ((SR.LaneMask & DstMask).none () &&
1601
- (SR.LaneMask & NewMIImplicitOpsMask).none ()) {
1595
+ if ((SR.LaneMask & DstMask).none ()) {
1602
1596
LLVM_DEBUG (dbgs ()
1603
1597
<< " Removing undefined SubRange "
1604
1598
<< PrintLaneMask (SR.LaneMask ) << " : " << SR << " \n " );
@@ -1863,7 +1857,7 @@ void RegisterCoalescer::addUndefFlag(const LiveInterval &Int, SlotIndex UseIdx,
1863
1857
}
1864
1858
1865
1859
void RegisterCoalescer::updateRegDefsUses (Register SrcReg, Register DstReg,
1866
- unsigned SubIdx, bool IsSubregToReg ) {
1860
+ unsigned SubIdx) {
1867
1861
bool DstIsPhys = DstReg.isPhysical ();
1868
1862
LiveInterval *DstInt = DstIsPhys ? nullptr : &LIS->getInterval (DstReg);
1869
1863
@@ -1883,14 +1877,6 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
1883
1877
}
1884
1878
}
1885
1879
1886
- // If DstInt already has a subrange for the unused lanes, then we shouldn't
1887
- // create duplicate subranges when we update the interval for unused lanes.
1888
- LaneBitmask DefinedLanes;
1889
- if (DstInt && MRI->shouldTrackSubRegLiveness (DstReg)) {
1890
- for (LiveInterval::SubRange &SR : DstInt->subranges ())
1891
- DefinedLanes |= SR.LaneMask ;
1892
- }
1893
-
1894
1880
SmallPtrSet<MachineInstr*, 8 > Visited;
1895
1881
for (MachineRegisterInfo::reg_instr_iterator
1896
1882
I = MRI->reg_instr_begin (SrcReg), E = MRI->reg_instr_end ();
@@ -1914,19 +1900,15 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
1914
1900
if (DstInt && !Reads && SubIdx && !UseMI->isDebugInstr ())
1915
1901
Reads = DstInt->liveAt (LIS->getInstructionIndex (*UseMI));
1916
1902
1917
- bool FullDef = true ;
1918
-
1919
1903
// Replace SrcReg with DstReg in all UseMI operands.
1920
1904
for (unsigned Op : Ops) {
1921
1905
MachineOperand &MO = UseMI->getOperand (Op);
1922
1906
1923
1907
// Adjust <undef> flags in case of sub-register joins. We don't want to
1924
1908
// turn a full def into a read-modify-write sub-register def and vice
1925
1909
// versa.
1926
- if (SubIdx && MO.isDef ()) {
1910
+ if (SubIdx && MO.isDef ())
1927
1911
MO.setIsUndef (!Reads);
1928
- FullDef = false ;
1929
- }
1930
1912
1931
1913
// A subreg use of a partially undef (super) register may be a complete
1932
1914
// undef use now and then has to be marked that way.
@@ -1959,32 +1941,6 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
1959
1941
MO.substVirtReg (DstReg, SubIdx, *TRI);
1960
1942
}
1961
1943
1962
- if (IsSubregToReg && !FullDef) {
1963
- // If the coalesed instruction doesn't fully define the register, we need
1964
- // to preserve the original super register liveness for SUBREG_TO_REG.
1965
- //
1966
- // We pretended SUBREG_TO_REG was a regular copy for coalescing purposes,
1967
- // but it introduces liveness for other subregisters. Downstream users may
1968
- // have been relying on those bits, so we need to ensure their liveness is
1969
- // captured with a def of other lanes.
1970
-
1971
- if (DstInt && MRI->shouldTrackSubRegLiveness (DstReg)) {
1972
- assert (DstInt->hasSubRanges () &&
1973
- " SUBREG_TO_REG should have resulted in subrange" );
1974
- LaneBitmask DstMask = MRI->getMaxLaneMaskForVReg (DstInt->reg ());
1975
- LaneBitmask UsedLanes = TRI->getSubRegIndexLaneMask (SubIdx);
1976
- LaneBitmask UnusedLanes = DstMask & ~UsedLanes & ~DefinedLanes;
1977
- if ((UnusedLanes).any ()) {
1978
- BumpPtrAllocator &Allocator = LIS->getVNInfoAllocator ();
1979
- DstInt->createSubRangeFrom (Allocator, UnusedLanes, *DstInt);
1980
- DefinedLanes |= UnusedLanes;
1981
- }
1982
- }
1983
-
1984
- MachineInstrBuilder MIB (*MF, UseMI);
1985
- MIB.addReg (DstReg, RegState::ImplicitDefine);
1986
- }
1987
-
1988
1944
LLVM_DEBUG ({
1989
1945
dbgs () << " \t\t updated: " ;
1990
1946
if (!UseMI->isDebugInstr ())
@@ -2186,8 +2142,6 @@ bool RegisterCoalescer::joinCopy(
2186
2142
});
2187
2143
}
2188
2144
2189
- const bool IsSubregToReg = CopyMI->isSubregToReg ();
2190
-
2191
2145
ShrinkMask = LaneBitmask::getNone ();
2192
2146
ShrinkMainRange = false ;
2193
2147
@@ -2257,12 +2211,9 @@ bool RegisterCoalescer::joinCopy(
2257
2211
2258
2212
// Rewrite all SrcReg operands to DstReg.
2259
2213
// Also update DstReg operands to include DstIdx if it is set.
2260
- if (CP.getDstIdx ()) {
2261
- assert (!IsSubregToReg && " can this happen?" );
2262
- updateRegDefsUses (CP.getDstReg (), CP.getDstReg (), CP.getDstIdx (), false );
2263
- }
2264
- updateRegDefsUses (CP.getSrcReg (), CP.getDstReg (), CP.getSrcIdx (),
2265
- IsSubregToReg);
2214
+ if (CP.getDstIdx ())
2215
+ updateRegDefsUses (CP.getDstReg (), CP.getDstReg (), CP.getDstIdx ());
2216
+ updateRegDefsUses (CP.getSrcReg (), CP.getDstReg (), CP.getSrcIdx ());
2266
2217
2267
2218
// Shrink subregister ranges if necessary.
2268
2219
if (ShrinkMask.any ()) {
0 commit comments