Skip to content

Commit

Permalink
[mlgo][regalloc] Fix register masking
Browse files Browse the repository at this point in the history
If AllocationOrder has less than 32 elements, we were treating the extra
positions as if they were valid. This was detected by a subsequent
assert. The fix also tightens the asserts.
  • Loading branch information
mtrofin committed Jan 30, 2022
1 parent dc3b936 commit a8a7bf9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
Expand Up @@ -615,23 +615,23 @@ MCRegister MLEvictAdvisor::tryFindEvictionCandidate(
for (auto I = Order.begin(), E = Order.getOrderLimitEnd(OrderLimit); I != E;
++I, ++Pos) {
MCRegister PhysReg = *I;
Regs[Pos] = std::make_pair(PhysReg, true);
assert(!Regs[Pos].second);
assert(PhysReg);
if (!canAllocatePhysReg(CostPerUseLimit, PhysReg)) {
Regs[Pos].second = false;
continue;
}
if (loadInterferenceFeatures(VirtReg, PhysReg, I.isHint(), FixedRegisters,
Largest, Pos)) {
++Available;
Regs[Pos].second = true;
Regs[Pos] = std::make_pair(PhysReg, true);
}
}
if (Available == 0) {
// Nothing to decide, nothing to learn.
assert(!MustFindEviction);
return MCRegister::NoRegister;
}
const size_t ValidPosLimit = Pos;
// If we must find eviction, the candidate should be masked out of the
// decision making process.
Regs[CandidateVirtRegPos].second = !MustFindEviction;
Expand Down Expand Up @@ -665,6 +665,7 @@ MCRegister MLEvictAdvisor::tryFindEvictionCandidate(
assert(!MustFindEviction);
return MCRegister::NoRegister;
}
assert(CandidatePos < ValidPosLimit);
return Regs[CandidatePos].first;
}

Expand Down

0 comments on commit a8a7bf9

Please sign in to comment.