Skip to content

Commit c398fa0

Browse files
Revert "Reapply "RegisterCoalescer: Add implicit-def of super register when coalescing SUBREG_TO_REG""
This reverts commit f4b5be1. The above change was breaking the clang-ppc64le-linux-test-suite bot.
1 parent e564d24 commit c398fa0

6 files changed

+57
-670
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.
@@ -1347,7 +1343,8 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
13471343
if (DstReg.isPhysical()) {
13481344
Register NewDstReg = DstReg;
13491345

1350-
unsigned NewDstIdx = TRI->composeSubRegIndices(CP.getSrcIdx(), DefSubIdx);
1346+
unsigned NewDstIdx = TRI->composeSubRegIndices(CP.getSrcIdx(),
1347+
DefMI->getOperand(0).getSubReg());
13511348
if (NewDstIdx)
13521349
NewDstReg = TRI->getSubReg(DstReg, NewDstIdx);
13531350

@@ -1496,7 +1493,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
14961493
MRI->setRegClass(DstReg, NewRC);
14971494

14981495
// Update machine operands and add flags.
1499-
updateRegDefsUses(DstReg, DstReg, DstIdx, false);
1496+
updateRegDefsUses(DstReg, DstReg, DstIdx);
15001497
NewMI.getOperand(0).setSubReg(NewIdx);
15011498
// updateRegDefUses can add an "undef" flag to the definition, since
15021499
// it will replace DstReg with DstReg.DstIdx. If NewIdx is 0, make
@@ -1817,7 +1814,7 @@ void RegisterCoalescer::addUndefFlag(const LiveInterval &Int, SlotIndex UseIdx,
18171814
}
18181815

18191816
void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
1820-
unsigned SubIdx, bool IsSubregToReg) {
1817+
unsigned SubIdx) {
18211818
bool DstIsPhys = DstReg.isPhysical();
18221819
LiveInterval *DstInt = DstIsPhys ? nullptr : &LIS->getInterval(DstReg);
18231820

@@ -1857,22 +1854,16 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
18571854
if (DstInt && !Reads && SubIdx && !UseMI->isDebugInstr())
18581855
Reads = DstInt->liveAt(LIS->getInstructionIndex(*UseMI));
18591856

1860-
bool FullDef = true;
1861-
18621857
// Replace SrcReg with DstReg in all UseMI operands.
18631858
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
18641859
MachineOperand &MO = UseMI->getOperand(Ops[i]);
18651860

18661861
// Adjust <undef> flags in case of sub-register joins. We don't want to
18671862
// turn a full def into a read-modify-write sub-register def and vice
18681863
// versa.
1869-
if (SubIdx && MO.isDef()) {
1864+
if (SubIdx && MO.isDef())
18701865
MO.setIsUndef(!Reads);
18711866

1872-
if (!Reads)
1873-
FullDef = false;
1874-
}
1875-
18761867
// A subreg use of a partially undef (super) register may be a complete
18771868
// undef use now and then has to be marked that way.
18781869
if (MO.isUse() && !DstIsPhys) {
@@ -1904,25 +1895,6 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
19041895
MO.substVirtReg(DstReg, SubIdx, *TRI);
19051896
}
19061897

1907-
if (IsSubregToReg && !FullDef) {
1908-
// If the coalesed instruction doesn't fully define the register, we need
1909-
// to preserve the original super register liveness for SUBREG_TO_REG.
1910-
//
1911-
// We pretended SUBREG_TO_REG was a regular copy for coalescing purposes,
1912-
// but it introduces liveness for other subregisters. Downstream users may
1913-
// have been relying on those bits, so we need to ensure their liveness is
1914-
// captured with a def of other lanes.
1915-
1916-
// FIXME: Need to add new subrange if tracking subranges. We could also
1917-
// skip adding this if we knew the other lanes are dead, and only for
1918-
// other lanes.
1919-
1920-
assert(!MRI->shouldTrackSubRegLiveness(DstReg) &&
1921-
"this should update subranges");
1922-
MachineInstrBuilder MIB(*MF, UseMI);
1923-
MIB.addReg(DstReg, RegState::ImplicitDefine);
1924-
}
1925-
19261898
LLVM_DEBUG({
19271899
dbgs() << "\t\tupdated: ";
19281900
if (!UseMI->isDebugInstr())
@@ -2122,8 +2094,6 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
21222094
});
21232095
}
21242096

2125-
const bool IsSubregToReg = CopyMI->isSubregToReg();
2126-
21272097
ShrinkMask = LaneBitmask::getNone();
21282098
ShrinkMainRange = false;
21292099

@@ -2191,12 +2161,9 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
21912161

21922162
// Rewrite all SrcReg operands to DstReg.
21932163
// Also update DstReg operands to include DstIdx if it is set.
2194-
if (CP.getDstIdx()) {
2195-
assert(!IsSubregToReg && "can this happen?");
2196-
updateRegDefsUses(CP.getDstReg(), CP.getDstReg(), CP.getDstIdx(), false);
2197-
}
2198-
updateRegDefsUses(CP.getSrcReg(), CP.getDstReg(), CP.getSrcIdx(),
2199-
IsSubregToReg);
2164+
if (CP.getDstIdx())
2165+
updateRegDefsUses(CP.getDstReg(), CP.getDstReg(), CP.getDstIdx());
2166+
updateRegDefsUses(CP.getSrcReg(), CP.getDstReg(), CP.getSrcIdx());
22002167

22012168
// Shrink subregister ranges if necessary.
22022169
if (ShrinkMask.any()) {

0 commit comments

Comments
 (0)