[llvm] [AMDGPU] Optionally Use GCNRPTrackers during scheduling (PR #93090)
Jeffrey Byrnes via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 24 13:06:48 PDT 2024
================
@@ -414,6 +534,49 @@ void GCNUpwardRPTracker::recede(const MachineInstr &MI) {
assert(CurPressure == getRegPressure(*MRI, LiveRegs));
}
+void GCNUpwardRPTracker::bumpUpwardPressure(const MachineInstr *MI,
+ const SIRegisterInfo *TRI) {
+ assert(!MI->isDebugOrPseudoInstr() && "Expect a nondebug instruction.");
+
+ SlotIndex SlotIdx = LIS.getInstructionIndex(*MI).getRegSlot();
+
+ // Account for register pressure similar to RegPressureTracker::recede().
+ RegisterOperands RegOpers;
+
+ RegOpers.collect(*MI, *TRI, *MRI, true, /*IgnoreDead=*/true);
+ assert(RegOpers.DeadDefs.empty());
+ adjustDefLaneLiveness(RegOpers.Defs, SlotIdx, LIS, *MRI);
+ RegOpers.detectDeadDefs(*MI, LIS);
+
+ // Boost max pressure for all dead defs together.
+ // Since CurrSetPressure and MaxSetPressure
+ bumpDeadDefs(RegOpers.DeadDefs);
+
+ // Kill liveness at live defs.
+ for (const RegisterMaskPair &P : RegOpers.Defs) {
+ Register Reg = P.RegUnit;
+ if (!Reg.isVirtual())
+ continue;
+ LaneBitmask LiveAfter = LiveRegs[Reg];
+ LaneBitmask UseLanes = getRegLanes(RegOpers.Uses, Reg);
+ LaneBitmask DefLanes = P.LaneMask;
+ LaneBitmask LiveBefore = (LiveAfter & ~DefLanes) | UseLanes;
+
+ CurPressure.inc(Reg, LiveAfter, LiveAfter & LiveBefore, *MRI);
+ MaxPressure = max(MaxPressure, CurPressure);
----------------
jrbyrnes wrote:
We do decrease pressure for defs (inc with PrevMask >= NewMask lowers to a decrease), but I've deleted the increase pressure for defs.
```
// Kill liveness at live defs.
for (const RegisterMaskPair &P : RegOpers.Defs) {
Register Reg = P.RegUnit;
LaneBitmask LiveAfter = LiveRegs.contains(Reg);
LaneBitmask UseLanes = getRegLanes(RegOpers.Uses, Reg);
LaneBitmask DefLanes = P.LaneMask;
LaneBitmask LiveBefore = (LiveAfter & ~DefLanes) | UseLanes;
// There may be parts of the register that were dead before the
// instruction, but became live afterwards. Similarly, some parts
// may have been killed in this instruction.
decreaseRegPressure(Reg, LiveAfter, LiveAfter & LiveBefore);
increaseRegPressure(Reg, LiveAfter, ~LiveAfter & LiveBefore);
}
// Generate liveness for uses.
for (const RegisterMaskPair &P : RegOpers.Uses) {
Register Reg = P.RegUnit;
// If this register was also in a def operand, we've handled it
// with defs.
if (getRegLanes(RegOpers.Defs, Reg).any())
continue;
LaneBitmask LiveAfter = LiveRegs.contains(Reg);
LaneBitmask LiveBefore = LiveAfter | P.LaneMask;
increaseRegPressure(Reg, LiveAfter, LiveBefore);
}
}
```
The "missing" line is `increaseRegPressure(Reg, LiveAfter, ~LiveAfter & LiveBefore);` . This line exists in generic trackers to handle those registers which appear in both uses and defs of an instruction. The generic tracker then skips over these registers when considering the uses in the subsequent loop.
In the "missing" `increaseRegPressure`, the lane masks seem incompatible. The `NewMask` ( `~LiveAfter & LiveBefore` ) has no overlap with `LiveAfter`. For this reason alone, we can't 1:1 port it to our tracker. Additionally, this only works in the generic tracker because the `increaseRegPressure` exits if `NewMask` (which reduces to `~LiveAfter & UseLanes`) has no active lanes (which is often the case). We can't add this exit to our `inc` method as the `NewMask` can have no active lanes -- a common use case when we close out a range and want to decrement the pressure.
We could add this check to `bumpUpwardPressure` and/or fix the masks, but, to me, this "missing" line is a pretty confusing way to increase the RP for any new use lanes introduced by the instruction. In this PR, I've just handled these regs in the use loop.
https://github.com/llvm/llvm-project/pull/93090
More information about the llvm-commits
mailing list