Skip to content

Conversation

jakobbotsch
Copy link
Member

Also switch the register used when generating the check if there is a tailcall in the block on x64. This allows us to enable fast tailcalls out of methods with GS cookie checks on x64.

Fix #119949

Also switch the register used when generating the check if there is a
tailcall in the block on x64. This allows us to enable fast tailcalls
out of methods with GS cookie checks on x64.
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Sep 29, 2025
@jakobbotsch
Copy link
Member Author

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

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jakobbotsch jakobbotsch marked this pull request as ready for review October 6, 2025 14:43
@Copilot Copilot AI review requested due to automatic review settings October 6, 2025 14:43
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 enables fast tail calls from methods that require GS (Guard Stack) security cookie checks on x64 by modeling the GS cookie check in LSRA (Linear Scan Register Allocator) and adapting register selection for tail call scenarios. Previously, fast tail calls were disabled for methods with GS cookie checks on x64 due to compatibility requirements.

  • Removes the restriction that prevented fast tail calls from methods with GS cookie checks on x64
  • Models GS cookie checks in LSRA to properly handle register allocation conflicts
  • Introduces dynamic register selection for GS cookie checks based on whether a tail call is present

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/tests/JIT/opt/Tailcall/TailcallVerifyWithPrefix.il Removes test case Condition17 that is no longer needed
src/coreclr/jit/targetriscv64.h Replaces individual register definitions with register mask for GS cookie temps
src/coreclr/jit/targetloongarch64.h Replaces individual register definitions with register mask for GS cookie temps
src/coreclr/jit/targetarm64.h Replaces individual register definitions with register mask for GS cookie temps
src/coreclr/jit/targetarm.h Replaces individual register definitions with register mask for GS cookie temps
src/coreclr/jit/morph.cpp Removes x64-specific restriction preventing fast tail calls with GS cookie checks
src/coreclr/jit/lsraxarch.cpp Adds logic to exclude GS cookie temp registers from control expression candidates for fast tail calls
src/coreclr/jit/lsrariscv64.cpp Updates to use new centralized GS cookie temp register selection
src/coreclr/jit/lsraloongarch64.cpp Updates to use new centralized GS cookie temp register selection
src/coreclr/jit/lsrabuild.cpp Adds LSRA modeling for GS cookie checks by inserting register kills
src/coreclr/jit/lsraarmarch.cpp Updates to use new centralized GS cookie temp register selection
src/coreclr/jit/lower.cpp Removes assertion that prevented GS cookie checks in fast tail calls on x64
src/coreclr/jit/codegenxarch.cpp Simplifies GS cookie check implementation and removes tail call specific logic
src/coreclr/jit/codegenriscv64.cpp Updates GS cookie check to use dynamic register selection
src/coreclr/jit/codegenloongarch64.cpp Updates GS cookie check to use dynamic register selection
src/coreclr/jit/codegeninterface.h Adds declaration for new genGetGSCookieTempRegs method
src/coreclr/jit/codegencommon.cpp Implements centralized logic for GS cookie temp register selection
src/coreclr/jit/codegenarmarch.cpp Updates GS cookie check to use dynamic register selection
src/coreclr/jit/codegen.h Updates genEmitGSCookieCheck method signature to use tailCall parameter

} // end of method Condition17::.cctor

} // end of class TailcallVerify.Condition17

Copy link
Member Author

Choose a reason for hiding this comment

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

This particular test was relying on no tailcall to happen from method with unsafe local in it.

@jakobbotsch
Copy link
Member Author

PTAL @dotnet/jit-contrib

Diffs. Some minor size regressions because the proper encoding of the kill seems to perturb LSRA a little bit, making it pick some other registers with larger encoding. Rarely some improvements when we now tailcall out of some more methods.

@jakobbotsch jakobbotsch requested a review from a team October 6, 2025 14:47
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.

[RuntimeAsync] GS check at returns should be modeled via a register kill in LSRA
1 participant