Skip to content

JIT: Make all static base helpers byref typed in async functions#130317

Draft
jakobbotsch wants to merge 3 commits into
dotnet:mainfrom
jakobbotsch:fix-130212
Draft

JIT: Make all static base helpers byref typed in async functions#130317
jakobbotsch wants to merge 3 commits into
dotnet:mainfrom
jakobbotsch:fix-130212

Conversation

@jakobbotsch

Copy link
Copy Markdown
Member

There were a handful of static base helpers that we treated as returning
TYP_I_IMPL. At the same time VN considers these helpers to be
invariant, allowing them to be CSE'd. However, these helpers are not
invariant in async functions.

Initially I explicitly marked VNs referring to these helpers as killed
across async suspensions in CSE (see first commits on this PR). However,
figuring out which VNs refer to those helpers is actually non-trivial
when you take VNPhiDef and other functions into account. Instead this PR
just changes the type of these helpers to let the standard byref
handling pick them up.

A more ideal solution would be some kind of thread-SSA that worked like
memory SSA and were passed as an input to these VNs. But that's much
more complicated.

This reverts commit 5867608.
There were a handful of static base helpers that we treated as returning
`TYP_I_IMPL`. At the same time VN considers these helpers to be
invariant, allowing them to be CSE'd. However, these helpers are not
invariant in async functions.

Initially I explicitly marked VNs referring to these helpers as killed
across async suspensions in CSE (see first commits on this PR). However,
figuring out which VNs refer to those helpers is actually non-trivial
when you take VNPhiDef and other functions into account. Instead this PR
just changes the type of these helpers to let the standard byref
handling pick them up.
Copilot AI review requested due to automatic review settings July 7, 2026 19:28
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

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 PR changes how the JIT types certain “static base” helper calls when compiling async state-machine methods, so that the existing byref-based handling in later phases naturally prevents incorrect CSE/availability across async suspension points.

Changes:

  • In fgGetStaticsCCtorHelper, return TYP_BYREF (instead of TYP_I_IMPL) for pinned static-base helpers when compIsAsync() is true.
  • Add an explanatory comment for the async-specific typing choice.

Comment on lines +761 to +765
// In async calls we model these helpers as byrefs to get "killed
// across suspensions" behavior for free, while also properly
// ensuring derived addresses are byref typed and are treated
// similarly.
type = compIsAsync() ? TYP_BYREF : TYP_I_IMPL;
@jkotas jkotas added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI runtime-async and removed area-VM-coreclr labels Jul 8, 2026
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 runtime-async

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants