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

Skip to content

Don't optimize prologues/epilogues in OptimizePostIndexed #114843

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 1 commit into from
Apr 20, 2025

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Apr 20, 2025

Addresses #114630 (comment)

A similar check exists in emitter::IsOptimizableLdrStrWithPair for ldr/str to ldp/stp optimization.

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 20, 2025
@filipnavara
Copy link
Member

filipnavara commented Apr 20, 2025

The conditions to hit this are quite specific but presumably it can affect NativeAOT on win-arm64 (1). That said, to see any issue we'd need to run unwinding exactly at the very first instruction of such optimized funclet epilog (2) and that may be very rare to happen in practice. The only reason it was hit on CoreCLR in the referenced PR was due to GC stress testing that we are missing on AOT (3).

(1) On Unix we use different unwinding format and handle epilogs differently so it's not an issue there.
(2) For any other instruction in the epilog we should not be at GC safepoint, so full stack unwinding should not take place. Hijacking inside epilog is generally forbidden and we'd be past the FP/LR savepoint, so that should naturally fail.
(3) ... and likely also combination of JIT stress testing that forced specific frame type for the prolog. However, this can be reached with regular code too. For the given case we'd just need to use stackalloc in the method. It may also affect epilog of other frame types though, so I am mentioning it only for completeness.

@EgorBo
Copy link
Member Author

EgorBo commented Apr 20, 2025

Looks like there are no diffs (but our coverage of NativeAOT in SPMI is extremely small)

@EgorBo EgorBo marked this pull request as ready for review April 20, 2025 15:46
@Copilot Copilot AI review requested due to automatic review settings April 20, 2025 15:46
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses an issue where post-index optimizations are inadvertently applied during the generation of unwind prologues and epilogues. The changes add a condition to disable such optimizations in emitter::OptimizePostIndexed to ensure consistency with the similar check in emitter::IsOptimizableLdrStrWithPair.

@EgorBo
Copy link
Member Author

EgorBo commented Apr 20, 2025

@filipnavara should it be merged then?

@filipnavara
Copy link
Member

@filipnavara should it be merged then?

Let's wait for the GC stress on the other PR as additional verification.

@am11
Copy link
Member

am11 commented Apr 20, 2025

(1) On Unix we use different unwinding format and handle epilogs differently so it's not an issue there.

Does it mean we can / should exclude it from Unix? 👀

@filipnavara
Copy link
Member

filipnavara commented Apr 20, 2025

Does it mean we can / should exclude it from Unix? 👀

No, it will apply to CoreCLR/Unix once we get the PSPSym PR merged too. We can optimize the prologues/epilogues separately, there will be more stuff to clean up.

Copy link
Member

@filipnavara filipnavara left a comment

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

4 participants