Skip to content

Commit

Permalink
[CodeGen] Skip null physical register in AntiDepBreaker (NFCI)
Browse files Browse the repository at this point in the history
D151036 adds an assertions that prohibits iterating over sub- and
super-registers of a null register. This is already the case when
iterating over register units of a null register, and worked by
accident for sub- and super-registers.
The only place where the assertion is currently triggering is in
CriticalAntiDepBreaker::ScanInstruction. Other places are changed
in case new assertions are added and should be harmless otherwise.

Differential Revision: https://reviews.llvm.org/D151288
  • Loading branch information
s-barannikov committed May 24, 2023
1 parent e522fe1 commit d41f6cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp
Expand Up @@ -200,7 +200,7 @@ void AggressiveAntiDepBreaker::Observe(MachineInstr &MI, unsigned Count,
LLVM_DEBUG(dbgs() << "\tRegs:");

std::vector<unsigned> &DefIndices = State->GetDefIndices();
for (unsigned Reg = 0; Reg != TRI->getNumRegs(); ++Reg) {
for (unsigned Reg = 1; Reg != TRI->getNumRegs(); ++Reg) {
// If Reg is current live, then mark that it can't be renamed as
// we don't know the extent of its live-range anymore (now that it
// has been scheduled). If it is not live but was defined in the
Expand Down Expand Up @@ -776,7 +776,7 @@ unsigned AggressiveAntiDepBreaker::BreakAntiDependencies(
#ifndef NDEBUG
LLVM_DEBUG(dbgs() << "\n===== Aggressive anti-dependency breaking\n");
LLVM_DEBUG(dbgs() << "Available regs:");
for (unsigned Reg = 0; Reg < TRI->getNumRegs(); ++Reg) {
for (unsigned Reg = 1; Reg < TRI->getNumRegs(); ++Reg) {
if (!State->IsLive(Reg))
LLVM_DEBUG(dbgs() << " " << printReg(Reg, TRI));
}
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp
Expand Up @@ -49,7 +49,7 @@ CriticalAntiDepBreaker::~CriticalAntiDepBreaker() = default;

void CriticalAntiDepBreaker::StartBlock(MachineBasicBlock *BB) {
const unsigned BBSize = BB->size();
for (unsigned i = 0, e = TRI->getNumRegs(); i != e; ++i) {
for (unsigned i = 1, e = TRI->getNumRegs(); i != e; ++i) {
// Clear out the register class data.
Classes[i] = nullptr;

Expand Down Expand Up @@ -111,7 +111,7 @@ void CriticalAntiDepBreaker::Observe(MachineInstr &MI, unsigned Count,
return;
assert(Count < InsertPosIndex && "Instruction index out of expected range!");

for (unsigned Reg = 0; Reg != TRI->getNumRegs(); ++Reg) {
for (unsigned Reg = 1; Reg != TRI->getNumRegs(); ++Reg) {
if (KillIndices[Reg] != ~0u) {
// If Reg is currently live, then mark that it can't be renamed as
// we don't know the extent of its live-range anymore (now that it
Expand Down Expand Up @@ -265,7 +265,7 @@ void CriticalAntiDepBreaker::ScanInstruction(MachineInstr &MI, unsigned Count) {
[&](MCPhysReg SR) { return MO.clobbersPhysReg(SR); });
};

for (unsigned i = 0, e = TRI->getNumRegs(); i != e; ++i) {
for (unsigned i = 1, e = TRI->getNumRegs(); i != e; ++i) {
if (ClobbersPhysRegAndSubRegs(i)) {
DefIndices[i] = Count;
KillIndices[i] = ~0u;
Expand Down Expand Up @@ -463,7 +463,7 @@ BreakAntiDependencies(const std::vector<SUnit> &SUnits,
LLVM_DEBUG(dbgs() << "Critical path has total latency "
<< (Max->getDepth() + Max->Latency) << "\n");
LLVM_DEBUG(dbgs() << "Available regs:");
for (unsigned Reg = 0; Reg < TRI->getNumRegs(); ++Reg) {
for (unsigned Reg = 1; Reg < TRI->getNumRegs(); ++Reg) {
if (KillIndices[Reg] == ~0u)
LLVM_DEBUG(dbgs() << " " << printReg(Reg, TRI));
}
Expand Down

0 comments on commit d41f6cf

Please sign in to comment.