Skip to content

JIT: recognize CORINFO_HELP_BOX in impThrowIfNull#129392

Open
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-128574-throwifnull-helper-box
Open

JIT: recognize CORINFO_HELP_BOX in impThrowIfNull#129392
AndyAyersMS wants to merge 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 <223556219+Copilot@users.noreply.github.com>
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

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

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

2 participants