-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
typeof(T).IsValueType isn't fully optimized for reference types T #32094
Comments
For static bool ReturnIsValueTypeForString() => ReturnIsValueType<string>();
static bool ReturnIsValueType<T>() => typeof(T).IsValueType; (when inlining is involved) xor eax, eax
ret |
Yeah, things are inlined cleanly. The unexpected codegen only occurs when inlining is suppressed. |
The codegen for ref type
I suppose one could argue this is unnecessary in a leaf method with no GC safe regions; I don't know the runtime well enough to say for sure. |
@AndyAyersMS I understand why the type information has to be passed in the rcx register, but why in the method implementation is it being pushed onto the stack if it's never used? |
It is implicitly used by the runtime. The location is conveyed from the jit to the runtime by the GC info, and the only supported reporting location is on the stack. |
Related: #1157
It looks like there are still some cases where
typeof(T).IsValueType
isn't fully optimized by the JIT. Repro:For value types
bool
andbool?
this is optimized as expected.But for
string
there's still some throwaway work involving the passed type parameter and a stack spill before eventually returning the constant value false.The text was updated successfully, but these errors were encountered: