Improvements for null check folding. by erozenfeld · Pull Request #1735 · dotnet/runtime (original) (raw)
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
optFoldNullChecks attempts to remove GT_NULLCHECK nodes that are post-dominated by indirections on the same variable. These changes implement a number of improvements.
- Recognize more patterns. Before these changes only the following pattern was recognized: x = comma(nullcheck(y), add(y, const1))
followed by
indir(add(x, const2))
where const1 + const2 is sufficiently small.
With these changes the following patterns are recognized:
nullcheck(x) or x = comma(nullcheck(y), add(y, const1))
followed by
indir(x) or indir(add(x, const2))
where const1 + const2 is sufficiently small.
Indirections now include GT_ARR_LENGTH nodes.
Morph has an optimization ((x+icon1)+icon2) => (x+(icon1+icon2)) These changes generalize it to handle commas: ((comma(y, x+icon1)+icon2) => comma(y, x+(icon1+icon2))
That exposes more trees to null check folding.
Fix a bug in flow transformations that could lose BBF_HAS_NULLCHECK flag on some basic blocks, which led to missing opportunities for null check folding.
Make safety checks in optCanMoveNullCheckPastTree (for trees between the nullcheck and the indirection) both more correct and less conservative. For example, we were not allowing any assignments if we were inside try; however, assignments to compiler temps are safe since they won't be visible in handlers.
Increase the maximum number of trees we check between GT_NULLCHECK and the indirection from 25 to 50.
Refactor the code and move pattern recognition and safety checks to helper methods.
Add missing BBF_HAS_NULLCHECK and OMF_HAS_NULLCHECK when we create GT_NULLCHECK nodes.
sdmaclea added a commit to sdmaclea/runtime that referenced this pull request
Thies file was added accidentally as part of dotnet#1735
sdmaclea added a commit that referenced this pull request
Thies file was added accidentally as part of #1735
ghost locked as resolved and limited conversation to collaborators