-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
JIT should optimize away the cast that occurs after Array.Clone #45302
Comments
Can we not use covariant return types here, to make the return type of |
|
I think it should be easy to fix in JIT, given a tree:
drop the helper if arg0's type and that CNS_INT handle return |
Possible fix: EgorBo@43282cd
|
Why would the intrinsic annotation be on MemberwiseClone? I realize Array.Copy is just a dumb wrapper around it, so I guess inlining has already taken place at this point? |
The typical way to clone an array is to use
Array.Clone
, which returns an object that needs to be cast back to the original array type.After the call to
Clone
, the JIT emits a call to theChkCastAny
helper to ensure that the cast is legitimate.There is an opportunity for improvement here. If the target of the
Array.Clone
call is known by the JIT to be a local of type T, and if the return value ofClone
is immediately cast to T or type U (where reinterpret_cast<U>(T) is legal), then the JIT should no-op the cast. In the sample above, that means labels L000b - L001d would disappear.Some examples:
The text was updated successfully, but these errors were encountered: