Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AMDGPU] Constrain use LiveMask by the operand's LaneMask for RP calculation. #111452

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,33 +259,40 @@ static void
collectVirtualRegUses(SmallVectorImpl<RegisterMaskPair> &RegMaskPairs,
const MachineInstr &MI, const LiveIntervals &LIS,
const MachineRegisterInfo &MRI) {
SlotIndex InstrSI;

auto &TRI = *MRI.getTargetRegisterInfo();
for (const auto &MO : MI.operands()) {
if (!MO.isReg() || !MO.getReg().isVirtual())
continue;
if (!MO.isUse() || !MO.readsReg())
continue;

Register Reg = MO.getReg();
if (llvm::any_of(RegMaskPairs, [Reg](const RegisterMaskPair &RM) {
return RM.RegUnit == Reg;
}))
continue;
auto I = llvm::find_if(RegMaskPairs, [Reg](const RegisterMaskPair &RM) {
return RM.RegUnit == Reg;
});

auto &P = I == RegMaskPairs.end()
? RegMaskPairs.emplace_back(Reg, LaneBitmask::getNone())
: *I;

LaneBitmask UseMask;
auto &LI = LIS.getInterval(Reg);
P.LaneMask |= MO.getSubReg() ? TRI.getSubRegIndexLaneMask(MO.getSubReg())
: MRI.getMaxLaneMaskForVReg(Reg);
jrbyrnes marked this conversation as resolved.
Show resolved Hide resolved
}

SlotIndex InstrSI;
for (auto &P : RegMaskPairs) {
auto &LI = LIS.getInterval(P.RegUnit);
if (!LI.hasSubRanges())
UseMask = MRI.getMaxLaneMaskForVReg(Reg);
else {
// For a tentative schedule LIS isn't updated yet but livemask should
// remain the same on any schedule. Subreg defs can be reordered but they
// all must dominate uses anyway.
if (!InstrSI)
InstrSI = LIS.getInstructionIndex(*MO.getParent()).getBaseIndex();
UseMask = getLiveLaneMask(LI, InstrSI, MRI);
}
continue;

// For a tentative schedule LIS isn't updated yet but livemask should
// remain the same on any schedule. Subreg defs can be reordered but they
// all must dominate uses anyway.
if (!InstrSI)
InstrSI = LIS.getInstructionIndex(MI).getBaseIndex();

RegMaskPairs.emplace_back(Reg, UseMask);
P.LaneMask = getLiveLaneMask(LI, InstrSI, MRI, P.LaneMask);
}
}

Expand All @@ -294,22 +301,25 @@ collectVirtualRegUses(SmallVectorImpl<RegisterMaskPair> &RegMaskPairs,

LaneBitmask llvm::getLiveLaneMask(unsigned Reg, SlotIndex SI,
const LiveIntervals &LIS,
const MachineRegisterInfo &MRI) {
return getLiveLaneMask(LIS.getInterval(Reg), SI, MRI);
const MachineRegisterInfo &MRI,
LaneBitmask MaxLaneMask) {
return getLiveLaneMask(LIS.getInterval(Reg), SI, MRI, MaxLaneMask);
}

LaneBitmask llvm::getLiveLaneMask(const LiveInterval &LI, SlotIndex SI,
const MachineRegisterInfo &MRI) {
const MachineRegisterInfo &MRI,
LaneBitmask MaxLaneMask) {
LaneBitmask LiveMask;
if (LI.hasSubRanges()) {
for (const auto &S : LI.subranges())
if (S.liveAt(SI)) {
if ((S.LaneMask & MaxLaneMask).any() && S.liveAt(SI)) {
LiveMask |= S.LaneMask;
assert(LiveMask == (LiveMask & MRI.getMaxLaneMaskForVReg(LI.reg())));
}
} else if (LI.liveAt(SI)) {
LiveMask = MRI.getMaxLaneMaskForVReg(LI.reg());
}
LiveMask &= MaxLaneMask;
return LiveMask;
}

Expand Down
13 changes: 9 additions & 4 deletions llvm/lib/Target/AMDGPU/GCNRegPressure.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,18 @@ class GCNDownwardRPTracker : public GCNRPTracker {
const LiveRegSet *LiveRegsCopy = nullptr);
};

LaneBitmask getLiveLaneMask(unsigned Reg,
SlotIndex SI,
/// \returns the LaneMask of live lanes of \p Reg at position \p SI. Only the
/// active lanes of \p MaxLaneMask will be set in the return value. This is
jrbyrnes marked this conversation as resolved.
Show resolved Hide resolved
/// used, for example, to limit the live lanes to a specific subreg when
/// calculating use masks.
LaneBitmask getLiveLaneMask(unsigned Reg, SlotIndex SI,
const LiveIntervals &LIS,
const MachineRegisterInfo &MRI);
const MachineRegisterInfo &MRI,
LaneBitmask MaxLaneMask = LaneBitmask::getAll());

LaneBitmask getLiveLaneMask(const LiveInterval &LI, SlotIndex SI,
const MachineRegisterInfo &MRI);
const MachineRegisterInfo &MRI,
LaneBitmask MaxLaneMask = LaneBitmask::getAll());

GCNRPTracker::LiveRegSet getLiveRegs(SlotIndex SI, const LiveIntervals &LIS,
const MachineRegisterInfo &MRI);
Expand Down
Loading