Skip to content

Commit 4874306

Browse files
committed
Use getMBBEndIdx(MBB).getPrevSlot() as getMBBLastIdx result.
1 parent d27a6de commit 4874306

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

llvm/include/llvm/CodeGen/SlotIndexes.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,11 @@ class raw_ostream;
481481
/// This index corresponds to the dead slot of the last non-debug
482482
/// instruction and can be used to find live-out ranges of the block. Note
483483
/// that getMBBEndIdx returns the start index of the next block, which is
484-
/// also used as the start index for segments with phi-def values. Returns
485-
/// an invalid SlotIndex if the block has no non-debug instructions.
484+
/// also used as the start index for segments with phi-def values. If the
485+
/// basic block doesn't contain any non-debug instructions, this returns
486+
/// the same as getMBBStartIdx.getDeadSlot().
486487
SlotIndex getMBBLastIdx(const MachineBasicBlock *MBB) const {
487-
auto LastInstrI = MBB->getLastNonDebugInstr();
488-
return LastInstrI == MBB->end()
489-
? SlotIndex()
490-
: getInstructionIndex(*LastInstrI).getDeadSlot();
488+
return getMBBEndIdx(MBB).getPrevSlot();
491489
}
492490

493491
/// Iterator over the idx2MBBMap (sorted pairs of slot index of basic block

llvm/lib/Target/AMDGPU/GCNRegPressure.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,13 +907,13 @@ bool GCNRegPressurePrinter::runOnMachineFunction(MachineFunction &MF) {
907907
OS << ":\n";
908908

909909
SlotIndex MBBStartSlot = LIS.getSlotIndexes()->getMBBStartIdx(&MBB);
910-
SlotIndex MBBEndSlot = LIS.getSlotIndexes()->getMBBEndIdx(&MBB);
911910
SlotIndex MBBLastSlot = LIS.getSlotIndexes()->getMBBLastIdx(&MBB);
911+
bool MBBHasNonDebugInstrs = MBBStartSlot != MBBLastSlot.getBaseIndex();
912912

913913
GCNRPTracker::LiveRegSet LiveIn, LiveOut;
914914
GCNRegPressure RPAtMBBEnd;
915915

916-
if (!MBBLastSlot.isValid()) { // MBB doesn't have any non-debug instrs.
916+
if (!MBBHasNonDebugInstrs) {
917917
LiveIn = LiveOut = getLiveRegs(MBBStartSlot, LIS, MRI);
918918
RPAtMBBEnd = getRegPressure(MRI, LiveIn);
919919
} else if (UseDownwardTracker) {
@@ -966,13 +966,14 @@ bool GCNRegPressurePrinter::runOnMachineFunction(MachineFunction &MF) {
966966
OS << printRP(RPAtMBBEnd) << '\n';
967967

968968
OS << PFX " Live-out:" << llvm::print(LiveOut, MRI);
969-
if (UseDownwardTracker && MBBLastSlot.isValid())
969+
if (UseDownwardTracker)
970970
ReportLISMismatchIfAny(LiveOut, getLiveRegs(MBBLastSlot, LIS, MRI));
971971

972972
GCNRPTracker::LiveRegSet LiveThrough;
973973
for (auto [Reg, Mask] : LiveIn) {
974974
LaneBitmask MaskIntersection = Mask & LiveOut.lookup(Reg);
975975
if (MaskIntersection.any()) {
976+
SlotIndex MBBEndSlot = LIS.getSlotIndexes()->getMBBEndIdx(&MBB);
976977
LaneBitmask LTMask = getRegLiveThroughMask(
977978
MRI, LIS, Reg, MBBStartSlot, MBBEndSlot, MaskIntersection);
978979
if (LTMask.any())

0 commit comments

Comments
 (0)