Skip to content

Commit 9e50c6e

Browse files
committed
Revert "Reapply "RegisterCoalescer: Add implicit-def of super register when coalescing SUBREG_TO_REG""
This reverts commit ba385ae. Reason: Broke the MSan buildbot. See comments on ba385ae for more information.
1 parent 48f980c commit 9e50c6e

5 files changed

+55
-668
lines changed

llvm/lib/CodeGen/RegisterCoalescer.cpp

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -1796,7 +1793,7 @@ void RegisterCoalescer::addUndefFlag(const LiveInterval &Int, SlotIndex UseIdx,
17961793
}
17971794

17981795
void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
1799-
unsigned SubIdx, bool IsSubregToReg) {
1796+
unsigned SubIdx) {
18001797
bool DstIsPhys = DstReg.isPhysical();
18011798
LiveInterval *DstInt = DstIsPhys ? nullptr : &LIS->getInterval(DstReg);
18021799

@@ -1836,22 +1833,16 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
18361833
if (DstInt && !Reads && SubIdx && !UseMI->isDebugInstr())
18371834
Reads = DstInt->liveAt(LIS->getInstructionIndex(*UseMI));
18381835

1839-
bool FullDef = true;
1840-
18411836
// Replace SrcReg with DstReg in all UseMI operands.
18421837
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
18431838
MachineOperand &MO = UseMI->getOperand(Ops[i]);
18441839

18451840
// Adjust <undef> flags in case of sub-register joins. We don't want to
18461841
// turn a full def into a read-modify-write sub-register def and vice
18471842
// versa.
1848-
if (SubIdx && MO.isDef()) {
1843+
if (SubIdx && MO.isDef())
18491844
MO.setIsUndef(!Reads);
18501845

1851-
if (!Reads)
1852-
FullDef = false;
1853-
}
1854-
18551846
// A subreg use of a partially undef (super) register may be a complete
18561847
// undef use now and then has to be marked that way.
18571848
if (MO.isUse() && !DstIsPhys) {
@@ -1883,25 +1874,6 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
18831874
MO.substVirtReg(DstReg, SubIdx, *TRI);
18841875
}
18851876

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-
19051877
LLVM_DEBUG({
19061878
dbgs() << "\t\tupdated: ";
19071879
if (!UseMI->isDebugInstr())
@@ -2101,8 +2073,6 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
21012073
});
21022074
}
21032075

2104-
const bool IsSubregToReg = CopyMI->isSubregToReg();
2105-
21062076
ShrinkMask = LaneBitmask::getNone();
21072077
ShrinkMainRange = false;
21082078

@@ -2170,12 +2140,9 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
21702140

21712141
// Rewrite all SrcReg operands to DstReg.
21722142
// 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());
21792146

21802147
// Shrink subregister ranges if necessary.
21812148
if (ShrinkMask.any()) {

0 commit comments

Comments
 (0)