Skip to content

Commit b760ac7

Browse files
alexmalyshevfacebook-github-bot
authored andcommitted
Ensure LiveInterval allocations are always the same size
Summary: It's really only a problem for stack slots, which are reused and can have different sizes. Reviewed By: DinoV Differential Revision: D82038937 fbshipit-source-id: ea8dacdeeeb1ed07388432d9907544b248dd4fa8
1 parent 6afe66c commit b760ac7

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

cinderx/Jit/lir/regalloc.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ std::unique_ptr<LiveInterval> LiveInterval::splitAt(LIRLocation loc) {
250250
}
251251

252252
void LiveInterval::allocateTo(PhyLocation loc) {
253+
JIT_CHECK(
254+
allocated_loc.bitSize == loc.bitSize,
255+
"Trying to change size of live interval: {} -> {}, with location {} -> "
256+
"{}, for operand {}",
257+
allocated_loc.bitSize,
258+
loc.bitSize,
259+
allocated_loc,
260+
loc,
261+
*operand);
253262
allocated_loc = loc;
254263
}
255264

@@ -969,14 +978,15 @@ PhyLocation LinearScanAllocator::getStackSlot(const Operand* operand) {
969978
PhyLocation LinearScanAllocator::newStackSlot(const Operand* operand) {
970979
PhyLocation slot;
971980
if (free_stack_slots_.empty()) {
972-
max_stack_slot_ -= kPointerSize;
973-
// Intentionally set all new stack slots to be 8-bytes, regardless of the
981+
// Intentionally align all new stack slots to 8-bytes, regardless of the
974982
// operand's size. Uses more stack space but avoids alignment issues.
975-
size_t bit_size = 64;
976-
slot = PhyLocation{max_stack_slot_, bit_size};
983+
max_stack_slot_ -= kPointerSize;
984+
slot = PhyLocation{max_stack_slot_, operand->sizeInBits()};
977985
TRACE("Allocating new stack slot {} for operand {}", slot, *operand);
978986
} else {
979987
slot = free_stack_slots_.back();
988+
// Update slot to the correct size.
989+
slot.bitSize = operand->sizeInBits();
980990
free_stack_slots_.pop_back();
981991
TRACE("Reusing stack slot {} for operand {}", slot, *operand);
982992
}

0 commit comments

Comments
 (0)