Streamline fgExcludeFromSsa (dotnet/coreclr#15351)
authormikedn <onemihaid@hotmail.com>
Sat, 25 Aug 2018 22:29:28 +0000 (01:29 +0300)
committerSergey Andreenko <seandree@microsoft.com>
Sat, 25 Aug 2018 22:29:28 +0000 (15:29 -0700)
commitd0367d7a3fb41d9c707fa5b3dc7941e42cec3cf2
tree82467d37ca84e79b109256d69760b20d130f3412
parentf227b2b02ae3154f192ba84516435e320ba9659e
Streamline fgExcludeFromSsa (dotnet/coreclr#15351)

This function is relatively expensive due to the many checks it does. Adding an LclVarDsc "in SSA" bit that is set during SSA construction by calling fgExcludeFromSsa only once per variable results in 0.35% drop in instructions retired.

Most of the checks done in fgExcludeFromSsa are implied by lvTracked and they could probably be converted to asserts. But lvOverlappingFields is not implied by lvTracked so even if all redundant checks are converted to asserts fgExcludeFromSsa still needs 2 checks rather than just one.

Incidentally, this difference between tracked variables and SSA variables results in SSA and value numbers being assigned to some variables that are actually excluded from SSA - SsaBuilder::RenameVariables and fgValueNumber assign numbers to all live in fgFirstBB variables that require initialization without checking fgExcludeFromSsa first. Structs with overlapping fields are not common but properly excluding them is still enough to save 0.15% memory when compiling corelib.

- Replace calls to fgExcludeFromSsa with calls to lvaInSsa (the old name is kind of weird, it has nothing to do with the flow graph and "exclude" results in double negation)
- Move fgExcludeFromSsa logic to SsaBuild::IncludeInSsa and use it to initialize LclVarDsc::lvInSsa for all variables
- Change RenameVariables and fgValueNumber to call lvaInSsa before assigning numbers to live in fgFirstBB variables

Commit migrated from https://github.com/dotnet/coreclr/commit/9951a1b06f1279fdf8ad465dff355fc38238211f
src/coreclr/src/jit/assertionprop.cpp
src/coreclr/src/jit/compiler.h
src/coreclr/src/jit/compiler.hpp
src/coreclr/src/jit/copyprop.cpp
src/coreclr/src/jit/earlyprop.cpp
src/coreclr/src/jit/morph.cpp
src/coreclr/src/jit/optimizer.cpp
src/coreclr/src/jit/ssabuilder.cpp
src/coreclr/src/jit/ssabuilder.h
src/coreclr/src/jit/valuenum.cpp