-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Implement additional CEE_BOX peepholes #121763
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
base: main
Are you sure you want to change the base?
Conversation
This change implements CEE_BOX peepholes like JIT does, mostly to fix issues with sequences starting with CEE_BOX applied to ByRefLike types. While it is illegal to box a ByRefLike types, some sequences can be replaced by constants or nop. There is also one extra fix for the destination type of an unbox. It was incorrectly changed to StackTypeO by a large change in the past from the correct StackTypeI. This fixes a relatively large number of failing libraries tests.
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
There was a problem hiding this 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 implements additional CEE_BOX peephole optimizations in the CoreCLR interpreter, mirroring the JIT's Compiler::impBoxPatternMatch functionality. The primary goal is to handle sequences involving BOX operations on ByRefLike types by replacing them with constants or no-ops, as boxing ByRefLike types is illegal but certain code patterns can be safely optimized away.
Key changes:
- Changed
ApplyPeepFunc_treturn type fromvoidtointto support flexible skip distances - Added 6 new peephole optimization patterns for BOX-related sequences (BOX+BRTRUE/BRFALSE, BOX+ISINST, BOX+ISINST+BRTRUE/BRFALSE, etc.)
- Fixed UNBOX destination type from StackTypeO to StackTypeI (correcting a previous regression)
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/coreclr/interpreter/compiler.h | Updated ApplyPeepFunc_t return type and added declarations for 6 new BOX-related peephole check/apply function pairs |
| src/coreclr/interpreter/compiler.cpp | Implemented new BOX peephole patterns, updated existing Apply functions to return skip distance, fixed UNBOX type, and registered new peepholes in the optimization pipeline |
| if (helpFunc == CORINFO_HELP_UNBOX) | ||
| { | ||
| EmitPushHelperCall_2(helpFunc, embedInfo, m_pStackPointer[0].var, StackTypeO, (CORINFO_CLASS_HANDLE)embedInfo.compileTimeHandle); | ||
| EmitPushHelperCall_2(helpFunc, embedInfo, m_pStackPointer[0].var, StackTypeI, (CORINFO_CLASS_HANDLE)embedInfo.compileTimeHandle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a pointer onto the GC heap? Doesn't it need to be StackTypeByRef?
This change implements CEE_BOX peepholes like JIT does in Compiler::impBoxPatternMatch, mostly to fix issues with sequences starting with CEE_BOX applied to ByRefLike types. While it is illegal to box a ByRefLike types, some sequences can be replaced by constants or nop.
There is also one extra fix for the destination type of an unbox. It was incorrectly changed to StackTypeO by a large change in the past from the correct StackTypeI.
This fixes a relatively large number of failing libraries tests.