Skip to content

JIT: recognize CORINFO_HELP_BOX in impThrowIfNull - #129392

Merged
AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-128574-throwifnull-helper-box
Jun 16, 2026
Merged

AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-128574-throwifnull-helper-box

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

In Tier0 struct boxes are emitted as direct CORINFO_HELP_BOX helper calls rather than GT_BOX nodes; recognize this form too so Tier0 ThrowIfNull(struct) doesn't allocate.

Fixes #128574.

In Tier0 struct boxes are emitted as direct CORINFO_HELP_BOX helper
calls rather than GT_BOX nodes; recognize this form too so Tier0
ThrowIfNull(struct) doesn't allocate.

Fixes dotnet#128574.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 14, 2026 16:12
@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 Jun 14, 2026
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@EgorBo PTAL
fyi @dotnet/jit-contrib

Small number of diffs.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
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 extends an existing Tier0-specific importer optimization in Compiler::impThrowIfNull to also recognize value-type boxing that is represented as a direct CORINFO_HELP_BOX helper call (instead of a GT_BOX node). When the pattern is detected, the importer drops the ArgumentNullException.ThrowIfNull call as a no-op while preserving any side effects from evaluating the box helper’s address argument and the valueName argument.

Changes:

  • Add a new pattern match for ArgumentNullException_ThrowIfNull(CORINFO_HELP_BOX(clsHnd, addr), valueName) in Tier0.
  • Preserve evaluation order/side effects by spilling addr and valueName before returning NOP (gtNewNothingNode()).

@AndyAyersMS

Copy link
Copy Markdown
Member Author

diffs

Comment thread src/coreclr/jit/importercalls.cpp Resolved
@AndyAyersMS

Copy link
Copy Markdown
Member Author

/ba-g persistent timeouts

@AndyAyersMS
AndyAyersMS merged commit 3d40d73 into dotnet:main Jun 16, 2026
137 of 141 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 17, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
In Tier0 struct boxes are emitted as direct CORINFO_HELP_BOX helper
calls rather than GT_BOX nodes; recognize this form too so Tier0
ThrowIfNull(struct) doesn't allocate.

Fixes #128574.

Co-authored-by: Copilot <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

Avoid boxing ArgumentNullException.ThrowIfNull for user-defined struct arguments in Tier-0

3 participants