Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

I'm not completely sure this is a fine assumption to make (we're assuming something that RyuJIT should do). Wanted to collect numbers if this is worth pursuing.

Change salvaged out of #118479, rt-sz will decide if we want to pursue it.

I'm not completely sure this is a fine assumption to make (we're assuming something that RyuJIT should do). Wanted to collect numbers if this is worth pursuing.

Change salvaged out of dotnet#118479, rt-sz will decide if we want to pursue it.
Copilot AI review requested due to automatic review settings August 8, 2025 12:46
Copy link
Contributor

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 change modifies the IL scanner's box instruction handling to avoid considering certain types as boxed, relying on RyuJIT to eliminate trivial box operations. The change expands the scope of box operation validation from only byref-like types to all non-runtime-determined types, while maintaining the existing validation logic for byref-like types.

Key changes:

  • Expands box operation analysis to all non-runtime-determined types
  • Restructures the validation logic to check for trivial elimination patterns first, then validate byref-like type restrictions

if (type.IsByRefLike)
ThrowHelper.ThrowInvalidProgramException();
}

Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

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

The ThrowInvalidProgramException call is now only reachable when type.IsByRefLike is true, but it's placed outside the if block. This will cause the exception to be thrown for all byref-like types, even those that should be valid according to the preceding validation logic. The exception should be moved inside the if block or the logic should be restructured.

Suggested change
}
if (type.IsByRefLike)
ThrowHelper.ThrowInvalidProgramException();

Copilot uses AI. Check for mistakes.
@dotnet-policy-service
Copy link
Contributor

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

}

ThrowHelper.ThrowInvalidProgramException();
// If this is a byref-like type, only the above operations are permitted.
Copy link
Member

Choose a reason for hiding this comment

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

This works only if we recognize all patterns that are recognized by the JIT. I see RyuJIT recognizing more patterns than what we do here - e.g. something with LDNULL:

// for ldnull case, we'll replace the whole "box + isinst + ldnull + cgt_un" sequence

@MichalStrehovsky
Copy link
Member Author

Rt-sz says this is not meaningful so it doesn't look worth pursuing.

@MichalStrehovsky MichalStrehovsky deleted the boxopt branch August 8, 2025 14:34
@github-actions github-actions bot locked and limited conversation to collaborators Sep 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants