Skip to content

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

Merged
JulieLeeMSFT merged 3 commits into
dotnet:mainfrom
jakobbotsch:fix-130212
Jul 8, 2026
Merged

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

Conversation

@jakobbotsch

@jakobbotsch jakobbotsch commented Jul 7, 2026

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.

Fix #130212

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 thread src/coreclr/jit/flowgraph.cpp
@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
@jakobbotsch
jakobbotsch marked this pull request as ready for review July 8, 2026 08:24
@jakobbotsch

Copy link
Copy Markdown
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

@JulieLeeMSFT

Copy link
Copy Markdown
Member

/ba-g known issues.

@JulieLeeMSFT
JulieLeeMSFT merged commit 1ab7d05 into dotnet:main Jul 8, 2026
156 of 158 checks passed
@jakobbotsch
jakobbotsch deleted the fix-130212 branch July 8, 2026 17:45
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 10, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
…0317)

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.

Fix #130212
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.

[ci-scan] Test failure: Async2ManagedThreadId.TestThreadIdReflectsResumptionThread Assert.Equal under JIT stress

5 participants