Skip to content

Commit

Permalink
JIT: Don't create zero-sized method fragments in emitter::emitSplit (
Browse files Browse the repository at this point in the history
…#107568)

* Fix emitSplit logic

* Remove TODO

* Add more comments
  • Loading branch information
amanasifkhalid authored Sep 20, 2024
1 parent 39a1d44 commit 8756775
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3071,8 +3071,25 @@ void emitter::emitSplit(emitLocation* startLoc,

} // end for loop

splitIfNecessary();
assert(curSize < UW_MAX_FRAGMENT_SIZE_BYTES);
// It's possible to have zero-sized IGs at this point in the emitter.
// For example, the JIT may create an IG to align a loop,
// but then later walk back this decision after other alignment decisions,
// which means it will zero out the new IG.
// If a zero-sized IG precedes a populated IG, it will be included in the latter's fragment.
// However, if the last IG candidate is a zero-sized IG, splitting would create a zero-sized fragment,
// so skip the last split in such cases.
// (The last IG in the main method body can be zero-sized if it was created to align a loop in the first funclet.)
if ((igLastCandidate != nullptr) && (curSize == candidateSize))
{
JITDUMP("emitSplit: can't split at last candidate IG%02u because it would create a zero-sized fragment\n",
igLastCandidate->igNum);
}
else
{
splitIfNecessary();
}

assert((curSize > 0) && (curSize < UW_MAX_FRAGMENT_SIZE_BYTES));
}

/*****************************************************************************
Expand Down

0 comments on commit 8756775

Please sign in to comment.