-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add liveness analysis to optimise local var init #327
Comments
Simple example to use for testing, note this is using unsafe code:
|
For structs generally IL will contain a ldloca before a stfld or a ldloc before a ldfld. For the store the ldloca will be interpreted in the liveness analysis as a use of the struct thus resulting in the struct being marked as must-init. So currently the prolog code will be zeroing the struct. If a constructor is used for the struct then potentially there is double initialization happening. However the current implementation is conservative and does not try to deal with this. |
In terms of testing zero initialization of locals - it looks like these are the tests in dotnet runtime: https://github.com/dotnet/runtime/tree/0916f7ba98716b18ccfa60081befa164bec3c203/src/tests/JIT/Directed/zeroinit |
Code generator emits code to initialise locals as part of method prolog, see CodeGenerator.GenerateProlog(..). Similarly the LocalHeapCodeGenerator.GenerateCode(..) does initialisation of localloc memory.
Currently the entire of the locals/localloc is initialised - this is suboptimal if assignments are made to the locals before use. To detect this liveness analysis needs to be implemented and used to set the LocalVariableDescriptor.MustInit flag. The init code can then just init the vars that have been marked as needing it.
The text was updated successfully, but these errors were encountered: