Skip to content

Commit f24aa3b

Browse files
committed
[AMDGPU] Add SGPR class 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 necessary instructions into the BB prolog. Change-Id: Ic747d09771839f7371a44c85b606ea06e972427b
1 parent a565d43 commit f24aa3b

File tree

4 files changed

+70
-69
lines changed

4 files changed

+70
-69
lines changed

llvm/include/llvm/CodeGen/MachineInstr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class MachineInstr
114114
// this instruction.
115115
Unpredictable = 1 << 16, // Instruction with unpredictable condition.
116116
NoConvergent = 1 << 17, // Call does not require convergence guarantees.
117+
LRSplit = 1 << 18 // Live range split instruction.
117118
};
118119

119120
private:

llvm/lib/CodeGen/SplitKit.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ SlotIndex SplitEditor::buildCopy(Register FromReg, Register ToReg,
554554
// The full vreg is copied.
555555
MachineInstr *CopyMI =
556556
BuildMI(MBB, InsertBefore, DebugLoc(), Desc, ToReg).addReg(FromReg);
557+
CopyMI->setFlag(MachineInstr::LRSplit);
557558
return Indexes.insertMachineInstrInMaps(*CopyMI, Late).getRegSlot();
558559
}
559560

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8930,15 +8930,18 @@ bool SIInstrInfo::isBasicBlockPrologue(const MachineInstr &MI,
89308930
// needed by the prolog. However, the insertions for scalar registers can
89318931
// always be placed at the BB top as they are independent of the exec mask
89328932
// value.
8933+
const MachineFunction *MF = MI.getParent()->getParent();
8934+
const MachineRegisterInfo &MRI = MF->getRegInfo();
89338935
bool IsNullOrVectorRegister = true;
8934-
if (Reg) {
8935-
const MachineRegisterInfo &MRI = MI.getParent()->getParent()->getRegInfo();
8936+
if (Reg)
89368937
IsNullOrVectorRegister = !RI.isSGPRClass(RI.getRegClassForReg(MRI, Reg));
8937-
}
89388938

89398939
uint16_t Opcode = MI.getOpcode();
89408940
return IsNullOrVectorRegister &&
89418941
(isSGPRSpill(Opcode) || isWWMRegSpillOpcode(Opcode) ||
8942+
(MI.getFlag(MachineInstr::LRSplit) &&
8943+
RI.isSGPRClass(
8944+
RI.getRegClassForReg(MRI, MI.getOperand(0).getReg()))) ||
89428945
(!MI.isTerminator() && Opcode != AMDGPU::COPY &&
89438946
MI.modifiesRegister(AMDGPU::EXEC, &RI)));
89448947
}

0 commit comments

Comments
 (0)