Skip to content

Commit 7e501d5

Browse files
committed
Do not allow remat for instructions with dependencies
Change-Id: I69ea68a41b86026e600ac2a4a6b5c351c6753893
1 parent 91c69c5 commit 7e501d5

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,47 @@ void PreRARematStage::collectRematerializableInstructions() {
16911691
if (Def->getParent() == UseI->getParent())
16921692
continue;
16931693

1694+
bool HasRematDependency = false;
1695+
// Check if this instruction uses any registers that are planned to be
1696+
// rematerialized
1697+
for (auto &RematEntry : RematerializableInsts) {
1698+
if (find_if(RematEntry.second,
1699+
[&Def](std::pair<MachineInstr *, MachineInstr *> &Remat) {
1700+
for (MachineOperand &MO : Def->operands()) {
1701+
if (!MO.isReg())
1702+
continue;
1703+
if (MO.getReg() == Remat.first->getOperand(0).getReg())
1704+
return true;
1705+
}
1706+
return false;
1707+
}) != RematEntry.second.end()) {
1708+
HasRematDependency = true;
1709+
break;
1710+
}
1711+
}
1712+
// Do not rematerialize an instruction if it uses an instruction that we
1713+
// have designated for rematerialization.
1714+
// FIXME: Allow for rematerialization chains: this requires 1. updating
1715+
// remat points to account for uses that are rematerialized, and 2. either
1716+
// rematerializing the candidates in careful ordering, or deferring the MBB
1717+
// RP walk until the entire chain has been rematerialized.
1718+
if (HasRematDependency)
1719+
continue;
1720+
1721+
// Similarly, check if the UseI is planned to be remat.
1722+
for (auto &RematEntry : RematerializableInsts) {
1723+
if (find_if(RematEntry.second,
1724+
[&UseI](std::pair<MachineInstr *, MachineInstr *> &Remat) {
1725+
return Remat.first == UseI;
1726+
}) != RematEntry.second.end()) {
1727+
HasRematDependency = true;
1728+
break;
1729+
}
1730+
}
1731+
1732+
if (HasRematDependency)
1733+
break;
1734+
16941735
// We are only collecting defs that are defined in another block and are
16951736
// live-through or used inside regions at MinOccupancy. This means that the
16961737
// register must be in the live-in set for the region.

0 commit comments

Comments
 (0)