Skip to content

JIT: Cache start of cold section for reuse in 3-opt layout #111365

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
Jan 15, 2025

Conversation

amanasifkhalid
Copy link
Member

@amanasifkhalid amanasifkhalid commented Jan 13, 2025

During cold code motion, if fgMoveColdBlocks finds a call-finally pair that begins with a cold block, it will try to move the entire pair, regardless of whether the tail is cold or not. If the tail isn't cold, 3-opt layout's detection of the last hot block may terminate early, causing the cold part of an EH region to also be considered for reordering. Because 3-opt expects each EH subregion being reordered to be contiguous, this split causes asserts. Caching the cold region start point in fgMoveColdBlocks means we don't need to find the first cold block in 3-opt, thus removing the potential of getting it wrong.

While I was here, I decided to enhance fgMoveColdBlocks so that it can move cold call-finally pairs at the end of the hot main method body, and clean up 3-opt's initialization logic to reduce its allocation sizes. Fixes #111207.

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jan 13, 2025
@amanasifkhalid
Copy link
Member Author

/azp run runtime-coreclr libraries-pgo

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@amanasifkhalid amanasifkhalid changed the title JIT: Strengthen some 3-opt checks JIT: Cache start of cold section for reuse in 3-opt layout Jan 14, 2025
@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

/azp run runtime-coreclr libraries-pgo, runtime-coreclr libraries-jitstress

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@amanasifkhalid amanasifkhalid marked this pull request as ready for review January 15, 2025 16:19
@amanasifkhalid
Copy link
Member Author

cc @dotnet/jit-contrib, @AndyAyersMS PTAL. Diffs are from fgMoveColdBlocks being able to move the last cold call-finally pair we find in the main method body. Thanks!

@amanasifkhalid amanasifkhalid merged commit 07e4c1b into dotnet:main Jan 15, 2025
114 of 123 checks passed
@amanasifkhalid amanasifkhalid deleted the 3-opt-bounds-checking branch January 15, 2025 17:50
amanasifkhalid added a commit that referenced this pull request Jan 16, 2025
Follow-up to #111365. Instead of allocating a separate ordinal array, track each block's ordinal by overwriting its bbPostorderNum. We can check if a given block is in the candidate set of blocks being reordered if its ordinal is less than the number of hot blocks, and if the block at the given ordinal in blockOrder matches the block in question (i.e. the same implementation as FlowGraphDfsTree::Contains).
@github-actions github-actions bot locked and limited conversation to collaborators Feb 15, 2025
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 '(dstPos >= startPos) && (dstPos <= endPos)' during 'Optimize layout'
2 participants