JIT: fix slow preheader EH bookkeeping in loop cloning#128963
JIT: fix slow preheader EH bookkeeping in loop cloning#128963AndyAyersMS wants to merge 1 commit into
Conversation
When the loop's lex-bottom is in a different EH region than the preheader, `fgFindInsertPoint` returns a different `beforeSlowPreheader` block. The subsequent loop comparing `ebdTryLast`/`ebdHndLast` against `bottom` never matches, so no enclosing region gets extended to cover the slow preheader. `DuplicateWithEH` then resets (rather than extends) the enclosing `tryLast`/`hndLast` and the cloned inner try ends up beyond the outer try's `tryLast`, tripping `fgVerifyHandlerTab`. Compare against `beforeSlowPreheader` instead. `EHClauses(this, ebd)` starting from the preheader's most-nested enclosing region only visits enclosing or disjoint regions; disjoint regions can't have a `Last` equal to `beforeSlowPreheader`, so the simple `==` check is safe. This is mostly latent in production thanks to `optIsLoopClonable` strictness, but I hit it from a loop unswitching prototype. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@jakobbotsch PTAL no diffs expected |
There was a problem hiding this comment.
Pull request overview
This PR adjusts loop cloning’s EH-region extent bookkeeping when inserting the slow-path preheader so that any EH clauses ending at the actual insertion point (beforeSlowPreheader) are extended, preventing inadvertent EH region mis-sizing when the insertion point differs from the loop’s lexical bottom.
Changes:
- Update EH extent updates to key off
beforeSlowPreheader(the actual insertion point) rather thanbottom. - Add clarifying comments explaining why enclosing EH regions may need to be extended before
DuplicateWithEH.
|
Here's what my local AI has to say: The mismatched operand types come from the JIT's implicit-byref struct-argument rewrite. Import starts with the IL for which initially imports as: Later, and global morph rewrites the address node: into: The zero side remains a There is some logic in the stack allocation pass (which also rewrites pointer types) to try and make compensating changes for compares. We could do something like that here, or just bail on this case entirely. |
Fix a bug where loop cloning might improperly extend EH regions. This doesn't seem to be reachable with current cloning but I was running into it with some prototypes that did more general loop unswitching.