Skip to content

Commit 80232b5

Browse files
committed
[AMDGPU] Add liverange split instructions into BB Prolog
The COPY inserted for liverange split during sgpr-regalloc pipeline currently breaks the BB prolog during the subsequent vgpr-regalloc phase while spilling and/or splitting the vector liveranges. This patch fixes it by correctly including the the LR split instructions during sgpr-regalloc and wwm-regalloc pipelines into the BB prolog.
1 parent a9587c1 commit 80232b5

File tree

4 files changed

+707
-665
lines changed

4 files changed

+707
-665
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9709,6 +9709,30 @@ unsigned SIInstrInfo::getLiveRangeSplitOpcode(Register SrcReg,
97099709
return AMDGPU::COPY;
97109710
}
97119711

9712+
bool SIInstrInfo::canAddToBBProlog(const MachineInstr &MI) const {
9713+
uint16_t Opcode = MI.getOpcode();
9714+
// Check if it is SGPR spill or wwm-register spill Opcode.
9715+
if (isSGPRSpill(Opcode) || isWWMRegSpillOpcode(Opcode))
9716+
return true;
9717+
9718+
const MachineFunction *MF = MI.getMF();
9719+
const MachineRegisterInfo &MRI = MF->getRegInfo();
9720+
const SIMachineFunctionInfo *MFI = MF->getInfo<SIMachineFunctionInfo>();
9721+
9722+
// See if this is Liverange split instruction inserted for SGPR or
9723+
// wwm-register. The implicit def inserted for wwm-registers should also be
9724+
// included as they can appear at the bb begin.
9725+
bool IsLRSplitInst = MI.getFlag(MachineInstr::LRSplit);
9726+
if (!IsLRSplitInst && Opcode != AMDGPU::IMPLICIT_DEF)
9727+
return false;
9728+
9729+
Register Reg = MI.getOperand(0).getReg();
9730+
if (RI.isSGPRClass(RI.getRegClassForReg(MRI, Reg)))
9731+
return IsLRSplitInst;
9732+
9733+
return MFI->isWWMReg(Reg);
9734+
}
9735+
97129736
bool SIInstrInfo::isBasicBlockPrologue(const MachineInstr &MI,
97139737
Register Reg) const {
97149738
// We need to handle instructions which may be inserted during register
@@ -9717,20 +9741,16 @@ bool SIInstrInfo::isBasicBlockPrologue(const MachineInstr &MI,
97179741
// needed by the prolog. However, the insertions for scalar registers can
97189742
// always be placed at the BB top as they are independent of the exec mask
97199743
// value.
9720-
const MachineFunction *MF = MI.getParent()->getParent();
97219744
bool IsNullOrVectorRegister = true;
97229745
if (Reg) {
9746+
const MachineFunction *MF = MI.getMF();
97239747
const MachineRegisterInfo &MRI = MF->getRegInfo();
97249748
IsNullOrVectorRegister = !RI.isSGPRClass(RI.getRegClassForReg(MRI, Reg));
97259749
}
97269750

9727-
uint16_t Opcode = MI.getOpcode();
9728-
const SIMachineFunctionInfo *MFI = MF->getInfo<SIMachineFunctionInfo>();
97299751
return IsNullOrVectorRegister &&
9730-
(isSGPRSpill(Opcode) || isWWMRegSpillOpcode(Opcode) ||
9731-
(Opcode == AMDGPU::IMPLICIT_DEF &&
9732-
MFI->isWWMReg(MI.getOperand(0).getReg())) ||
9733-
(!MI.isTerminator() && Opcode != AMDGPU::COPY &&
9752+
(canAddToBBProlog(MI) ||
9753+
(!MI.isTerminator() && MI.getOpcode() != AMDGPU::COPY &&
97349754
MI.modifiesRegister(AMDGPU::EXEC, &RI)));
97359755
}
97369756

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,8 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
15611561
bool isBasicBlockPrologue(const MachineInstr &MI,
15621562
Register Reg = Register()) const override;
15631563

1564+
bool canAddToBBProlog(const MachineInstr &MI) const;
1565+
15641566
MachineInstr *createPHIDestinationCopy(MachineBasicBlock &MBB,
15651567
MachineBasicBlock::iterator InsPt,
15661568
const DebugLoc &DL, Register Src,

0 commit comments

Comments
 (0)