-
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
JIT: Poor codegen when calling an instance method on a temporary, unused struct #42354
Comments
IR after Morph: Method1
Method2
|
This issue is interesting, there are 2 solutions, I think both have their own benefits and should be implemented:
however, it won't work because importer sees it as "ADDR(LCL_VAR())` so we need a part of #11057.
Not sure if we have time for it in 6.0 but lets keep it here for now. |
Moving to .NET 8. |
Roslyn emits ldloca + dup + initobj when initializing structs. Normally we clone address trees instead of creating a local for them (which will address expose the local), but we treat this initobj pattern specially. Remove this special treatment. It means we sometimes end up with slightly larger code because we no longer have a register with the address in it (could potentially be fixed by CSE), but avoiding the address exposure seems like the right trade off to me. Fix dotnet#42354
Roslyn emits ldloca + dup + initobj when initializing structs. Normally we clone address trees instead of creating a local for them (which will address expose the local), but we treat this initobj pattern specially. Remove this special treatment. It means we sometimes end up with slightly larger code because we no longer have a register with the address in it (could potentially be fixed by CSE), but avoiding the address exposure seems like the right trade off to me. Fix #42354 Fix #57055
Description
Poor codegen in the following situation:
Configuration
Running a recent master build on Win 10 2004 x64
Other information
Given this code, the JIT produces this disassembly for
Method1
andMethod2
:If you do it the normal way (
new Rng().NextRandom()
) the JIT doesn't completely optimize it.It insists on initializing the struct. If the struct is a larger size the JIT would zero the entire struct on the stack before returning 4.
If you split
new Rng()
into its own function, the JIT does completely optimize it.category:cq
theme:structs
skill-level:intermediate
cost:medium
The text was updated successfully, but these errors were encountered: