Skip to content

Commit

Permalink
Revert "[AMDGPU] RA inserted scalar instructions can be at the BB top (
Browse files Browse the repository at this point in the history
…llvm#72140)"

This reverts commit ce7fd49.

Change-Id: Iafb1f24fad78c477d3168a69cd8f9ccde6bc5038
  • Loading branch information
alex-t authored and kzhuravl committed Jul 29, 2024
1 parent 53c4610 commit 675ba5e
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 32 deletions.
6 changes: 2 additions & 4 deletions llvm/include/llvm/CodeGen/MachineBasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,8 @@ class MachineBasicBlock

/// Return the first instruction in MBB after I that is not a PHI, label or
/// debug. This is the correct point to insert copies at the beginning of a
/// basic block. \p Reg is the register being used by a spill or defined for a
/// restore/split during register allocation.
iterator SkipPHIsLabelsAndDebug(iterator I, Register Reg = Register(),
bool SkipPseudoOp = true);
/// basic block.
iterator SkipPHIsLabelsAndDebug(iterator I, bool SkipPseudoOp = true);

/// Returns an iterator to the first terminator instruction of this basic
/// block. If a terminator does not exist, it returns end().
Expand Down
6 changes: 2 additions & 4 deletions llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2013,10 +2013,8 @@ class TargetInstrInfo : public MCInstrInfo {

/// True if the instruction is bound to the top of its basic block and no
/// other instructions shall be inserted before it. This can be implemented
/// to prevent register allocator to insert spills for \p Reg before such
/// instructions.
virtual bool isBasicBlockPrologue(const MachineInstr &MI,
Register Reg = Register()) const {
/// to prevent register allocator to insert spills before such instructions.
virtual bool isBasicBlockPrologue(const MachineInstr &MI) const {
return false;
}

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,7 @@ class StatepointState {

if (EHPad && !RC.hasReload(Reg, RegToSlotIdx[Reg], EHPad)) {
RC.recordReload(Reg, RegToSlotIdx[Reg], EHPad);
auto EHPadInsertPoint =
EHPad->SkipPHIsLabelsAndDebug(EHPad->begin(), Reg);
auto EHPadInsertPoint = EHPad->SkipPHIsLabelsAndDebug(EHPad->begin());
insertReloadBefore(Reg, EHPadInsertPoint, EHPad);
LLVM_DEBUG(dbgs() << "...also reload at EHPad "
<< printMBBReference(*EHPad) << "\n");
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/InlineSpiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ bool InlineSpiller::hoistSpillInsideBB(LiveInterval &SpillLI,
MachineBasicBlock *MBB = LIS.getMBBFromIndex(SrcVNI->def);
MachineBasicBlock::iterator MII;
if (SrcVNI->isPHIDef())
MII = MBB->SkipPHIsLabelsAndDebug(MBB->begin(), SrcReg);
MII = MBB->SkipPHIsLabelsAndDebug(MBB->begin());
else {
MachineInstr *DefMI = LIS.getInstructionFromIndex(SrcVNI->def);
assert(DefMI && "Defining instruction disappeared");
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/MachineBasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ MachineBasicBlock::SkipPHIsAndLabels(MachineBasicBlock::iterator I) {

MachineBasicBlock::iterator
MachineBasicBlock::SkipPHIsLabelsAndDebug(MachineBasicBlock::iterator I,
Register Reg, bool SkipPseudoOp) {
bool SkipPseudoOp) {
const TargetInstrInfo *TII = getParent()->getSubtarget().getInstrInfo();

iterator E = end();
while (I != E && (I->isPHI() || I->isPosition() || I->isDebugInstr() ||
(SkipPseudoOp && I->isPseudoProbe()) ||
TII->isBasicBlockPrologue(*I, Reg)))
TII->isBasicBlockPrologue(*I)))
++I;
// FIXME: This needs to change if we wish to bundle labels / dbg_values
// inside the bundle.
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/CodeGen/SplitKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,10 +807,8 @@ SlotIndex SplitEditor::leaveIntvAtTop(MachineBasicBlock &MBB) {
return Start;
}

unsigned RegIdx = 0;
Register Reg = LIS.getInterval(Edit->get(RegIdx)).reg();
VNInfo *VNI = defFromParent(RegIdx, ParentVNI, Start, MBB,
MBB.SkipPHIsLabelsAndDebug(MBB.begin(), Reg));
VNInfo *VNI = defFromParent(0, ParentVNI, Start, MBB,
MBB.SkipPHIsLabelsAndDebug(MBB.begin()));
RegAssign.insert(Start, VNI->def, OpenIdx);
LLVM_DEBUG(dump());
return VNI->def;
Expand Down
17 changes: 4 additions & 13 deletions llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8918,25 +8918,16 @@ unsigned SIInstrInfo::getLiveRangeSplitOpcode(Register SrcReg,
return AMDGPU::COPY;
}

bool SIInstrInfo::isBasicBlockPrologue(const MachineInstr &MI,
Register Reg) const {
bool SIInstrInfo::isBasicBlockPrologue(const MachineInstr &MI) const {
// We need to handle instructions which may be inserted during register
// allocation to handle the prolog. The initial prolog instruction may have
// been separated from the start of the block by spills and copies inserted
// needed by the prolog. However, the insertions for scalar registers can
// always be placed at the BB top as they are independent of the exec mask
// value.
bool IsNullOrVectorRegister = true;
if (Reg) {
const MachineRegisterInfo &MRI = MI.getParent()->getParent()->getRegInfo();
IsNullOrVectorRegister = !RI.isSGPRClass(RI.getRegClassForReg(MRI, Reg));
}

// needed by the prolog.
uint16_t Opc = MI.getOpcode();

// FIXME: Copies inserted in the block prolog for live-range split should also
// be included.
return IsNullOrVectorRegister &&
(isSpillOpcode(Opc) || (!MI.isTerminator() && Opc != AMDGPU::COPY &&
return (isSpillOpcode(Opc) || (!MI.isTerminator() && Opc != AMDGPU::COPY &&
MI.modifiesRegister(AMDGPU::EXEC, &RI)));
}

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/AMDGPU/SIInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1283,8 +1283,7 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
unsigned getLiveRangeSplitOpcode(Register Reg,
const MachineFunction &MF) const override;

bool isBasicBlockPrologue(const MachineInstr &MI,
Register Reg = Register()) const override;
bool isBasicBlockPrologue(const MachineInstr &MI) const override;

MachineInstr *createPHIDestinationCopy(MachineBasicBlock &MBB,
MachineBasicBlock::iterator InsPt,
Expand Down

0 comments on commit 675ba5e

Please sign in to comment.