Skip to content

JIT: Spill value before byref address in stsfld #115772

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
May 21, 2025

Conversation

jakobbotsch
Copy link
Member

We could end up producing trees like

▌  STOREIND  ref
├──▌  ADD       byref
│  ├──▌  CALL help byref  CORINFO_HELP_GETDYNAMIC_GCSTATIC_BASE_NOCTOR
│  │  └──▌  CNS_INT   long   0x7ff84228d6b8
│  └──▌  CNS_INT   long   0 Fseq[s_3]
└──▌  CALL      ref    Program:M2():int[] (async)
   └──▌  CNS_INT   ref    null

where a byref is live across a suspension point.

Fix #115671

We could end up producing trees like

```
▌  STOREIND  ref
├──▌  ADD       byref
│  ├──▌  CALL help byref  CORINFO_HELP_GETDYNAMIC_GCSTATIC_BASE_NOCTOR
│  │  └──▌  CNS_INT   long   0x7ff84228d6b8
│  └──▌  CNS_INT   long   0 Fseq[s_3]
└──▌  CALL      ref    Program:M2():int[] (async)
   └──▌  CNS_INT   ref    null
```

where a byref is live across a suspension point.
@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 May 20, 2025
Copy link
Contributor

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

@jakobbotsch jakobbotsch marked this pull request as ready for review May 20, 2025 22:00
@Copilot Copilot AI review requested due to automatic review settings May 20, 2025 22:00
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS @EgorBo

@jakobbotsch jakobbotsch requested review from EgorBo and AndyAyersMS May 20, 2025 22:00
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 a bug where a byref value can be live across a suspension point by ensuring it is spilled appropriately before a stsfld operation. The changes include renaming a variable for clarity in importer.cpp and adding a new condition to spill byref addresses in async methods, along with printing an async flag in gentree.cpp.

  • Rename of the variable from check_spill to checkSpill in importer.cpp.
  • Added a conditional branch in importer.cpp to spill side effects for byref addresses in async methods.
  • Updated gentree.cpp to print an "(async)" suffix when a call is asynchronous.

Reviewed Changes

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

File Description
src/coreclr/jit/importer.cpp Renamed variable and added a new condition for spilling byref addresses in async methods.
src/coreclr/jit/gentree.cpp Added an indication for asynchronous calls in the debug tree display.

@@ -9627,6 +9627,12 @@ void Compiler::impImportBlockCode(BasicBlock* block)
{
impSpillSideEffects(true, CHECK_SPILL_ALL DEBUGARG("value for stsfld with typeinit"));
}
else if (compIsAsync() && op1->TypeIs(TYP_BYREF))
Copy link
Preview

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

The new condition for spilling byref addresses in async methods always triggers the spill even though the inline comment suggests it may only be necessary if op2 possibly performs an async call. Consider refining this condition in the future to more precisely match the intended necessity for spilling.

Copilot uses AI. Check for mistakes.

@jakobbotsch
Copy link
Member Author

/ba-g Failure is timeout and build failure fixed by #115767

@jakobbotsch jakobbotsch merged commit 4e0dc08 into dotnet:main May 21, 2025
105 of 110 checks passed
@jakobbotsch jakobbotsch deleted the fix-115671 branch May 21, 2025 08:41
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.

JIT: Assertion failed 'dsc->TypeGet() != TYP_BYREF' during 'Transform async'
2 participants