Skip to content

Commit 5d9acc6

Browse files
committed
Handle deleted instructions at segment end
1 parent 9d7952f commit 5d9acc6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

llvm/lib/Target/AMDGPU/AMDGPUMarkLastScratchLoad.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "AMDGPU.h"
1717
#include "GCNSubtarget.h"
1818
#include "llvm/CodeGen/LiveStacks.h"
19+
#include "llvm/CodeGen/LiveIntervals.h"
1920
#include "llvm/CodeGen/MachineOperand.h"
2021

2122
using namespace llvm;
@@ -27,6 +28,7 @@ namespace {
2728
class AMDGPUMarkLastScratchLoad : public MachineFunctionPass {
2829
private:
2930
LiveStacks *LS = nullptr;
31+
LiveIntervals *LIS = nullptr;
3032
SlotIndexes *SI = nullptr;
3133
const SIInstrInfo *SII = nullptr;
3234

@@ -41,6 +43,7 @@ class AMDGPUMarkLastScratchLoad : public MachineFunctionPass {
4143

4244
void getAnalysisUsage(AnalysisUsage &AU) const override {
4345
AU.addRequired<SlotIndexes>();
46+
AU.addRequired<LiveIntervals>();
4447
AU.addRequired<LiveStacks>();
4548
AU.setPreservesAll();
4649
MachineFunctionPass::getAnalysisUsage(AU);
@@ -62,8 +65,10 @@ bool AMDGPUMarkLastScratchLoad::runOnMachineFunction(MachineFunction &MF) {
6265
return false;
6366

6467
LS = &getAnalysis<LiveStacks>();
68+
LIS = &getAnalysis<LiveIntervals>();
6569
SI = &getAnalysis<SlotIndexes>();
6670
SII = ST.getInstrInfo();
71+
SlotIndexes &Slots = *LIS->getSlotIndexes();
6772

6873
const unsigned NumSlots = LS->getNumIntervals();
6974
if (NumSlots == 0) {
@@ -87,12 +92,14 @@ bool AMDGPUMarkLastScratchLoad::runOnMachineFunction(MachineFunction &MF) {
8792
MachineInstr *LastLoad = nullptr;
8893

8994
MachineInstr *MISegmentEnd = SI->getInstructionFromIndex(Segment.end);
95+
96+
// If there is no instruction at this slot because it was deleted take the
97+
// instruction from the next slot.
9098
if (!MISegmentEnd) {
91-
// FIXME: The start and end can refer to deleted instructions. We should
92-
// be able to handle this more gracefully by finding the closest real
93-
// instructions.
94-
continue;
99+
SlotIndex NextSlot = Slots.getNextNonNullIndex(Segment.end);
100+
MISegmentEnd = SI->getInstructionFromIndex(NextSlot);
95101
}
102+
96103
MachineInstr *MISegmentStart = SI->getInstructionFromIndex(Segment.start);
97104
MachineBasicBlock *BB = MISegmentEnd->getParent();
98105

0 commit comments

Comments
 (0)