Skip to content

JIT: stop treating ManagedThreadId helper as constant/pure#130006

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/remove-unnecessary-threadid-constant
Open

JIT: stop treating ManagedThreadId helper as constant/pure#130006
Copilot wants to merge 4 commits into
mainfrom
copilot/remove-unnecessary-threadid-constant

Conversation

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

This PR removes JIT assumptions that can treat CORINFO_HELP_GETCURRENTMANAGEDTHREADID as stable across async suspension, where execution may resume on a different thread.

  • Description

    • Removed CORINFO_HELP_GETCURRENTMANAGEDTHREADID -> VNF_ManagedThreadId from fgValueNumberJitHelperMethodVNFunc in src/coreclr/jit/valuenum.cpp.
    • Removed the now-unused ValueNumFuncDef(ManagedThreadId, 0, false, false) from src/coreclr/jit/valuenumfuncs.h.
    • Kept a narrow fallback in fgValueNumberHelperCall to treat CORINFO_HELP_GETCURRENTMANAGEDTHREADID as non-pure for VN purposes if it survives as a helper call, so it goes through opaque VN handling instead of function-mapped VN.
    • Updated HelperCallProperties::init() in src/coreclr/jit/utils.cpp so CORINFO_HELP_GETCURRENTMANAGEDTHREADID is no longer marked pure, while still marked no-throw.
  • What stays unchanged

    • Helper identity and JIT/EE interface are unchanged (CORINFO_HELP_GETCURRENTMANAGEDTHREADID remains).
    • Inline-candidate conversion path (impConvertToUserCallAndMarkForInlining) is unchanged.
    • The helper remains no-throw.
// Removed from fgValueNumberJitHelperMethodVNFunc:
case CORINFO_HELP_GETCURRENTMANAGEDTHREADID:
    vnf = VNF_ManagedThreadId;
    break;

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @VSadov
See info in area-owners.md if you want to be subscribed.

Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 29, 2026 22:52
Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 29, 2026 23:01
Copilot AI changed the title [WIP] Remove unnecessary constant for managed thread ID helper JIT: remove ManagedThreadId constant VN mapping to avoid cross-await reuse Jun 29, 2026
Copilot AI requested a review from VSadov June 29, 2026 23:02
@VSadov

VSadov commented Jun 30, 2026

Copy link
Copy Markdown
Member

@copilot we should also not mark the helper as "pure" in general, so that it cannot be moved and cross async suspend points. It is still valid to treat it as no-throw.

Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 30, 2026 01:10

Copilot AI commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot we should also not mark the helper as "pure" in general, so that it cannot be moved and cross async suspend points. It is still valid to treat it as no-throw.

Updated in da58ef9: CORINFO_HELP_GETCURRENTMANAGEDTHREADID is no longer marked pure in HelperCallProperties::init(), and it remains marked no-throw (exceptions = ExceptionSetFlags::None).

Copilot AI changed the title JIT: remove ManagedThreadId constant VN mapping to avoid cross-await reuse JIT: stop treating ManagedThreadId helper as constant/pure across async suspension Jun 30, 2026
@VSadov VSadov changed the title JIT: stop treating ManagedThreadId helper as constant/pure across async suspension JIT: stop treating ManagedThreadId helper as constant/pure Jun 30, 2026
@VSadov VSadov marked this pull request as ready for review June 30, 2026 05:21
Copilot AI review requested due to automatic review settings June 30, 2026 05:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This change updates CoreCLR JIT value numbering and helper metadata so CORINFO_HELP_GETCURRENTMANAGEDTHREADID is no longer modeled as a pure / method-constant operation, preventing VN from treating repeated uses as equivalent across the method.

Changes:

  • Removed the VN function (VNF_ManagedThreadId) plumbing for CORINFO_HELP_GETCURRENTMANAGEDTHREADID.
  • Updated helper call properties so CORINFO_HELP_GETCURRENTMANAGEDTHREADID is no longer marked pure (while remaining no-throw).
  • Added a VN-path guard to ensure the helper is treated as non-pure during helper-call VN handling.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/valuenumfuncs.h Removes the VNFunc definition previously used for ManagedThreadId.
src/coreclr/jit/valuenum.cpp Stops mapping the helper to a VNFunc and adjusts helper-call VN handling accordingly.
src/coreclr/jit/utils.cpp Updates helper metadata so GETCURRENTMANAGEDTHREADID is no longer classified as pure.

Comment on lines +15043 to +15046
if (helpFunc == CORINFO_HELP_GETCURRENTMANAGEDTHREADID)
{
pure = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants