Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JIT: Fix placement of loop exit blocks in handler regions #107582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 10, 2024

Conversation

amanasifkhalid
Copy link
Member

@amanasifkhalid amanasifkhalid commented Sep 9, 2024

Fixes #107524. When canonicalizing loops, it's possible for the loop to be in a try region with a finally handler, and for that try region to be nested in a handler region. So if we insert a new exit block into the try region, we need to set the block's handler region, and update the end pointer for the handler region, if applicable.

@amanasifkhalid amanasifkhalid added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Sep 9, 2024
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Sep 9, 2024
@amanasifkhalid
Copy link
Member Author

/azp run runtime-coreclr libraries-pgo

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@amanasifkhalid amanasifkhalid removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Sep 10, 2024
@amanasifkhalid
Copy link
Member Author

/azp run runtime-coreclr libraries-pgo

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@amanasifkhalid amanasifkhalid marked this pull request as ready for review September 10, 2024 13:27
@amanasifkhalid
Copy link
Member Author

@dotnet/jit-contrib PTAL, libraries-pgo isn't hitting the assert anymore. Thanks!

void Compiler::ehUpdateLastHndBlocks(BasicBlock* oldHndLast, BasicBlock* newHndLast)
{
assert(oldHndLast->hasHndIndex() && BasicBlock::sameHndRegion(oldHndLast, newHndLast));
unsigned XTnum = oldHndLast->getHndIndex();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you should also assert that we do at least one update (that is, that oldHndLast is indeed the last block of its enclosing handler region).

// Notes:
// It is the responsibility of the caller to set the new block's handler index,
// if it is being inserted into a handler region, too.
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we not just always do the handler fixup?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have a funclet section, and the try region we're inserting into is in a handler region, then it makes sense to always extend the handler region too. But if we don't have funclets, and we have a try region that contains a handler region ending on the old last try block, do we want to extend the handler region to cover the new last try block? The previous block check at the fgNewBBatTryRegionEnd is meant to fix the former scenario, but I suppose it's also (inadvertently) covering the second scenario too, and it hasn't given us problems yet. I'll try your suggestion and consolidate the new helper into this one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without thinking about it too much, and without enough context... why are all these helpers better than the existing fgNewBBinRegion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fgNewBBinRegion does a lot of extra work to try to insert the new block in the correct region without breaking up any existing fallthrough -- most of this complexity is hidden in fgFindInsertPoint. Ideally, we wouldn't worry about block ordering at all when creating new blocks, and deferring all ordering to block layout wouldn't interfere with intermediate phases. My goal of adding this new helper is to eventually phase fgNewBBinRegion out with it such that all block creation logic is ordering-agnostic, and refactor any phases that prematurely rely on block ordering.

@amanasifkhalid
Copy link
Member Author

/azp run runtime-coreclr libraries-pgo

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@amanasifkhalid
Copy link
Member Author

libraries-pgo failed on arm due to known Tensor test issues, and the x64 leg timed out. Otherwise, this fix seems to work.

@amanasifkhalid amanasifkhalid merged commit d41aadd into dotnet:main Sep 10, 2024
110 of 115 checks passed
@amanasifkhalid amanasifkhalid deleted the fix-loop-canonicalization branch September 10, 2024 22:17
jtschuster pushed a commit to jtschuster/runtime that referenced this pull request Sep 17, 2024
sirntar pushed a commit to sirntar/runtime that referenced this pull request Sep 30, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Oct 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assertion failed 'block->hasHndIndex() == true'
3 participants