Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Streamline fgExcludeFromSsa#15351

Merged
sandreenko merged 1 commit into
dotnet:masterfrom
mikedn:ssa-exclude
Aug 25, 2018
Merged

Streamline fgExcludeFromSsa#15351
sandreenko merged 1 commit into
dotnet:masterfrom
mikedn:ssa-exclude

Conversation

@mikedn
Copy link
Copy Markdown

@mikedn mikedn commented Dec 3, 2017

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

PIN data: https://1drv.ms/x/s!Av4baJYSo5pjgrsOjE-3c5Tow10lFw

MemStats diff: https://gist.github.com/mikedn/9c9d6d7b40306d9fff18109c3a4b5e9c

@mikedn mikedn force-pushed the ssa-exclude branch 2 times, most recently from a9768e5 to 297bab5 Compare April 2, 2018 16:42
@CarolEidt CarolEidt added this to the 2.2.0 milestone Apr 12, 2018
Copy link
Copy Markdown

@briansull briansull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good, we should get AsmDiffs

@mikedn mikedn changed the title [WIP] Do not assign SSA numbers to excluded vars Streamline fgExcludeFromSsa Apr 15, 2018
@mikedn
Copy link
Copy Markdown
Author

mikedn commented Apr 15, 2018

I ran jit-diff fx+tests on x86/64 - no diffs.

Updated PR title to match commit. This started initially being solely about excluding some variables from SSA but then it turned out that it was slightly slower due to the extra fgExcludeFromSsa calls. So the change ended up being mostly about improving fgExcludeFromSsa performance.

Copy link
Copy Markdown

@briansull briansull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good

@sandreenko
Copy link
Copy Markdown

Nice change, thank you.
LGTM, I will merge it if you can fix the conflicts.

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
@mikedn
Copy link
Copy Markdown
Author

mikedn commented Aug 25, 2018

@sandreenko Conflicts fixed, thank you

@sandreenko sandreenko merged commit 9951a1b into dotnet:master Aug 25, 2018
@mikedn mikedn deleted the ssa-exclude branch September 28, 2019 19:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants