[r2r] Fix rule for skipping compilation of methods with CompExactlyDependsOn#125372
Open
BrzVlad wants to merge 1 commit intodotnet:mainfrom
Open
[r2r] Fix rule for skipping compilation of methods with CompExactlyDependsOn#125372BrzVlad wants to merge 1 commit intodotnet:mainfrom
BrzVlad wants to merge 1 commit intodotnet:mainfrom
Conversation
…pendsOn
If a method has `CompExactlyDependsOn` attribute, it means the correctness of its code depends on matching support for the instruction set between r2r compilation time and run time jit compilation.
For the example of ShuffleNativeModified:
```
[CompExactlyDependsOn(typeof(Ssse3))]
internal static Vector128<byte> ShuffleNativeModified(Vector128<byte> vector, Vector128<byte> indices)
{
if (Ssse3.IsSupported)
return Ssse3.Shuffle(vector, indices);
return Vector128.Shuffle(vector, indices);
}
```
Ssse3 is an intel specific instruction set that is never used on arm64. The check in code was returning an ILLEGAL instruction set. This case was treated as `continue` instead of setting `doBypass` to false. Because of this, this method was skipped from r2r compilation. The fix avoids interpreting this method on ios-arm64, making JSON serialization/deserialization 2x faster.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the ReadyToRun (R2R) compiler logic that incorrectly excluded methods from compilation when all of their CompExactlyDependsOn attributes referenced instruction sets not applicable to the target architecture (i.e., returning InstructionSet.ILLEGAL).
Changes:
- The
doBypass = truedefault variable and thereturn doBypassstatement are removed, eliminating the incorrect early-exit path - ILLEGAL instruction sets are now treated as a known compile-time state (never supported on the target), so they no longer trigger the bypass heuristic
- Only instruction sets in an undetermined/opportunistic state (neither explicitly supported nor explicitly unsupported) still cause the method to be skipped from R2R compilation
BrzVlad
commented
Mar 10, 2026
| @@ -611,30 +611,20 @@ public static bool ShouldCodeNotBeCompiledIntoFinalImage(InstructionSetSupport i | |||
|
|
|||
| if (compExactlyDependsOnList != null && compExactlyDependsOnList.Count > 0) | |||
| { | |||
| // Default to true, and set to false if at least one of the types is actually supported in the current environment, and none of the | |||
| // intrinsic types are in an opportunistic state. | |||
| bool doBypass = true; | |||
Member
Author
There was a problem hiding this comment.
This variable seems confusing to me and it was probably meant to serve a purpose that I don't really understand. Also the ILLEGAL case was deliberately skipped, while it feels it should have set doBypass to false. @davidwrighton Could you validate that I'm not missing something obvious here ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If a method has
CompExactlyDependsOnattribute, it means the correctness of its code depends on matching support for the instruction set between r2r compilation time and run time jit compilation.For the example of ShuffleNativeModified:
Ssse3 is an intel specific instruction set that is never used on arm64. The check in code was returning an ILLEGAL instruction set. This case was treated as
continueinstead of settingdoBypassto false. Because of this, this method was skipped from r2r compilation. We now treat the ILLEGAL case as known compile time support, so we don't skip the method from r2r compilation. The fix avoids interpreting this method on ios-arm64, making JSON serialization/deserialization 2x faster.