-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Strange boxing deopt #82291
Comments
Aside as workaround; replacing |
@benaadams that would be incorrect for nullable types (like |
The reason is that Roslyn (helpfully) optimizes the method itself:
The Jit then doesn't drop the unused box. The fix would be to simplify |
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak Issue DetailsDescriptionGiven the following code, only the first function optimizes acceptably here. I'm not quite sure why it can't kick in for the other cases? Reproduction Stepspublic class C {
[SharpLab.Runtime.JitGeneric(typeof(int))]
public bool GetValueOrNull<T>()
{
if (default(T) != null)
return true;
return false;
}
[SharpLab.Runtime.JitGeneric(typeof(int))]
public bool GetValueOrNullSlow<T>()
{
if (default(T) != null)
return false;
return false;
}
[SharpLab.Runtime.JitGeneric(typeof(int))]
public void GetValueOrNullSlow2<T>()
{
if (default(T) != null)
return;
return;
}
} Expected behaviorGetValueOrNullSlow and GetValueOrNullSlow2 are both optimized like GetValueOrNull Actual behaviorThey don't Regression?No response Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
Description
Given the following code, only the first function optimizes acceptably here. I'm not quite sure why it can't kick in for the other cases?
Reproduction Steps
https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABAJgEYBYAKGIAYACY8gOgCUBXAOwwEt8YLAMIR8AB14AbGFADKMgG68wMXAG4a9JuQCsG6poDMTUgyEMA3jQY2G12wG1ZAC2xQxAGWzB23PgJYAKV4MAHEYLhllAAoMAE8xGAgAM2jeHgBKDIBdextiY2AICEkGcIwANWxJDhgAeSgAOQ5JSQAeABUAPmiMvMt+2wZeZIZogBMYZOwWjGiOjIYAQgBeBi4WyT7qId3iAHYGDCha/V2hwfzD6clcGDPbAF8Lndt+p1d3Lx9OHn5BYJhCJRMCxBJJVLpDBZXKvfKFYqlcpVGr1JqbWSSCAAd06PW2QyscN2IzGk2ms3mi1W602BPOVwYNzuDwZlyY12qLP6zzeBmJ7xcbk83l8fwCgPCkSgMXiiRSaUyOX6BSYKDKMEq1VqDWarUxONIeN6/SJDOGowmUxmkjmC2Waw2rXpDIOrPO7LdPJejyAA
Expected behavior
GetValueOrNullSlow and GetValueOrNullSlow2 are both optimized like GetValueOrNull
Actual behavior
They don't
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: